]> granicus.if.org Git - file/commitdiff
Add -h support for POSIX.
authorChristos Zoulas <christos@zoulas.com>
Fri, 12 Aug 2005 14:19:33 +0000 (14:19 +0000)
committerChristos Zoulas <christos@zoulas.com>
Fri, 12 Aug 2005 14:19:33 +0000 (14:19 +0000)
ChangeLog
doc/file.man
src/file.c

index df6a13ecd14dfb65da72bc1d68e31587f399b09d..df95a93ef667d8014119a9cc925b451e423a6d7e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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)
index 22fd61ad5a9c4e9c1cd8fe0be567064039bc00ba..0790ea9ca1a35ffcfe64d59c4aacd341bd7fe657 100644 (file)
@@ -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.
index bace25793cb221db1ff938a5eb16baf0a00dd22a..dd9bde7aac45cd822f1710b873956b8f050c0825 100644 (file)
 #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: