make sure we do not write out non-printable characters in file names
and symbolic links (by default) PR: bin/19354 Reviewed by: silence on -current
This commit is contained in:
parent
950ec7e473
commit
ee579ffbea
@ -43,13 +43,13 @@ int revnamecmp __P((const FTSENT *, const FTSENT *));
|
||||
int statcmp __P((const FTSENT *, const FTSENT *));
|
||||
int revstatcmp __P((const FTSENT *, const FTSENT *));
|
||||
|
||||
void prcopy __P((char *, char *, int));
|
||||
void printcol __P((DISPLAY *));
|
||||
void printlong __P((DISPLAY *));
|
||||
void printscol __P((DISPLAY *));
|
||||
void usage __P((void));
|
||||
int len_octal __P((char *, int));
|
||||
int prn_octal __P((char *));
|
||||
int len_octal __P((const char *, int));
|
||||
int prn_octal __P((const char *));
|
||||
int prn_printable __P((const char *));
|
||||
#ifdef COLORLS
|
||||
void parsecolors __P((char *cs));
|
||||
void colorquit __P((int));
|
||||
|
@ -566,8 +566,6 @@ display(p, list)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (f_nonprint)
|
||||
prcopy(cur->fts_name, cur->fts_name, cur->fts_namelen);
|
||||
if (cur->fts_namelen > maxlen)
|
||||
maxlen = cur->fts_namelen;
|
||||
if (f_octal || f_octal_escape) {
|
||||
|
@ -48,6 +48,7 @@ extern int f_inode; /* print inode */
|
||||
extern int f_longform; /* long listing format */
|
||||
extern int f_octal; /* print unprintables in octal */
|
||||
extern int f_octal_escape; /* like f_octal but use C escapes if possible */
|
||||
extern int f_nonprint; /* show unprintables as ? */
|
||||
extern int f_sectime; /* print the real time for all files */
|
||||
extern int f_size; /* list size in short listing */
|
||||
extern int f_statustime; /* use time of last mode change */
|
||||
|
@ -112,6 +112,21 @@ printscol(dp)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* print name in current style
|
||||
*/
|
||||
static int
|
||||
printname(name)
|
||||
const char *name;
|
||||
{
|
||||
if (f_octal || f_octal_escape)
|
||||
return prn_octal(name);
|
||||
else if (f_nonprint)
|
||||
return prn_printable(name);
|
||||
else
|
||||
return printf("%s", name);
|
||||
}
|
||||
|
||||
void
|
||||
printlong(dp)
|
||||
DISPLAY *dp;
|
||||
@ -166,8 +181,7 @@ printlong(dp)
|
||||
if (f_color)
|
||||
color_printed = colortype(sp->st_mode);
|
||||
#endif
|
||||
if (f_octal || f_octal_escape) (void)prn_octal(p->fts_name);
|
||||
else (void)printf("%s", p->fts_name);
|
||||
(void)printname(p->fts_name);
|
||||
#ifdef COLORLS
|
||||
if (f_color && color_printed)
|
||||
endcolor(0);
|
||||
@ -278,8 +292,7 @@ printaname(p, inodefield, sizefield)
|
||||
if (f_color)
|
||||
color_printed = colortype(sp->st_mode);
|
||||
#endif
|
||||
chcnt += (f_octal || f_octal_escape) ? prn_octal(p->fts_name)
|
||||
: printf("%s", p->fts_name);
|
||||
chcnt += printname(p->fts_name);
|
||||
#ifdef COLORLS
|
||||
if (f_color && color_printed)
|
||||
endcolor(0);
|
||||
@ -494,9 +507,6 @@ printlink(p)
|
||||
return;
|
||||
}
|
||||
path[lnklen] = '\0';
|
||||
if (f_octal || f_octal_escape) {
|
||||
(void)printf(" -> ");
|
||||
(void)prn_octal(path);
|
||||
}
|
||||
else (void)printf(" -> %s", path);
|
||||
(void)printf(" -> ");
|
||||
printname(path);
|
||||
}
|
||||
|
@ -56,17 +56,19 @@ static const char rcsid[] =
|
||||
#include "ls.h"
|
||||
#include "extern.h"
|
||||
|
||||
void
|
||||
prcopy(src, dest, len)
|
||||
char *src, *dest;
|
||||
int len;
|
||||
int
|
||||
prn_printable(s)
|
||||
const char *s;
|
||||
{
|
||||
unsigned char ch;
|
||||
unsigned char c;
|
||||
int n;
|
||||
|
||||
while (len--) {
|
||||
ch = *src++;
|
||||
*dest++ = isprint(ch) ? ch : '?';
|
||||
}
|
||||
for (n = 0; (c = *s) != '\0'; ++s, ++n)
|
||||
if (isprint(c))
|
||||
putchar(c);
|
||||
else
|
||||
putchar('?');
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -84,7 +86,7 @@ prcopy(src, dest, len)
|
||||
|
||||
int
|
||||
len_octal(s, len)
|
||||
char *s;
|
||||
const char *s;
|
||||
int len;
|
||||
{
|
||||
int r = 0;
|
||||
@ -96,7 +98,7 @@ len_octal(s, len)
|
||||
|
||||
int
|
||||
prn_octal(s)
|
||||
char *s;
|
||||
const char *s;
|
||||
{
|
||||
unsigned char ch;
|
||||
int len = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user