aboutsummaryrefslogtreecommitdiff
path: root/bin/ls/print.c
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2000-06-06 06:52:03 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2000-06-06 06:52:03 +0000
commit38782c258deaa23466313e11ebc3382fd5f21311 (patch)
tree3d33ce9133a455f7e9a6e5db8c5ceffd56c7b348 /bin/ls/print.c
parent2803b77e52b45f0af8be32154841a68344ed80a9 (diff)
downloadsrc-38782c258deaa23466313e11ebc3382fd5f21311.tar.gz
src-38782c258deaa23466313e11ebc3382fd5f21311.zip
Make signal handler safe - don't use stdio (pointed by bde)
Staticize some color functions Add yet one tolower() call which is forgotten after check Don't check for OOPS - not really needed
Notes
Notes: svn path=/head/; revision=61321
Diffstat (limited to 'bin/ls/print.c')
-rw-r--r--bin/ls/print.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/bin/ls/print.c b/bin/ls/print.c
index fc9bf93f4b6f..f439de4b79ca 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -69,6 +69,10 @@ static int printaname __P((FTSENT *, u_long, u_long));
static void printlink __P((FTSENT *));
static void printtime __P((time_t));
static int printtype __P((u_int));
+#ifdef COLORLS
+static void endcolor __P((int));
+static int colortype __P((mode_t));
+#endif
#define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT)
@@ -166,7 +170,7 @@ printlong(dp)
else (void)printf("%s", p->fts_name);
#ifdef COLORLS
if (f_color && color_printed)
- endcolor();
+ endcolor(0);
#endif
if (f_type)
(void)printtype(sp->st_mode);
@@ -290,7 +294,7 @@ printaname(p, inodefield, sizefield)
: printf("%s", p->fts_name);
#ifdef COLORLS
if (f_color && color_printed)
- endcolor();
+ endcolor(0);
#endif
if (f_type)
chcnt += printtype(sp->st_mode);
@@ -359,9 +363,18 @@ printtype(mode)
int putch(c)
int c;
{
- return putc(c, stdout);
+ (void) putchar(c);
+ return 0;
}
+int writech(c)
+ int c;
+{
+ char tmp = c;
+
+ (void) write(STDOUT_FILENO, &tmp, 1);
+ return 0;
+}
void
printcolor(c)
@@ -371,24 +384,25 @@ printcolor(c)
if (colors[c][0] != -1) {
ansiseq = tgoto(ansi_fgcol, 0, colors[c][0]);
- if (ansiseq && *ansiseq != 'O') /* "OOPS" */
+ if (ansiseq)
tputs(ansiseq, 1, putch);
}
if (colors[c][1] != -1) {
ansiseq = tgoto(ansi_bgcol, 0, colors[c][1]);
- if (ansiseq && *ansiseq != 'O') /* "OOPS" */
+ if (ansiseq)
tputs(ansiseq, 1, putch);
}
}
-void
-endcolor()
+static void
+endcolor(sig)
+ int sig;
{
- tputs(ansi_coloff, 1, putch);
+ tputs(ansi_coloff, 1, sig ? writech : putch);
}
-int
+static int
colortype(mode)
mode_t mode;
{
@@ -436,6 +450,7 @@ char *cs;
{
int i, j, len;
char c[2];
+
if (cs == NULL) cs = ""; /* LSCOLORS not set */
len = strlen(cs);
for (i = 0 ; i < C_NUMCOLORS ; i++) {
@@ -455,7 +470,7 @@ char *cs;
c[j]);
c[j] = defcolors[2*i+j];
}
- if (c[j] == 'x')
+ if (tolower((unsigned char)c[j]) == 'x')
colors[i][j] = -1;
else
colors[i][j] = c[j]-'0';
@@ -466,8 +481,7 @@ char *cs;
void colorquit(sig)
int sig;
{
- endcolor();
- fflush(stdout);
+ endcolor(sig);
(void) signal(sig, SIG_DFL);
(void) kill(getpid(), sig);