Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP1:Update
util-linux.2662
util-linux-cal-no-terminal.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File util-linux-cal-no-terminal.patch of Package util-linux.2662
From 2a4b073e8b2d34dfadd8306f7d71957687923bdd Mon Sep 17 00:00:00 2001 From: Karel Zak <kzak@redhat.com> Date: Thu, 12 Mar 2015 11:50:07 +0100 Subject: [PATCH] cal: care about setuprterm() result References: https://bugzilla.suse.com/show_bug.cgi?id=903440 Signed-off-by: Karel Zak <kzak@redhat.com> --- misc-utils/cal.c | 59 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/misc-utils/cal.c b/misc-utils/cal.c index d6d4a0f..96c9e78 100644 --- misc-utils/cal.c +++ misc-utils/cal.c @@ -74,6 +74,9 @@ #include "mbsalign.h" #include "strutils.h" +static int has_term = 0; +static const char *Senter = "", *Sexit = ""; /* enter and exit standout mode */ + #if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) # ifdef HAVE_NCURSES_H # include <ncurses.h> @@ -82,22 +85,31 @@ # endif # include <term.h> -static void my_setupterm(const char *term, int fildes, int *errret) +static int setup_terminal(char *term) { - setupterm((char *)term, fildes, errret); + int ret; + + if (setupterm(term, STDOUT_FILENO, &ret) != OK || ret != 1) + return -1; + return 0; } static void my_putstring(char *s) { - putp(s); + if (has_term) + putp(s); + else + fputs(s, stdout); } static const char *my_tgetstr(char *s __attribute__((__unused__)), char *ss) { - const char *ret = tigetstr(ss); + const char *ret = NULL; + + if (has_term) + ret = tigetstr(ss); if (!ret || ret == (char *)-1) return ""; - return ret; } @@ -108,22 +120,29 @@ static char termbuffer[4096]; static char tcbuffer[4096]; static char *strbuf = termbuffer; -static void my_setupterm(const char *term, int fildes __attribute__((__unused__)), int *errret) +static int setup_terminal(char *term) { - *errret = tgetent(tcbuffer, term); + if (tgetent(tcbuffer, term) < 0) + return -1; + return 0; } static void my_putstring(char *s) { - tputs(s, 1, putchar); + if (has_term) + tputs(s, 1, putchar); + else + fputs(s, stdout); } static const char *my_tgetstr(char *s, char *ss __attribute__((__unused__))) { - const char *ret = tgetstr(s, &strbuf); + const char *ret = NULL; + + if (has_term) + ret = tgetstr(s, &strbuf); if (!ret) return ""; - return ret; } @@ -136,11 +155,6 @@ static void my_putstring(char *s) #endif /* end of LIBTERMCAP / NCURSES */ -#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) || defined(HAVE_LIBTERMCAP) -static const char *term=""; -#endif - -static const char *Senter="", *Sexit="";/* enter and exit standout mode */ #include "widechar.h" @@ -293,12 +307,15 @@ int main(int argc, char **argv) atexit(close_stdout); #if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) || defined(HAVE_LIBTERMCAP) - if ((term = getenv("TERM"))) { - int ret; - my_setupterm(term, STDOUT_FILENO, &ret); - if (ret > 0) { - Senter = my_tgetstr("so","smso"); - Sexit = my_tgetstr("se","rmso"); + { + char *term = getenv("TERM"); + + if (term) { + has_term = setup_terminal(term) == 0; + if (has_term) { + Senter = my_tgetstr("so","smso"); + Sexit = my_tgetstr("se","rmso"); + } } } #endif
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor