[hackers] [sbase] od: For the 'c' type, format non-printable charecters as octal || Michael Forney

From: <git_AT_suckless.org>
Date: Mon, 26 Feb 2018 08:02:54 +0100 (CET)

commit d098ac4abc805d6bdfc2b331de4633d7bda03b00
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Sun Feb 25 22:56:07 2018 -0800
Commit: Michael Forney <mforney_AT_mforney.org>
CommitDate: Sun Feb 25 23:01:57 2018 -0800

    od: For the 'c' type, format non-printable charecters as octal
    
    This is the behavior specified by POSIX.

diff --git a/od.c b/od.c
index eb63318..0b1c5c6 100644
--- a/od.c
+++ b/od.c
_AT_@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include <ctype.h>
 #include <fcntl.h>
 #include <stdint.h>
 #include <stdio.h>
_AT_@ -69,6 +70,8 @@ printchunk(const unsigned char *s, unsigned char format, size_t len)
         case 'c':
                 if (strchr("\a\b\t\n\v\f\r\0", *s)) {
                         printf(" %3s", escdict[*s]);
+ } else if (!isprint(*s)) {
+ printf(" %3o", *s);
                 } else {
                         printf(" %3c", *s);
                 }
Received on Mon Feb 26 2018 - 08:02:54 CET

This archive was generated by hypermail 2.3.0 : Mon Feb 26 2018 - 08:12:24 CET