From: Christos Zoulas Date: Fri, 17 Nov 2006 16:11:09 +0000 (+0000) Subject: add -0 X-Git-Tag: FILE4_19~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=409ab83b1167c2b93dddf7448a1144d69d6a9ea7;p=file add -0 --- diff --git a/ChangeLog b/ChangeLog index 0117dcb4..7c7e1c90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-11-17 10:51 Christos Zoulas + + * Added a -0 option to print a '\0' separator + Etienne Buira + 2006-10-31 15:14 Christos Zoulas * Check offset before copying (Mike Frysinger) diff --git a/doc/file.man b/doc/file.man index ce8caccf..3016d07a 100644 --- a/doc/file.man +++ b/doc/file.man @@ -1,5 +1,5 @@ .TH FILE __CSECTION__ "Copyright but distributable" -.\" $Id: file.man,v 1.58 2006/05/03 19:20:25 christos Exp $ +.\" $Id: file.man,v 1.59 2006/11/17 16:11:10 christos Exp $ .SH NAME file \- determine file type @@ -271,6 +271,10 @@ Print the version of the program and exit. .TP 8 .B "\-z, \-\-uncompress" Try to look inside compressed files. +.B "\-0, \-\-print0" +Output a null character ('\0') after the end of the filename. Nice to +.BR cut (1) +the output. This does not affect the separator which is still printed. .TP 8 .B "\-\-help" Print a help message and exit. diff --git a/src/file.c b/src/file.c index 30e04fa6..ac583bab 100644 --- a/src/file.c +++ b/src/file.c @@ -71,7 +71,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$Id: file.c,v 1.102 2006/06/02 00:07:58 ian Exp $") +FILE_RCSID("@(#)$Id: file.c,v 1.103 2006/11/17 16:11:10 christos Exp $") #endif /* lint */ @@ -81,7 +81,7 @@ FILE_RCSID("@(#)$Id: file.c,v 1.102 2006/06/02 00:07:58 ian Exp $") #define SYMLINKFLAG "" #endif -# define USAGE "Usage: %s [-bcik" SYMLINKFLAG "nNrsvz] [-f namefile] [-F separator] [-m magicfiles] file...\n %s -C -m magicfiles\n" +# define USAGE "Usage: %s [-bcik" SYMLINKFLAG "nNrsvz0] [-f namefile] [-F separator] [-m magicfiles] file...\n %s -C -m magicfiles\n" #ifndef MAXPATHLEN #define MAXPATHLEN 512 @@ -90,7 +90,8 @@ FILE_RCSID("@(#)$Id: file.c,v 1.102 2006/06/02 00:07:58 ian Exp $") private int /* Global command-line options */ bflag = 0, /* brief output format */ nopad = 0, /* Don't pad output */ - nobuffer = 0; /* Do not buffer stdout */ + nobuffer = 0, /* Do not buffer stdout */ + nullsep = 0; /* Append '\0' to the separator */ private const char *magicfile = 0; /* where the magic is */ private const char *default_magicfile = MAGIC; @@ -127,7 +128,7 @@ main(int argc, char *argv[]) char *home, *usermagic; struct stat sb; static const char hmagic[] = "/.magic"; -#define OPTSTRING "bcCdf:F:hikLm:nNprsvz" +#define OPTSTRING "bcCdf:F:hikLm:nNprsvz0" #ifdef HAVE_GETOPT_LONG int longindex; static const struct option long_options[] = @@ -155,6 +156,7 @@ main(int argc, char *argv[]) {"no-pad", 0, 0, 'N'}, {"special-files", 0, 0, 's'}, {"compile", 0, 0, 'C'}, + {"print0", 0, 0, '0'}, {0, 0, 0, 0}, }; #endif @@ -206,6 +208,9 @@ main(int argc, char *argv[]) help(); break; #endif + case '0': + nullsep = 1; + break; case 'b': ++bflag; break; @@ -397,8 +402,9 @@ process(const char *inname, int wid) int std_in = strcmp(inname, "-") == 0; if (wid > 0 && !bflag) - (void)printf("%s%s%*s ", std_in ? "/dev/stdin" : inname, - separator, (int) (nopad ? 0 : (wid - file_mbswidth(inname))), ""); + (void)printf("%s%*c%s%*s ", std_in ? "/dev/stdin" : inname, + nullsep ? 1 : 0, '\0', separator, + (int) (nopad ? 0 : (wid - file_mbswidth(inname))), ""); type = magic_file(magic, std_in ? NULL : inname); if (type == NULL)