Sanity.
authorjbj <devnull@localhost>
Tue, 1 Oct 2002 21:46:33 +0000 (21:46 +0000)
committerjbj <devnull@localhost>
Tue, 1 Oct 2002 21:46:33 +0000 (21:46 +0000)
CVS patchset: 5745
CVS date: 2002/10/01 21:46:33

12 files changed:
file/.lclintrc
file/Makefile.am
file/acinclude.m4
file/apprentice.c
file/ascmagic.c
file/file.c
file/file.h
file/fsmagic.c
file/is_tar.c
file/softmagic.c
file/system.h
file/tar.h

index d1c90c9..7bba368 100644 (file)
@@ -1,4 +1,4 @@
--I. -DHAVE_CONFIG_H -DSTDC
+-I. -DHAVE_CONFIG_H -DSTDC -D_GNU_SOURCE -D__GLIBC__ -D__STDC__=1 -DHAVE_STRUCT_STAT_ST_RDEV
 
 #+partial
 +forcehints
 -exportheader          # 19
 -formatconst           # 9
 -macroredef            # 1 tar.h
--moduncon              # 1 getopt_long
--modunconnomods                # 12 ctype.h
--mustmod               # 1 mman.h
--noparams              # 3 getopt_long
 -nullderef             # 4
 -nullpass              # 27
 -nullptrarith          # 1
 -redef                 # 4
 -sizeoftype            # 29
 -uniondef              # 6
--usevarargs            # 1
 
 # --- +partial artifacts
--exportlocal           # 18
 
 # --- not-yet at strict level
 -bitwisesigned         # 47
 -elseifcomplete                # 3
--fielduse              # 21 tar.h
+#-fielduse             # 21 tar.h
 -forblock              # 6
 -ifblock               # 231
 -incondefs             # 36
index 667c057..04a9413 100644 (file)
@@ -21,11 +21,12 @@ man_MANS = file.1 $(man_MAGIC)
 file_SOURCES = file.c apprentice.c fsmagic.c softmagic.c ascmagic.c \
        compress.c is_tar.c readelf.c print.c \
        file.h names.h patchlevel.h readelf.h tar.h
+file_LDFLAGS = -all-static
 
-EXTRA_DIST = LEGAL.NOTICE MAINT PORTING Makefile.std magic2mime \
+EXTRA_DIST = LEGAL.NOTICE MAINT Makefile.std magic2mime \
        Localstuff Header $(magic_FRAGMENTS) file.man magic.man
 
-CLEANFILES = $(man_MANS) magic magic.mgc magic.mime.mgc
+BUILT_SOURCES = $(man_MANS) magic magic.mgc magic.mime.mgc
 
 magic: Header Localstuff $(magic_FRAGMENTS)
        cat $(srcdir)/Header $(srcdir)/Localstuff > $@
index bf71c79..bd52776 100644 (file)
@@ -204,8 +204,7 @@ AC_DEFUN([AC_SYS_LARGEFILE],
      [  --disable-largefile     omit support for large files])
    if test "$enable_largefile" != no; then
 
