]> granicus.if.org Git - file/commitdiff
PR/528: Make -00 print name\0description\0
authorChristos Zoulas <christos@zoulas.com>
Mon, 14 Mar 2016 02:30:22 +0000 (02:30 +0000)
committerChristos Zoulas <christos@zoulas.com>
Mon, 14 Mar 2016 02:30:22 +0000 (02:30 +0000)
src/file.c

index 4b24b45de2f13a1b467c0dbc8d4b3d6798b5d1f4..b8d6ce5d5d887d965d3b38b028bd6463fd0aff41 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: file.c,v 1.168 2015/09/30 14:02:06 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.169 2016/03/14 02:30:22 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -206,7 +206,7 @@ main(int argc, char *argv[])
                        flags |= MAGIC_MIME_ENCODING;
                        break;
                case '0':
-                       nulsep = 1;
+                       nulsep++;
                        break;
                case 'b':
                        bflag++;
@@ -494,24 +494,28 @@ unwrap(struct magic_set *ms, const char *fn)
 private int
 process(struct magic_set *ms, const char *inname, int wid)
 {
-       const char *type;
+       const char *type, c = nulsep > 1 ? '\0' : '\n';
        int std_in = strcmp(inname, "-") == 0;
 
        if (wid > 0 && !bflag) {
                (void)printf("%s", std_in ? "/dev/stdin" : inname);
                if (nulsep)
                        (void)putc('\0', stdout);
-               (void)printf("%s", separator);
-               (void)printf("%*s ",
-                   (int) (nopad ? 0 : (wid - file_mbswidth(inname))), "");
+               if (nulsep < 2) {
+                       (void)printf("%s", separator);
+                       (void)printf("%*s ",
+                           (int) (nopad ? 0 : (wid - file_mbswidth(inname))),
+                           "");
+               }
        }
 
        type = magic_file(ms, std_in ? NULL : inname);
+
        if (type == NULL) {
-               (void)printf("ERROR: %s\n", magic_error(ms));
+               (void)printf("ERROR: %s%c", magic_error(ms), c);
                return 1;
        } else {
-               (void)printf("%s\n", type);
+               (void)printf("%s%c", type, c);
                return 0;
        }
 }