summaryrefslogtreecommitdiff
path: root/bin/ls/util.c
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>1998-04-21 22:02:01 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>1998-04-21 22:02:01 +0000
commit7ea3064820774f66f6ba35b0c75e16781531825e (patch)
tree05f57e3c610cd0b6651343ac49a6b26527e56aec /bin/ls/util.c
parent4431d4ba23d35ef44b86c8e24088ffbd63b28ad8 (diff)
Notes
Diffstat (limited to 'bin/ls/util.c')
-rw-r--r--bin/ls/util.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/bin/ls/util.c b/bin/ls/util.c
index 05c9cd4acceec..e445b993a68d0 100644
--- a/bin/ls/util.c
+++ b/bin/ls/util.c
@@ -39,7 +39,7 @@
static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/2/94";
#else
static const char rcsid[] =
- "$Id: util.c,v 1.10 1997/08/07 15:33:50 steve Exp $";
+ "$Id: util.c,v 1.11 1997/08/07 22:28:25 steve Exp $";
#endif
#endif /* not lint */
@@ -47,6 +47,7 @@ static const char rcsid[] =
#include <sys/stat.h>
#include <ctype.h>
+#include <err.h>
#include <fts.h>
#include <stdio.h>
#include <stdlib.h>
@@ -68,6 +69,44 @@ prcopy(src, dest, len)
}
}
+/*
+ * The fts system makes it difficult to replace fts_name with a different-
+ * sized string, so we just calculate the real length here and do the
+ * conversion in prn_octal()
+ */
+int
+len_octal(s, len)
+ char *s;
+ int len;
+{
+ int r;
+
+ while (len--)
+ if (isprint(*s++)) r++; else r += 4;
+ return r;
+}
+
+int
+prn_octal(s)
+ char *s;
+{
+ unsigned char ch;
+ int len = 0;
+
+ while ((ch = *s++))
+ {
+ if (isprint(ch)) putchar(ch), len++;
+ else {
+ putchar('\\');
+ putchar('0' + (ch >> 6));
+ putchar('0' + ((ch >> 3) & 3));
+ putchar('0' + (ch & 3));
+ len += 4;
+ }
+ }
+ return len;
+}
+
void
usage()
{