-     AC_CACHE_CHECK([for special C compiler options needed for large files=
-],
+     AC_CACHE_CHECK([for special C compiler options needed for large files],
        ac_cv_sys_largefile_CC,
        [ac_cv_sys_largefile_CC=no
         if test "$GCC" != yes; then
index 7136e37..ca3938a 100644 (file)
@@ -55,9 +55,9 @@ FILE_RCSID("@(#)Id: apprentice.c,v 1.49 2002/07/03 19:00:41 christos Exp ")
 
 /*@unchecked@*/
 #ifdef __EMX__
-  char PATHSEP=';';
+  static char PATHSEP=';';
 #else
-  char PATHSEP=':';
+  static char PATHSEP=':';
 #endif
 
 /*@unchecked@*/
index 89e839a..5eff3a9 100644 (file)
@@ -190,7 +190,7 @@ looks_extended(const unsigned char *buf, int nbytes,
        return 1;
 }
 
-int
+static int
 looks_utf8(const unsigned char *buf, int nbytes,
                /*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
        /*@modifies *ubuf, *ulen @*/
@@ -319,7 +319,7 @@ looks_unicode(const unsigned char *buf, int nbytes,
  */
 
 /*@unchecked@*/ /*@observer@*/
-unsigned char ebcdic_to_ascii[] = {
+static unsigned char ebcdic_to_ascii[] = {
   0,   1,   2,   3, 156,   9, 134, 127, 151, 141, 142,  11,  12,  13,  14,  15,
  16,  17,  18,  19, 157, 133,   8, 135,  24,  25, 146, 143,  28,  29,  30,  31,
 128, 129, 130, 131, 132,  10,  23,  27, 136, 137, 138, 139, 140,   5,   6,   7,
@@ -353,7 +353,7 @@ unsigned char ebcdic_to_ascii[] = {
  */
 
 /*@unchecked@*/ /*@unused@*/ /*@observer@*/
-unsigned char ebcdic_1047_to_8859[] = {
+static unsigned char ebcdic_1047_to_8859[] = {
 0x00,0x01,0x02,0x03,0x9C,0x09,0x86,0x7F,0x97,0x8D,0x8E,0x0B,0x0C,0x0D,0x0E,0x0F,
 0x10,0x11,0x12,0x13,0x9D,0x0A,0x08,0x87,0x18,0x19,0x92,0x8F,0x1C,0x1D,0x1E,0x1F,
 0x80,0x81,0x82,0x83,0x84,0x85,0x17,0x1B,0x88,0x89,0x8A,0x8B,0x8C,0x05,0x06,0x07,
index c1e1607..5dca051 100644 (file)
@@ -52,21 +52,28 @@ int os2_apptype (const char *fn, char *buf, int nb);
 #define        MAXPATHLEN      512
 #endif
 
+                       /* Global command-line options          */
 /*@unchecked@*/
-int                    /* Global command-line options          */
-       debug = 0,      /* debugging                            */
-       lflag = 0,      /* follow Symlinks (BSD only)           */
-       bflag = 0,      /* brief output format                  */
-       zflag = 0,      /* follow (uncompress) compressed files */
-       sflag = 0,      /* read block special files             */
-       iflag = 0,
-       nobuffer = 0,   /* Do not buffer stdout */
-       kflag = 0;      /* Keep going after the first match     */
+       int     debug = 0;      /* debugging                            */
+/*@unchecked@*/
+       int     lflag = 0;      /* follow Symlinks (BSD only)           */
+/*@unchecked@*/
+static int     bflag = 0;      /* brief output format                  */
+/*@unchecked@*/
+       int     zflag = 0;      /* follow (uncompress) compressed files */
+/*@unchecked@*/
+       int     sflag = 0;      /* read block special files             */
+/*@unchecked@*/
+       int     iflag = 0;
+/*@unchecked@*/
+static int     nobuffer = 0;   /* Do not buffer stdout */
+/*@unchecked@*/
+       int     kflag = 0;      /* Keep going after the first match     */
 
 /*@unchecked@*/ /*@null@*/
 const char *magicfile = 0;     /* where the magic is           */
 /*@unchecked@*/ /*@observer@*/
-const char *default_magicfile = MAGIC;
+static const char *default_magicfile = MAGIC;
 
 /*@unchecked@*/
 char *progname;                /* used throughout                      */
@@ -373,8 +380,10 @@ main(int argc, char **argv)
 #ifndef HAVE_GETOPT_H
        while ((c = getopt(argc, argv, OPTSTRING)) != -1)
 #else
+/*@-compdef @*/
        while ((c = getopt_long(argc, argv, OPTSTRING, long_options,
            &longindex)) != -1)
+/*@=compdef @*/
 #endif
        {
                switch (c) {
index d66198b..de861e5 100644 (file)
@@ -124,6 +124,7 @@ extern int lineno;          /* current line number in magic file    */
 /*@unchecked@*/
 extern struct mlist mlist;     /* list of arrays of magic entries      */
 
+/*@-exportlocal@*/
 /*@unchecked@*/
 extern int debug;              /* enable debugging?                    */
 /*@unchecked@*/
@@ -134,13 +135,9 @@ extern int lflag;          /* follow symbolic links?               */
 extern int sflag;              /* read/analyze block special files?    */
 /*@unchecked@*/
 extern int iflag;              /* Output types as mime-types           */
-
-#ifdef NEED_GETOPT
-/*@unchecked@*/
-extern int optind;             /* From getopt(3)                       */
 /*@unchecked@*/
-extern char *optarg;
-#endif
+extern int kflag;              /* Keep going after the first match     */
+/*@=exportlocal@*/
 
 /*@mayexit@*/
 extern int   apprentice(const char *fn, int action)
@@ -158,8 +155,8 @@ extern void  ckfputs(const char *str, FILE *fil)
        /*@modifies fil, fileSystem @*/;
 struct stat;
 extern int   fsmagic(const char *fn, /*@out@*/ struct stat *sb)
-       /*@globals fileSystem @*/
-       /*@modifies *sb, fileSystem @*/;
+       /*@globals fileSystem, internalState @*/
+       /*@modifies *sb, fileSystem, internalState @*/;
 /*@observer@*/
 extern char *fmttime(long v, int local)
        /*@*/;
index f837772..3dae102 100644 (file)
@@ -40,7 +40,7 @@ fsmagic(const char *fn, struct stat *sb)
         * Fstat is cheaper but fails for files you don't have read perms on.
         * On 4.2BSD and similar systems, use lstat() to identify symlinks.
         */
-#ifdef S_IFLNK
+#if defined(S_IFLNK) || defined(__LCLINT__)
        if (!lflag)
                ret = lstat(fn, sb);
        else
@@ -62,13 +62,13 @@ fsmagic(const char *fn, struct stat *sb)
                }
        }
        else {
-#ifdef S_ISUID
+#if defined(S_ISUID) || defined(__LCLINT__)
                if (sb->st_mode & S_ISUID) ckfputs("setuid ", stdout);
 #endif
-#ifdef S_ISGID
+#if defined(S_ISGID) || defined(__LCLINT__)
                if (sb->st_mode & S_ISGID) ckfputs("setgid ", stdout);
 #endif
-#ifdef S_ISVTX
+#if defined(S_ISVTX) || defined(__LCLINT__)
                if (sb->st_mode & S_ISVTX) ckfputs("sticky ", stdout);
 #endif
        }
@@ -77,7 +77,7 @@ fsmagic(const char *fn, struct stat *sb)
        case S_IFDIR:
                ckfputs("directory", stdout);
                return 1;
-#ifdef S_IFCHR
+#if defined(S_IFCHR) || defined(__LCLINT__)
        case S_IFCHR:
                /* 
                 * If -s has been specified, treat character special files
@@ -86,7 +86,7 @@ fsmagic(const char *fn, struct stat *sb)
                 */
                if (sflag)
                        break;
-#ifdef HAVE_ST_RDEV
+#ifdef HAVE_STRUCT_STAT_ST_RDEV
 # ifdef dv_unit
                (void) printf("character special (%d/%d/%d)",
                        major(sb->st_rdev),
@@ -101,7 +101,7 @@ fsmagic(const char *fn, struct stat *sb)
 #endif
                return 1;
 #endif
-#ifdef S_IFBLK
+#if defined(S_IFBLK) || defined(__LCLINT__)
        case S_IFBLK:
                /* 
                 * If -s has been specified, treat block special files
@@ -110,7 +110,7 @@ fsmagic(const char *fn, struct stat *sb)
                 */
                if (sflag)
                        break;
-#ifdef HAVE_ST_RDEV
+#ifdef HAVE_STRUCT_STAT_ST_RDEV
 # ifdef dv_unit
                (void) printf("block special (%d/%d/%d)",
                        major(sb->st_rdev),
@@ -126,23 +126,24 @@ fsmagic(const char *fn, struct stat *sb)
                return 1;
 #endif
        /* TODO add code to handle V7 MUX and Blit MUX files */
-#ifdef S_IFIFO
+#if defined(S_IFIFO) || defined(__LCLINT__)
        case S_IFIFO:
                ckfputs("fifo (named pipe)", stdout);
                return 1;
 #endif
-#ifdef S_IFDOOR
+#if defined(S_IFDOOR)
        case S_IFDOOR:
                ckfputs("door", stdout);
                return 1;
 #endif
-#ifdef S_IFLNK
+#if defined(S_IFLNK) || defined(__LCLINT__)
        case S_IFLNK:
                {
                        char buf[BUFSIZ+4];
                        int nch;
                        struct stat tstatbuf;
 
+                       buf[0] = '\0';
                        if ((nch = readlink(fn, buf, BUFSIZ-1)) <= 0) {
                                ckfprintf(stdout, "unreadable symlink (%s).", 
                                      strerror(errno));
@@ -151,6 +152,7 @@ fsmagic(const char *fn, struct stat *sb)
                        buf[nch] = '\0';        /* readlink(2) forgets this */
 
                        /* If broken symlink, say so and quit early. */
+/*@-branchstate@*/
                        if (*buf == '/') {
                            if (stat(buf, &tstatbuf) < 0) {
                                ckfprintf(stdout,
@@ -177,6 +179,7 @@ fsmagic(const char *fn, struct stat *sb)
                                return 1;
                            }
                         }
+/*@=branchstate@*/
 
                        /* Otherwise, handle it. */
                        if (lflag) {
@@ -189,7 +192,7 @@ fsmagic(const char *fn, struct stat *sb)
                }
                return 1;
 #endif
-#ifdef S_IFSOCK
+#if defined(S_IFSOCK)
 #ifndef __COHERENT__
        case S_IFSOCK:
                ckfputs("socket", stdout);
index 74b0284..2146071 100644 (file)
@@ -80,12 +80,12 @@ is_tar(unsigned char *buf, int nbytes)
        /* Adjust checksum to count the "chksum" field as blanks. */
        for (i = sizeof(header->header.chksum); --i >= 0;)
                sum -= 0xFF & header->header.chksum[i];
-       sum += ' '* sizeof header->header.chksum;       
+       sum += ' ' * sizeof header->header.chksum;      
 
        if (sum != recsum)
                return 0;       /* Not a tar archive */
        
-       if (0==strcmp(header->header.magic, TMAGIC)) 
+       if (!strcmp(header->header.magic, TMAGIC)) 
                return 2;               /* Unix Standard tar archive */
 
        return 1;                       /* Old fashioned tar archive */
index e58de62..3f935c9 100644 (file)
 
 FILE_RCSID("@(#)Id: softmagic.c,v 1.51 2002/07/03 18:26:38 christos Exp ")
 
-/*@-redecl@*/
-/*@unchecked@*/
-extern int kflag;
-/*@=redecl@*/
-
 static int32_t
 mprint(union VALUETYPE *p, struct magic *m)
        /*@globals fileSystem @*/
@@ -1109,9 +1104,10 @@ softmagic(unsigned char *buf, int nbytes)
 {
        struct mlist *ml;
 
-       for (ml = mlist.next; ml != &mlist; ml = ml->next)
+       for (ml = mlist.next; ml != &mlist; ml = ml->next) {
                if (match(ml->magic, ml->nmagic, buf, nbytes))
                        return 1;
+       }
 
        return 0;
 }
index 56244f9..a705558 100644 (file)
@@ -53,10 +53,20 @@ extern int errno;
 
 #if defined (__GLIBC__) && defined(__LCLINT__)
 /*@-declundef@*/
+/*@-exportfcn@*/
+extern __const unsigned short int **__ctype_b_loc (void)
+     __attribute__ ((__const)) /*@*/;
+extern __const __int32_t **__ctype_tolower_loc (void)
+     __attribute__ ((__const)) /*@*/;
+extern __const __int32_t **__ctype_toupper_loc (void)
+     __attribute__ ((__const)) /*@*/;
+/*@=exportfcn@*/
+/*@-exportvar@*/
 /*@unchecked@*/
 extern __const __int32_t *__ctype_tolower;
 /*@unchecked@*/
 extern __const __int32_t *__ctype_toupper;
+/*@=exportvar@*/
 /*@=declundef@*/
 #endif
 
@@ -65,12 +75,17 @@ extern __const __int32_t *__ctype_toupper;
 #if defined (__GLIBC__) && defined(__LCLINT__)
 /*@-exportlocal@*/
 extern int isalnum(int) __THROW        /*@*/;
+extern int isalpha(int) __THROW        /*@*/;
+extern int isascii(int) __THROW        /*@*/;
 extern int iscntrl(int) __THROW        /*@*/;
+extern int isdigit(int) __THROW        /*@*/;
 extern int isgraph(int) __THROW        /*@*/;
 extern int islower(int) __THROW        /*@*/;
+extern int isprint(int) __THROW        /*@*/;
 extern int ispunct(int) __THROW        /*@*/;
+extern int isspace(int) __THROW        /*@*/;
+extern int isupper(int) __THROW        /*@*/;
 extern int isxdigit(int) __THROW       /*@*/;
-extern int isascii(int) __THROW        /*@*/;
 extern int toascii(int) __THROW        /*@*/;
 extern int _toupper(int) __THROW       /*@*/;
 extern int _tolower(int) __THROW       /*@*/;
@@ -136,9 +151,24 @@ extern int _tolower(int) __THROW   /*@*/;
 #undef HAVE_MAJOR
 
 #ifdef HAVE_GETOPT_H 
+#if defined(__LCLINT__)
+/*@-declundef -exportfcn @*/
+extern int getopt_long (int ___argc, char *const *___argv,
+               const char *__shortopts, const struct option *__longopts,
+               int * __longind)
+       /*@*/;
+/*@=declundef =exportfcn @*/
+#endif
 #include <getopt.h>     /* for long options (is this portable?)*/
 #endif
 
+#ifdef NEED_GETOPT
+/*@unchecked@*/
+extern int optind;             /* From getopt(3)                       */
+/*@unchecked@*/
+extern char *optarg;
+#endif
+
 #if HAVE_REGEX_H
 #include <regex.h>
 #endif
index b8d7c93..d3afb19 100644 (file)
 #define        __tar_h__
 
 /*
- * Kludge for handling systems that can't cope with multiple
- * external definitions of a variable.  In ONE routine (tar.c),
- * we #define TAR_EXTERN to null; here, we set it to "extern" if
- * it is not already set.
- */
-#ifndef TAR_EXTERN
-#define TAR_EXTERN extern
-#endif
-
-/*
  * Header block on tape.
  *
  * I'm going to use traditional DP naming conventions here.
@@ -34,6 +24,7 @@
 #define        TUNMLEN 32
 #define        TGNMLEN 32
 
+/*@-fielduse@*/
 union record {
        char            charptr[RECORDSIZE];
        struct header {
@@ -53,6 +44,7 @@ union record {
                char    devminor[8];
        } header;
 };
+/*@=fielduse@*/
 
 /* The checksum field is filled with this while the checksum is computed. */
 #define        CHKBLANKS       "        "      /* 8 blanks, no null */
@@ -60,6 +52,7 @@ union record {
 /* The magic field is filled with this if uname and gname are valid. */
 #define        TMAGIC          "ustar  "       /* 7 chars and a null */
 
+#if 0
 /* The linkflag defines the type of file */
 #define        LF_OLDNORMAL    '\0'            /* Normal disk file, Unix compat */
 #define        LF_NORMAL       '0'             /* Normal disk file */
@@ -82,40 +75,38 @@ union record {
 #define        EX_SYSTEM       4               /* system gave unexpected error */
 
 
-#if 0
 /*
  * Global variables
  */
-TAR_EXTERN union record        *ar_block;      /* Start of block of archive */
-TAR_EXTERN union record        *ar_record;     /* Current record of archive */
-TAR_EXTERN union record        *ar_last;       /* Last+1 record of archive block */
-TAR_EXTERN char                ar_reading;     /* 0 writing, !0 reading archive */
-TAR_EXTERN int         blocking;       /* Size of each block, in records */
-TAR_EXTERN int         blocksize;      /* Size of each block, in bytes */
-TAR_EXTERN char                *ar_file;       /* File containing archive */
-TAR_EXTERN char                *name_file;     /* File containing names to work on */
-TAR_EXTERN char                *tar;           /* Name of this program */
+extern union record    *ar_block;      /* Start of block of archive */
+extern union record    *ar_record;     /* Current record of archive */
+extern union record    *ar_last;       /* Last+1 record of archive block */
+extern char            ar_reading;     /* 0 writing, !0 reading archive */
+extern int             blocking;       /* Size of each block, in records */
+extern int             blocksize;      /* Size of each block, in bytes */
+extern char            *ar_file;       /* File containing archive */
+extern char            *name_file;     /* File containing names to work on */
+extern char            *tar;           /* Name of this program */
 
 /*
  * Flags from the command line
  */
-TAR_EXTERN char        f_reblock;              /* -B */
-TAR_EXTERN char        f_create;               /* -c */
-TAR_EXTERN char        f_debug;                /* -d */
-TAR_EXTERN char        f_sayblock;             /* -D */
-TAR_EXTERN char        f_follow_links;         /* -h */
-TAR_EXTERN char        f_ignorez;              /* -i */
-TAR_EXTERN char        f_keep;                 /* -k */
-TAR_EXTERN char        f_modified;             /* -m */
-TAR_EXTERN char        f_oldarch;              /* -o */
-TAR_EXTERN char        f_use_protection;       /* -p */
-TAR_EXTERN char        f_sorted_names;         /* -s */
-TAR_EXTERN char        f_list;                 /* -t */
-TAR_EXTERN char        f_namefile;             /* -T */
-TAR_EXTERN char        f_verbose;              /* -v */
-TAR_EXTERN char        f_extract;              /* -x */
-TAR_EXTERN char        f_compress;             /* -z */
-#endif
+extern char    f_reblock;              /* -B */
+extern char    f_create;               /* -c */
+extern char    f_debug;                /* -d */
+extern char    f_sayblock;             /* -D */
+extern char    f_follow_links;         /* -h */
+extern char    f_ignorez;              /* -i */
+extern char    f_keep;                 /* -k */
+extern char    f_modified;             /* -m */
+extern char    f_oldarch;              /* -o */
+extern char    f_use_protection;       /* -p */
+extern char    f_sorted_names;         /* -s */
+extern char    f_list;                 /* -t */
+extern char    f_namefile;             /* -T */
+extern char    f_verbose;              /* -v */
+extern char    f_extract;              /* -x */
+extern char    f_compress;             /* -z */
 
 /*
  * We now default to Unix Standard format rather than 4.2BSD tar format.
@@ -139,13 +130,11 @@ struct name {
        char            name[NAMSIZ+1];
 };
 
-#if 0
-TAR_EXTERN struct name *namelist;      /* Points to first name in list */
-TAR_EXTERN struct name *namelast;      /* Points to last name in list */
+extern struct name     *namelist;      /* Points to first name in list */
+extern struct name     *namelast;      /* Points to last name in list */
 
-TAR_EXTERN int         archive;        /* File descriptor for archive file */
-TAR_EXTERN int         errors;         /* # of files in error */
-#endif
+extern int             archive;        /* File descriptor for archive file */
+extern int             errors;         /* # of files in error */
 
 /*
  *
@@ -165,14 +154,12 @@ struct link {
        char            name[NAMSIZ+1];
 };
 
-#if 0
-TAR_EXTERN struct link *linklist;      /* Points to first link in list */
-
+extern struct link     *linklist;      /* Points to first link in list */
 
 /*
  * Error recovery stuff
  */
-TAR_EXTERN char                read_error_flag;
+extern char            read_error_flag;
 #endif
 
 #endif /* __tar_h__ */