diff options
author | Christos Zoulas <christos@zoulas.com> | 2005-08-12 14:19:33 +0000 |
---|---|---|
committer | Christos Zoulas <christos@zoulas.com> | 2005-08-12 14:19:33 +0000 |
commit | f5888ca145daa55c3ae46a96fb0ee99e2afce4ad (patch) | |
tree | b28adc801300aa0d7c3d0ca4be011e52f5510457 | |
parent | f1f131e7a96006af34603b8694a83bbd9d10ba0c (diff) | |
download | file-git-f5888ca145daa55c3ae46a96fb0ee99e2afce4ad.tar.gz |
Add -h support for POSIX.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | doc/file.man | 28 | ||||
-rw-r--r-- | src/file.c | 13 |
3 files changed, 40 insertions, 6 deletions
@@ -1,4 +1,9 @@ +2005-08-12 10:17 Christos Zoulas <christos@zoulas.com> + + * Add -h flag and dereference symlinks if POSIXLY_CORRECT + is set. + 2005-07-29 13:57 Christos Zoulas <christos@zoulas.com> * Avoid search and regex buffer overflows (Kelledin) diff --git a/doc/file.man b/doc/file.man index 22fd61ad..0790ea9c 100644 --- a/doc/file.man +++ b/doc/file.man @@ -1,12 +1,12 @@ .TH FILE __CSECTION__ "Copyright but distributable" -.\" $Id: file.man,v 1.55 2005/02/09 19:07:30 christos Exp $ +.\" $Id: file.man,v 1.56 2005/08/12 14:19:33 christos Exp $ .SH NAME file \- determine file type .SH SYNOPSIS .B file [ -.B \-bcikLnNprsvz +.B \-bchikLnNprsvz ] [ .B \-f @@ -186,6 +186,13 @@ to test the standard input, use ``\-'' as a filename argument. Use the specified string as the separator between the filename and the file result returned. Defaults to ``:''. .TP 8 +.B "\-h, \-\-no-dereference" +option causes symlinks not to be followed +(on systems that support symbolic links). This is the default if the +environment variable +.I POSIXLY_CORRECT +is not defined. +.TP 8 .B "\-i, \-\-mime" Causes the file command to output mime type strings rather than the more traditional human readable ones. Thus it may say @@ -203,8 +210,11 @@ Don't stop at the first match, keep going. .TP 8 .B "\-L, \-\-dereference" option causes symlinks to be followed, as the like-named option in -.BR ls (1). +.BR ls (1) (on systems that support symbolic links). +This is the default if the environment variable +.I POSIXLY_CORRECT +is defined. .TP 8 .BI "\-m, \-\-magic\-file" " list" Specify an alternate list of files containing magic numbers. @@ -293,6 +303,18 @@ will not attempt to open .B $HOME/.magic . .B file adds ".mime" and/or ".mgc" to the value of this variable as appropriate. +The environment variable +.B POSIXLY_CORRECT +controls (on systems that support symbolic links), if +.B file +will attempt to follow symlinks or not. If set, then +.B file +follows symlink, otherwise it does not. This is also controlled +by the +.B L +and +.B h +options. .SH SEE ALSO .BR magic (__FSECTION__) \- description of magic file format. @@ -72,12 +72,12 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$Id: file.c,v 1.96 2005/03/06 05:58:22 christos Exp $") +FILE_RCSID("@(#)$Id: file.c,v 1.97 2005/08/12 14:19:33 christos Exp $") #endif /* lint */ #ifdef S_IFLNK -#define SYMLINKFLAG "L" +#define SYMLINKFLAG "Lh" #else #define SYMLINKFLAG "" #endif @@ -127,7 +127,7 @@ main(int argc, char *argv[]) int flags = 0; char *home, *usermagic; struct stat sb; -#define OPTSTRING "bcCdf:F:ikLm:nNprsvz" +#define OPTSTRING "bcCdf:F:hikLm:nNprsvz" #ifdef HAVE_GETOPT_LONG int longindex; private struct option long_options[] = @@ -143,6 +143,7 @@ main(int argc, char *argv[]) {"keep-going", 0, 0, 'k'}, #ifdef S_IFLNK {"dereference", 0, 0, 'L'}, + {"no-dereference", 0, 0, 'h'}, #endif {"magic-file", 1, 0, 'm'}, #if defined(HAVE_UTIME) || defined(HAVE_UTIMES) @@ -187,6 +188,9 @@ main(int argc, char *argv[]) } } +#ifdef S_IFLNK + flags |= getenv("POSIXLY_CORRECT") ? MAGIC_SYMLINK : 0; +#endif #ifndef HAVE_GETOPT_LONG while ((c = getopt(argc, argv, OPTSTRING)) != -1) #else @@ -261,6 +265,9 @@ main(int argc, char *argv[]) case 'L': flags |= MAGIC_SYMLINK; break; + case 'h': + flags &= ~MAGIC_SYMLINK; + break; #endif case '?': default: |