summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2000-06-06 06:52:03 +0000
committerache <ache@FreeBSD.org>2000-06-06 06:52:03 +0000
commit1b57c1627cd95f6a8b7ea5bc85f15e6254320c4f (patch)
tree014483485b1b2df4cb49634510a6a114dea29739 /bin
parentba3f3c2ac7e2d3c0db4e6534051fedbd6cfd0abb (diff)
downloadFreeBSD-src-1b57c1627cd95f6a8b7ea5bc85f15e6254320c4f.zip
FreeBSD-src-1b57c1627cd95f6a8b7ea5bc85f15e6254320c4f.tar.gz
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
Diffstat (limited to 'bin')
-rw-r--r--bin/ls/extern.h2
-rw-r--r--bin/ls/print.c38
2 files changed, 26 insertions, 14 deletions
diff --git a/bin/ls/extern.h b/bin/ls/extern.h
index 9707ea7..5f063cd 100644
--- a/bin/ls/extern.h
+++ b/bin/ls/extern.h
@@ -53,8 +53,6 @@ int len_octal __P((char *, int));
int prn_octal __P((char *));
#ifdef COLORLS
void parsecolors __P((char *cs));
-int colortype __P((mode_t mode));
-void endcolor __P((void));
char *ansi_fgcol;
char *ansi_bgcol;
diff --git a/bin/ls/print.c b/bin/ls/print.c
index fc9bf93..f439de4 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);
OpenPOWER on IntegriCloud