]> granicus.if.org Git - file/commitdiff
more fixes from rrt@
authorChristos Zoulas <christos@zoulas.com>
Thu, 7 Feb 2008 00:58:51 +0000 (00:58 +0000)
committerChristos Zoulas <christos@zoulas.com>
Thu, 7 Feb 2008 00:58:51 +0000 (00:58 +0000)
22 files changed:
.cvsignore
acinclude.m4
configure.ac [moved from configure.in with 100% similarity]
doc/file.man
magic/Magdir/mathcad
magic/Magdir/troff
src/.cvsignore
src/Makefile.am
src/ascmagic.c
src/compress.c
src/file.c
src/file.h
src/fsmagic.c
src/funcs.c
src/getopt_long.c [new file with mode: 0644]
src/magic.c
src/magic.h
src/names.h
src/readelf.h
src/softmagic.c
src/tar.h
src/test.c

index 98b8bcd82042012aaaf8a43f20b0a0a6c9d26159..341d88bbb411b94e6f30f8a22e17f91333173d74 100644 (file)
@@ -5,6 +5,7 @@ aclocal.m4
 config.guess
 config.h.in
 config.sub
+configure
 depcomp
 install-sh
 ltmain.sh
index 3a76bad1c7e8cd2fc07798c7201fe540e60f149e..31677b18215b96063670b96280ba0824f242fd1d 100644 (file)
@@ -1,19 +1,3 @@
-dnl cloned from autoconf 2.13 acspecific.m4
-AC_DEFUN([AC_C_LONG_LONG],
-[AC_CACHE_CHECK(for long long, ac_cv_c_long_long,
-[if test "$GCC" = yes; then
-  ac_cv_c_long_long=yes
-else
-AC_TRY_RUN([int main() {
-long long foo = 0;
-exit(sizeof(long long) < sizeof(long)); }],
-ac_cv_c_long_long=yes, ac_cv_c_long_long=no)
-fi])
-if test $ac_cv_c_long_long = yes; then
-  AC_DEFINE(HAVE_LONG_LONG)
-fi
-])
-
 dnl from autoconf 2.13 acspecific.m4, with changes to check for daylight
 
 AC_DEFUN([AC_STRUCT_TIMEZONE_DAYLIGHT],
@@ -43,7 +27,7 @@ AC_CACHE_CHECK([for tm_isdst in struct tm], ac_cv_struct_tm_isdst,
 #include <$ac_cv_struct_tm>], [struct tm tm; tm.tm_isdst;],
   ac_cv_struct_tm_isdst=yes, ac_cv_struct_tm_isdst=no)])
 if test "$ac_cv_struct_tm_isdst" = yes; then
-  AC_DEFINE(HAVE_TM_ISDST)
+  AC_DEFINE(HAVE_TM_ISDST,1,[HAVE_TM_ISDST])
 fi
 AC_CACHE_CHECK(for daylight, ac_cv_var_daylight,
 [AC_TRY_LINK(
@@ -55,224 +39,6 @@ extern int daylight;
 changequote([, ])dnl
 [atoi(daylight);], ac_cv_var_daylight=yes, ac_cv_var_daylight=no)])
   if test $ac_cv_var_daylight = yes; then
-    AC_DEFINE(HAVE_DAYLIGHT)
+    AC_DEFINE(HAVE_DAYLIGHT,1,[HAVE_DAYLIGHT])
   fi
 ])
-
-dnl from autoconf 2.13 acgeneral.m4, with patch:
-dnl Date: Fri, 15 Jan 1999 05:52:41 -0800
-dnl Message-ID: <199901151352.FAA18237@shade.twinsun.com>
-dnl From: eggert@twinsun.com (Paul Eggert)
-dnl Subject: autoconf 2.13 AC_CHECK_TYPE doesn't allow shell vars
-dnl Newsgroups: gnu.utils.bug
-dnl
-dnl now include <stdint.h> if available
-
-dnl AC_CHECK_TYPE2_STDC(TYPE, DEFAULT)
-AC_DEFUN([AC_CHECK_TYPE2_STDC],
-[AC_REQUIRE([AC_HEADER_STDC])dnl
-AC_REQUIRE([AC_HEADER_STDINT])dnl
-AC_MSG_CHECKING(for $1)
-AC_CACHE_VAL(ac_cv_type_$1,
-[AC_EGREP_CPP(dnl
-[(^|[^a-zA-Z_0-9])$1[^a-zA-Z_0-9]],
-[#if HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#include <sys/types.h>
-#if STDC_HEADERS
-#include <stdlib.h>
-#include <stddef.h>
-#endif], eval "ac_cv_type_$1=yes", eval "ac_cv_type_$1=no")])dnl
-if eval "test \"`echo '$ac_cv_type_'$1`\" = yes"; then
-  AC_MSG_RESULT(yes)
-else
-  AC_MSG_RESULT(no)
-  AC_DEFINE_UNQUOTED($1, $2)
-fi
-])
-
-dnl from autoconf 2.13 acgeneral.m4, with additional third argument
-dnl AC_CHECK_SIZEOF_INCLUDES(TYPE [, CROSS-SIZE [, INCLUDES]])
-AC_DEFUN([AC_CHECK_SIZEOF_INCLUDES],
-[dnl The name to #define.
-define([AC_TYPE_NAME], translit(sizeof_$1, [[[a-z *]]], [[[A-Z_P]]]))dnl
-dnl The cache variable name.
-define([AC_CV_NAME], translit(ac_cv_sizeof_$1, [[[ *]]], [[[_p]]]))dnl
-AC_MSG_CHECKING(size of $1)
-AC_CACHE_VAL(AC_CV_NAME,
-[AC_TRY_RUN([$3
-#include <stdio.h>
-main()
-{
-  FILE *f=fopen("conftestval", "w");
-  if (!f) exit(1);
-  fprintf(f, "%d\n", sizeof($1));
-  exit(0);
-}], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=0, ifelse([$2], , , AC_CV_NAME=$2))])dnl
-AC_MSG_RESULT($AC_CV_NAME)
-AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
-undefine([AC_TYPE_NAME])dnl
-undefine([AC_CV_NAME])dnl
-])
-
-dnl AC_CHECK_SIZEOF_STDC_HEADERS(TYPE [, CROSS_SIZE])
-AC_DEFUN([AC_CHECK_SIZEOF_STDC_HEADERS],
-[AC_REQUIRE([AC_HEADER_STDC])dnl
-AC_REQUIRE([AC_HEADER_STDINT])dnl
-AC_CHECK_SIZEOF_INCLUDES($1, $2,
-[#if HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#include <sys/types.h>
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
-])
-])
-
-
-dnl AC_CHECK_TYPE_STDC(TYPE, DEFAULT)
-AC_DEFUN([AC_CHECK_TYPE_STDC],
-[AC_REQUIRE([AC_HEADER_STDC])dnl
-AC_REQUIRE([AC_HEADER_STDINT])dnl
-AC_MSG_CHECKING(for $1)
-AC_CACHE_VAL(ac_cv_type_$1,
-[AC_EGREP_CPP(dnl
-[(^|[^a-zA-Z_0-9])$1[^a-zA-Z_0-9]],
-[#if HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#include <sys/types.h>
-#if STDC_HEADERS
-#include <stdlib.h>
-#include <stddef.h>
-#endif], ac_cv_type_$1=yes, ac_cv_type_$1=no)])dnl
-AC_MSG_RESULT($ac_cv_type_$1)
-if test $ac_cv_type_$1 = no; then
-  AC_DEFINE($1, $2)
-fi
-])
-
-dnl AC_HEADER_STDINT
-AC_DEFUN([AC_HEADER_STDINT], [AC_CHECK_HEADERS(stdint.h)])
-
-dnl By default, many hosts won't let programs access large files;
-dnl one must use special compiler options to get large-file access to work.
-dnl For more details about this brain damage please see:
-dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
-
-dnl Written by Paul Eggert <eggert@twinsun.com>.
-
-dnl Internal subroutine of AC_SYS_LARGEFILE.
-dnl AC_SYS_LARGEFILE_TEST_INCLUDES
-AC_DEFUN([AC_SYS_LARGEFILE_TEST_INCLUDES],
-  [[#include <sys/types.h>
-    /* Check that off_t can represent 2**63 - 1 correctly.
-       We can't simply "#define LARGE_OFF_T 9223372036854775807",
-       since some C++ compilers masquerading as C compilers
-       incorrectly reject 9223372036854775807.  */
-#   define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
-    int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
-                       && LARGE_OFF_T % 2147483647 == 1)
-                      ? 1 : -1];
-  ]])
-
-dnl Internal subroutine of AC_SYS_LARGEFILE.
-dnl AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR, COMMENT, INCLUDES, FUNCTION-BODY)
-AC_DEFUN([AC_SYS_LARGEFILE_MACRO_VALUE],
-  [AC_CACHE_CHECK([for $1 value needed for large files], $3,
-     [$3=no
-      AC_TRY_COMPILE([$5],
-       [$6],
-       ,
-       [AC_TRY_COMPILE([#define $1 $2]
-[$5]
-          ,
-          [$6],
-          [$3=$2])])])
-   if test "[$]$3" != no; then
-     AC_DEFINE_UNQUOTED([$1], [$]$3, [$4])
-   fi])
-
-AC_DEFUN([AC_SYS_LARGEFILE],
-  [AC_REQUIRE([AC_PROG_CC])
-   AC_ARG_ENABLE(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_cv_sys_largefile_CC,
-       [ac_cv_sys_largefile_CC=no
-        if test "$GCC" != yes; then
-         # IRIX 6.2 and later do not support large files by default,
-         # so use the C compiler's -n32 option if that helps.
-         AC_TRY_COMPILE(AC_SYS_LARGEFILE_TEST_INCLUDES, , ,
-           [ac_save_CC="$CC"
-            CC="$CC -n32"
-            AC_TRY_COMPILE(AC_SYS_LARGEFILE_TEST_INCLUDES, ,
-              ac_cv_sys_largefile_CC=' -n32')
-            CC="$ac_save_CC"])
-        fi])
-     if test "$ac_cv_sys_largefile_CC" != no; then
-       CC="$CC$ac_cv_sys_largefile_CC"
-     fi
-
-     AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64,
-       ac_cv_sys_file_offset_bits,
-       [Number of bits in a file offset, on hosts where this is settable.],
-       AC_SYS_LARGEFILE_TEST_INCLUDES)
-     AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1,
-       ac_cv_sys_large_files,
-       [Define for large files, on AIX-style hosts.],
-       AC_SYS_LARGEFILE_TEST_INCLUDES)
-   fi
-  ])
-
-AC_DEFUN([AC_FUNC_FSEEKO],
-  [AC_SYS_LARGEFILE_MACRO_VALUE(_LARGEFILE_SOURCE, 1,
-     ac_cv_sys_largefile_source,
-     [Define to make fseeko visible on some hosts (e.g. glibc 2.2).],
-     [#include <stdio.h>], [return !fseeko;])
-   # We used to try defining _XOPEN_SOURCE=500 too, to work around a bug
-   # in glibc 2.1.3, but that breaks too many other things.
-   # If you want fseeko and ftello with glibc, upgrade to a fixed glibc.
-
-   AC_CACHE_CHECK([for fseeko], ac_cv_func_fseeko,
-     [ac_cv_func_fseeko=no
-      AC_TRY_LINK([#include <stdio.h>],
-        [return fseeko && fseeko (stdin, 0, 0);],
-       [ac_cv_func_fseeko=yes])])
-   if test $ac_cv_func_fseeko != no; then
-     AC_DEFINE(HAVE_FSEEKO, 1,
-       [Define if fseeko (and presumably ftello) exists and is declared.])
-   fi])
-
-# From Paul Eggert.
-
-# BeOS 5 has <wchar.h> but does not define mbstate_t,
-# so you can't declare an object of that type.
-# Check for this incompatibility with Standard C.
-
-# Include stdlib.h first, because otherwise this test would fail on Linux
-# (at least glibc-2.1.3) because the "_XOPEN_SOURCE 500" definition elicits
-# a syntax error in wchar.h due to the use of undefined __int32_t.
-AC_DEFUN([AC_MBSTATE_T],
-  [
-   AC_CHECK_HEADERS(stdlib.h)
-  
-   AC_CACHE_CHECK([for mbstate_t], ac_cv_type_mbstate_t,
-    [AC_TRY_COMPILE([
-#if HAVE_STDLIB_H 
-# include <stdlib.h>
-#endif
-#include <wchar.h>],
-      [mbstate_t x; return sizeof x;],
-      ac_cv_type_mbstate_t=yes,
-      ac_cv_type_mbstate_t=no)])
-   if test $ac_cv_type_mbstate_t = no; then
-     AC_DEFINE(mbstate_t, int,
-               [Define to a type if <wchar.h> does not define.])
-   fi])
-
-
similarity index 100%
rename from configure.in
rename to configure.ac
index 64e69c9c97ba61f82d741f4851496f1a2c1d10db..ddac0e225c8f119f8023da9d4c20deba736971d1 100644 (file)
@@ -1,4 +1,4 @@
-.\" $File: file.man,v 1.68 2008/02/05 01:58:43 christos Exp $
+.\" $File: file.man,v 1.69 2008/02/05 19:53:17 christos Exp $
 .Dd January 8, 2007
 .Dt FILE __CSECTION__
 .Os
@@ -477,7 +477,7 @@ Contributions by the `&' operator by Rob McMahon, cudcv@warwick.ac.uk, 1989.
 Guy Harris, guy@netapp.com, made many changes from 1993 to the present.
 .Pp
 Primary development and maintenance from 1990 to the present by
-Christos Zoulas (christos@astron.com).
+Christos Zoulas (christos@zoulas.com).
 .Pp
 Altered by Chris Lowth, chris@lowth.com, 2000:
 Handle the 
@@ -537,24 +537,6 @@ is simplistic, inefficient and requires recompilation to update.
 .\" .Pp
 .\" Regular expression support has been done
 .\" The magic file and keywords should have regular expression support.
-Their use of
-.Dv ASCII TAB
-as a field delimiter is ugly and makes
-it hard to edit the files, but is entrenched.
-.Pp
-It might be advisable to allow upper-case letters in keywords
-for e.g.,
-.Xr troff 1
-commands vs man page macros.
-Regular expression support would make this easy.
-.Pp
-The program doesn't grok 
-.Dv FORTRAN .
-It should be able to figure
-.Dv FORTRAN
-by seeing some keywords which 
-appear indented at the start of line.
-Regular expression support would make this easy.
 .Pp
 The list of keywords in 
 .Dv ascmagic
@@ -587,9 +569,6 @@ versus
 Still, if the others don't pan out, it should be possible to use the
 first guess.  
 .Pp
-This program is slower than some vendors' file commands.
-The new support for multiple character codes makes it even slower.
-.Pp
 This manual page, and particularly this section, is too long.
 .Sh RETURN CODE
 .Nm
index 9acb390822f1d67911bb27f0bfdd3bf2c22289ec..41801968888e2a92445045497164b20e6b559d94 100644 (file)
@@ -4,4 +4,4 @@
 # URL: http://www.mathsoft.com/
 # From:        Josh Triplett <josh@freedesktop.org>
 
-0      string  .MCAD\          Mathcad document
+0      string  .MCAD\t         Mathcad document
index 01ad88a0b4457910efc2db64423dd96835cb98fb..320bb6194b2ee2c8643dd95fd270a2c1a537de30 100644 (file)
@@ -6,10 +6,15 @@
 
 # troff input
 0      string          .\\"            troff or preprocessor input text
+!:mime text/troff
 0      string          '\\"            troff or preprocessor input text
+!:mime text/troff
 0      string          '.\\"           troff or preprocessor input text
+!:mime text/troff
 0      string          \\"             troff or preprocessor input text
+!:mime text/troff
 0      string          '''             troff or preprocessor input text
+!:mime text/troff
 
 # ditroff intermediate output text
 0      string          x\ T            ditroff output text
index e750e770909b5e35f1410219108be0887d21fc27..9443f14464eaa6fecc291438fd4030d9acc7aff2 100644 (file)
@@ -10,3 +10,4 @@ stamp-h1
 *.la
 Makefile.in
 file
+test
index 9ab9258c797298f769a7ead2879c3891950b7ab9..7c7de186245a761f9b3df418b7f4e9f7735717d6 100644 (file)
@@ -1,11 +1,16 @@
-MAGIC   = $(pkgdatadir)/magic
+MAGIC = $(pkgdatadir)/magic
 lib_LTLIBRARIES = libmagic.la
 include_HEADERS = magic.h
-EXTRA_DIST = test.c
+EXTRA_DIST = getopt_long.c
 
 bin_PROGRAMS = file
 
-AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"'
+# FIXME: Actually run a test on a magic file
+check_PROGRAMS = test
+test_LDADD = -lmagic
+
+check-local:
+       MAGIC=$(top_builddir)/magic/magic ./test
 
 libmagic_la_SOURCES = magic.c apprentice.c softmagic.c ascmagic.c \
        compress.c is_tar.c readelf.c print.c fsmagic.c \
index ab224ac8ce812108984cc49ddd52636e6cc3547f..bcae753699e093ac45aaf100d75133d0d427ce1e 100644 (file)
@@ -49,7 +49,7 @@
 #include "names.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.53 2007/10/29 00:54:08 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.54 2008/01/26 18:45:16 christos Exp $")
 #endif /* lint */
 
 typedef unsigned long unichar;
@@ -160,31 +160,6 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
                goto done;
        }
 
-       /*
-        * for troff, look for . + letter + letter or .\";
-        * this must be done to disambiguate tar archives' ./file
-        * and other trash from real troff input.
-        *
-        * I believe Plan 9 troff allows non-ASCII characters in the names
-        * of macros, so this test might possibly fail on such a file.
-        */
-       if ((ms->flags & MAGIC_NO_CHECK_TROFF) == 0 && *ubuf == '.') {
-               unichar *tp = ubuf + 1;
-
-               while (ISSPC(*tp))
-                       ++tp;   /* skip leading whitespace */
-               if ((tp[0] == '\\' && tp[1] == '\"') ||
-                   (isascii((unsigned char)tp[0]) &&
-                    isalnum((unsigned char)tp[0]) &&
-                    isascii((unsigned char)tp[1]) &&
-                    isalnum((unsigned char)tp[1]) &&
-                    ISSPC(tp[2]))) {
-                       subtype_mime = "text/troff";
-                       subtype = "troff or preprocessor input";
-                       goto subtype_identified;
-               }
-       }
-
        /* look for tokens from names.h - this is expensive! */
 
        if ((ms->flags & MAGIC_NO_CHECK_TOKENS) != 0)
index 9eaca906eb4475ce8c0381fab83086ff128a8dee..9b41e1dfb064352fc0cdf4064329cf4813aa1d5d 100644 (file)
@@ -56,7 +56,7 @@
 
 
 #ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.54 2007/12/02 00:28:10 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.55 2008/01/26 18:45:16 christos Exp $")
 #endif
 
 private const struct {
@@ -374,6 +374,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
        int r;
 
 #ifdef BUILTIN_DECOMPRESS
+        /* FIXME: This doesn't cope with bzip2 */
        if (method == 2)
                return uncompressgzipped(ms, old, newch, n);
 #endif
index 1750191b2a6cdb74c3b655f64ebe5f09334bfcc4..1268a6e6bbab465b5e7192913f5fe7d97a97f7f5 100644 (file)
 #include <wchar.h>
 #endif
 
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>    /* for long options (is this portable?)*/
-#else
-#undef HAVE_GETOPT_LONG
+#include <getopt.h>
+#ifndef HAVE_GETOPT_LONG
+int getopt_long(int argc, char * const *argv, const char *optstring, const struct option *longopts, int *longindex);
 #endif
 
 #include <netinet/in.h>                /* for byte swapping */
@@ -71,7 +70,7 @@
 #include "patchlevel.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: file.c,v 1.117 2007/12/27 16:35:58 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.118 2008/02/04 20:51:17 christos Exp $")
 #endif /* lint */
 
 
@@ -103,13 +102,7 @@ private struct magic_set *magic;
 
 private void unwrap(char *);
 private void usage(void);
-#ifdef HAVE_GETOPT_LONG
 private void help(void);
-#endif
-#if 0
-private int byteconv4(int, int, int);
-private short byteconv2(int, int, int);
-#endif
 
 int main(int, char *[]);
 private void process(const char *, int);
@@ -130,7 +123,6 @@ main(int argc, char *argv[])
        struct stat sb;
        static const char hmagic[] = "/.magic";
 #define OPTSTRING      "bcCde:f:F:hikLm:nNprsvz0"
-#ifdef HAVE_GETOPT_LONG
        int longindex;
        static const struct option long_options[] =
        {
@@ -143,7 +135,6 @@ main(int argc, char *argv[])
 #undef OPT_LONGONLY
     {0, 0, NULL, 0}
 };
-#endif
 
        static const struct {
                const char *name;
@@ -156,13 +147,10 @@ main(int argc, char *argv[])
                { "soft",       MAGIC_NO_CHECK_SOFT },
                { "tar",        MAGIC_NO_CHECK_TAR },
                { "tokens",     MAGIC_NO_CHECK_TOKENS },
-               { "troff",      MAGIC_NO_CHECK_TROFF },
        };
 
-#ifdef LC_CTYPE
        /* makes islower etc work for other langs */
        (void)setlocale(LC_CTYPE, "");
-#endif
 
 #ifdef __EMX__
        /* sh-like wildcard expansion! Shouldn't hurt at least ... */
@@ -193,14 +181,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
        while ((c = getopt_long(argc, argv, OPTSTRING, long_options,
            &longindex)) != -1)
-#endif
                switch (c) {
-#ifdef HAVE_GETOPT_LONG
                case 0 :
                        switch (longindex) {
                        case 0:
@@ -214,7 +197,6 @@ main(int argc, char *argv[])
                                break;
                        }
                        break;
-#endif
                case '0':
                        nulsep = 1;
                        break;
@@ -439,64 +421,6 @@ process(const char *inname, int wid)
                (void)printf("%s\n", type);
 }
 
-
-#if 0
-/*
- * byteconv4
- * Input:
- *     from            4 byte quantity to convert
- *     same            whether to perform byte swapping
- *     big_endian      whether we are a big endian host
- */
-private int
-byteconv4(int from, int same, int big_endian)
-{
-       if (same)
-               return from;
-       else if (big_endian) {          /* lsb -> msb conversion on msb */
-               union {
-                       int i;
-                       char c[4];
-               } retval, tmpval;
-
-               tmpval.i = from;
-               retval.c[0] = tmpval.c[3];
-               retval.c[1] = tmpval.c[2];
-               retval.c[2] = tmpval.c[1];
-               retval.c[3] = tmpval.c[0];
-
-               return retval.i;
-       }
-       else
-               return ntohl(from);     /* msb -> lsb conversion on lsb */
-}
-
-/*
- * byteconv2
- * Same as byteconv4, but for shorts
- */
-private short
-byteconv2(int from, int same, int big_endian)
-{
-       if (same)
-               return from;
-       else if (big_endian) {          /* lsb -> msb conversion on msb */
-               union {
-                       short s;
-                       char c[2];
-               } retval, tmpval;
-
-               tmpval.s = (short) from;
-               retval.c[0] = tmpval.c[1];
-               retval.c[1] = tmpval.c[0];
-
-               return retval.s;
-       }
-       else
-               return ntohs(from);     /* msb -> lsb conversion on lsb */
-}
-#endif
-
 size_t
 file_mbswidth(const char *s)
 {
@@ -535,13 +459,10 @@ private void
 usage(void)
 {
        (void)fprintf(stderr, USAGE, progname, progname);
-#ifdef HAVE_GETOPT_LONG
        (void)fputs("Try `file --help' for more information.\n", stderr);
-#endif
        exit(1);
 }
 
-#ifdef HAVE_GETOPT_LONG
 private void
 help(void)
 {
@@ -558,4 +479,3 @@ help(void)
 #undef OPT_LONGONLY
        exit(0);
 }
-#endif
index cb4f7f78325f460902d8e490ca57c83170ef386d..f4b4575ffd72157c76b70570f298311be6d19591 100644 (file)
@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.92 2007/11/08 00:31:37 christos Exp $
+ * @(#)$File: file.h,v 1.93 2008/02/04 16:33:46 christos Exp $
  */
 
 #ifndef __file_h__
@@ -87,7 +87,7 @@
 # define HOWMANY (256 * 1024)  /* how much of the file to look at */
 #endif
 #define MAXMAGIS 8192          /* max entries in /etc/magic */
-#define MAXDESC        64              /* max leng of text description */
+#define MAXDESC        64              /* max leng of text description/MIME type */
 #define MAXstring 32           /* max leng of "string" types */
 
 #define MAGICNO                0xF11E041C
index ec7d0c9ca9ac04c291fe34043b74cb633c0514d5..f4866d339f4702636d2664704751e8b10c60fd4b 100644 (file)
@@ -57,7 +57,7 @@
 #undef HAVE_MAJOR
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.47 2007/01/12 17:38:28 christos Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.48 2007/10/17 19:33:31 christos Exp $")
 #endif /* lint */
 
 protected int
@@ -137,7 +137,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
                 */
                if ((ms->flags & MAGIC_DEVICES) != 0)
                        break;
-#ifdef HAVE_ST_RDEV
+#ifdef HAVE_STAT_ST_RDEV
 # ifdef dv_unit
                if (file_printf(ms, "character special (%d/%d/%d)",
                    major(sb->st_rdev), dv_unit(sb->st_rdev),
@@ -163,7 +163,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
                 */
                if ((ms->flags & MAGIC_DEVICES) != 0)
                        break;
-#ifdef HAVE_ST_RDEV
+#ifdef HAVE_STAT_ST_RDEV
 # ifdef dv_unit
                if (file_printf(ms, "block special (%d/%d/%d)",
                    major(sb->st_rdev), dv_unit(sb->st_rdev),
index 3731d9eff2af3e966fb13d495136ebabc6d766a1..b0ce090ea23dc1bde00805c314327daa69126366 100644 (file)
 #if defined(HAVE_WCTYPE_H)
 #include <wctype.h>
 #endif
-#if defined(HAVE_LIMITS_H)
-#include <limits.h>
-#endif
-#ifndef SIZE_T_MAX
-#ifdef __LP64__
-#define SIZE_T_MAX (size_t)0xffffffffffffffffU
-#else
-#define SIZE_T_MAX (size_t)0xffffffffU
-#endif
-#endif
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.35 2007/12/27 16:35:59 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.36 2008/02/04 16:33:46 christos Exp $")
 #endif /* lint */
 
 #ifndef HAVE_VSNPRINTF
@@ -279,7 +269,7 @@ file_getbuffer(struct magic_set *ms)
 
        len = ms->o.size - ms->o.left;
        /* * 4 is for octal representation, + 1 is for NUL */
-       if (len > (SIZE_T_MAX - 1) / 4) {
+       if (len > (SIZE_MAX - 1) / 4) {
                file_oomem(ms, len);
                return NULL;
        }
diff --git a/src/getopt_long.c b/src/getopt_long.c
new file mode 100644 (file)
index 0000000..e6efd0f
--- /dev/null
@@ -0,0 +1,482 @@
+/*     $NetBSD: getopt_long.c,v 1.21.4.1 2008/01/09 01:34:14 matt Exp $        */
+
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <err.h>
+#include <errno.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define REPLACE_GETOPT
+
+#define _DIAGASSERT assert
+
+#ifdef REPLACE_GETOPT
+#ifdef __weak_alias
+__weak_alias(getopt,_getopt)
+#endif
+int    opterr = 1;             /* if error message should be printed */
+int    optind = 1;             /* index into parent argv vector */
+int    optopt = '?';           /* character checked for validity */
+int    optreset;               /* reset getopt */
+char    *optarg;               /* argument associated with option */
+#elif HAVE_NBTOOL_CONFIG_H && !HAVE_DECL_OPTRESET
+static int optreset;
+#endif
+
+#ifdef __weak_alias
+__weak_alias(getopt_long,_getopt_long)
+#endif
+
+#define IGNORE_FIRST   (*options == '-' || *options == '+')
+#define PRINT_ERROR    ((opterr) && ((*options != ':') \
+                                     || (IGNORE_FIRST && options[1] != ':')))
+#define IS_POSIXLY_CORRECT (getenv("POSIXLY_CORRECT") != NULL)
+#define PERMUTE         (!IS_POSIXLY_CORRECT && !IGNORE_FIRST)
+/* XXX: GNU ignores PC if *options == '-' */
+#define IN_ORDER        (!IS_POSIXLY_CORRECT && *options == '-')
+
+/* return values */
+#define        BADCH   (int)'?'
+#define        BADARG          ((IGNORE_FIRST && options[1] == ':') \
+                        || (*options == ':') ? (int)':' : (int)'?')
+#define INORDER (int)1
+
+#define        EMSG    ""
+
+static int getopt_internal __P((int, char **, const char *));
+static int gcd __P((int, int));
+static void permute_args __P((int, int, int, char **));
+
+static const char *place = EMSG; /* option letter processing */
+
+/* XXX: set optreset to 1 rather than these two */
+static int nonopt_start = -1; /* first non option argument (for permute) */
+static int nonopt_end = -1;   /* first option after non options (for permute) */
+
+/* Error messages */
+static const char recargchar[] = "option requires an argument -- %c";
+static const char recargstring[] = "option requires an argument -- %s";
+static const char ambig[] = "ambiguous option -- %.*s";
+static const char noarg[] = "option doesn't take an argument -- %.*s";
+static const char illoptchar[] = "unknown option -- %c";
+static const char illoptstring[] = "unknown option -- %s";
+
+
+/*
+ * Compute the greatest common divisor of a and b.
+ */
+static int
+gcd(a, b)
+       int a;
+       int b;
+{
+       int c;
+
+       c = a % b;
+       while (c != 0) {
+               a = b;
+               b = c;
+               c = a % b;
+       }
+          
+       return b;
+}
+
+/*
+ * Exchange the block from nonopt_start to nonopt_end with the block
+ * from nonopt_end to opt_end (keeping the same order of arguments
+ * in each block).
+ */
+static void
+permute_args(panonopt_start, panonopt_end, opt_end, nargv)
+       int panonopt_start;
+       int panonopt_end;
+       int opt_end;
+       char **nargv;
+{
+       int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+       char *swap;
+
+       _DIAGASSERT(nargv != NULL);
+
+       /*
+        * compute lengths of blocks and number and size of cycles
+        */
+       nnonopts = panonopt_end - panonopt_start;
+       nopts = opt_end - panonopt_end;
+       ncycle = gcd(nnonopts, nopts);
+       cyclelen = (opt_end - panonopt_start) / ncycle;
+
+       for (i = 0; i < ncycle; i++) {
+               cstart = panonopt_end+i;
+               pos = cstart;
+               for (j = 0; j < cyclelen; j++) {
+                       if (pos >= panonopt_end)
+                               pos -= nnonopts;
+                       else
+                               pos += nopts;
+                       swap = nargv[pos];
+                       nargv[pos] = nargv[cstart];
+                       nargv[cstart] = swap;
+               }
+       }
+}
+
+/*
+ * getopt_internal --
+ *     Parse argc/argv argument vector.  Called by user level routines.
+ *  Returns -2 if -- is found (can be long option or end of options marker).
+ */
+static int
+getopt_internal(nargc, nargv, options)
+       int nargc;
+       char **nargv;
+       const char *options;
+{
+       char *oli;                              /* option letter list index */
+       int optchar;
+
+       _DIAGASSERT(nargv != NULL);
+       _DIAGASSERT(options != NULL);
+
+       optarg = NULL;
+
+       /*
+        * XXX Some programs (like rsyncd) expect to be able to
+        * XXX re-initialize optind to 0 and have getopt_long(3)
+        * XXX properly function again.  Work around this braindamage.
+        */
+       if (optind == 0)
+               optind = 1;
+
+       if (optreset)
+               nonopt_start = nonopt_end = -1;
+start:
+       if (optreset || !*place) {              /* update scanning pointer */
+               optreset = 0;
+               if (optind >= nargc) {          /* end of argument vector */
+                       place = EMSG;
+                       if (nonopt_end != -1) {
+                               /* do permutation, if we have to */
+                               permute_args(nonopt_start, nonopt_end,
+                                   optind, nargv);
+                               optind -= nonopt_end - nonopt_start;
+                       }
+                       else if (nonopt_start != -1) {
+                               /*
+                                * If we skipped non-options, set optind
+                                * to the first of them.
+                                */
+                               optind = nonopt_start;
+                       }
+                       nonopt_start = nonopt_end = -1;
+                       return -1;
+               }
+               if ((*(place = nargv[optind]) != '-')
+                   || (place[1] == '\0')) {    /* found non-option */
+                       place = EMSG;
+                       if (IN_ORDER) {
+                               /*
+                                * GNU extension: 
+                                * return non-option as argument to option 1
+                                */
+                               optarg = nargv[optind++];
+                               return INORDER;
+                       }
+                       if (!PERMUTE) {
+                               /*
+                                * if no permutation wanted, stop parsing
+                                * at first non-option
+                                */
+                               return -1;
+                       }
+                       /* do permutation */
+                       if (nonopt_start == -1)
+                               nonopt_start = optind;
+                       else if (nonopt_end != -1) {
+                               permute_args(nonopt_start, nonopt_end,
+                                   optind, nargv);
+                               nonopt_start = optind -
+                                   (nonopt_end - nonopt_start);
+                               nonopt_end = -1;
+                       }
+                       optind++;
+                       /* process next argument */
+                       goto start;
+               }
+               if (nonopt_start != -1 && nonopt_end == -1)
+                       nonopt_end = optind;
+               if (place[1] && *++place == '-') {      /* found "--" */
+                       place++;
+                       return -2;
+               }
+       }
+       if ((optchar = (int)*place++) == (int)':' ||
+           (oli = strchr(options + (IGNORE_FIRST ? 1 : 0), optchar)) == NULL) {
+               /* option letter unknown or ':' */
+               if (!*place)
+                       ++optind;
+               if (PRINT_ERROR)
+                       warnx(illoptchar, optchar);
+               optopt = optchar;
+               return BADCH;
+       }
+       if (optchar == 'W' && oli[1] == ';') {          /* -W long-option */
+               /* XXX: what if no long options provided (called by getopt)? */
+               if (*place) 
+                       return -2;
+
+               if (++optind >= nargc) {        /* no arg */
+                       place = EMSG;
+                       if (PRINT_ERROR)
+                               warnx(recargchar, optchar);
+                       optopt = optchar;
+                       return BADARG;
+               } else                          /* white space */
+                       place = nargv[optind];
+               /*
+                * Handle -W arg the same as --arg (which causes getopt to
+                * stop parsing).
+                */
+               return -2;
+       }
+       if (*++oli != ':') {                    /* doesn't take argument */
+               if (!*place)
+                       ++optind;
+       } else {                                /* takes (optional) argument */
+               optarg = NULL;
+               if (*place)                     /* no white space */
+                       optarg = (char *)place;
+               /* XXX: disable test for :: if PC? (GNU doesn't) */
+               else if (oli[1] != ':') {       /* arg not optional */
+                       if (++optind >= nargc) {        /* no arg */
+                               place = EMSG;
+                               if (PRINT_ERROR)
+                                       warnx(recargchar, optchar);
+                               optopt = optchar;
+                               return BADARG;
+                       } else
+                               optarg = nargv[optind];
+               }
+               place = EMSG;
+               ++optind;
+       }
+       /* dump back option letter */
+       return optchar;
+}
+
+#ifdef REPLACE_GETOPT
+/*
+ * getopt --
+ *     Parse argc/argv argument vector.
+ *
+ * [eventually this will replace the real getopt]
+ */
+int
+getopt(nargc, nargv, options)
+       int nargc;
+       char * const *nargv;
+       const char *options;
+{
+       int retval;
+
+       _DIAGASSERT(nargv != NULL);
+       _DIAGASSERT(options != NULL);
+
+       retval = getopt_internal(nargc, (char **)nargv, options);
+       if (retval == -2) {
+               ++optind;
+               /*
+                * We found an option (--), so if we skipped non-options,
+                * we have to permute.
+                */
+               if (nonopt_end != -1) {
+                       permute_args(nonopt_start, nonopt_end, optind,
+                                    (char **)nargv);
+                       optind -= nonopt_end - nonopt_start;
+               }
+               nonopt_start = nonopt_end = -1;
+               retval = -1;
+       }
+       return retval;
+}
+#endif
+
+/*
+ * getopt_long --
+ *     Parse argc/argv argument vector.
+ */
+int
+getopt_long(nargc, nargv, options, long_options, idx)
+       int nargc;
+       char * const *nargv;
+       const char *options;
+       const struct option *long_options;
+       int *idx;
+{
+       int retval;
+
+#define IDENTICAL_INTERPRETATION(_x, _y)                               \
+       (long_options[(_x)].has_arg == long_options[(_y)].has_arg &&    \
+        long_options[(_x)].flag == long_options[(_y)].flag &&          \
+        long_options[(_x)].val == long_options[(_y)].val)
+
+       _DIAGASSERT(nargv != NULL);
+       _DIAGASSERT(options != NULL);
+       _DIAGASSERT(long_options != NULL);
+       /* idx may be NULL */
+
+       retval = getopt_internal(nargc, (char **)nargv, options);
+       if (retval == -2) {
+               char *current_argv, *has_equal;
+               size_t current_argv_len;
+               int i, ambiguous, match;
+
+               current_argv = (char *)place;
+               match = -1;
+               ambiguous = 0;
+
+               optind++;
+               place = EMSG;
+
+               if (*current_argv == '\0') {            /* found "--" */
+                       /*
+                        * We found an option (--), so if we skipped
+                        * non-options, we have to permute.
+                        */
+                       if (nonopt_end != -1) {
+                               permute_args(nonopt_start, nonopt_end,
+                                            optind, (char **)nargv);
+                               optind -= nonopt_end - nonopt_start;
+                       }
+                       nonopt_start = nonopt_end = -1;
+                       return -1;
+               }
+               if ((has_equal = strchr(current_argv, '=')) != NULL) {
+                       /* argument found (--option=arg) */
+                       current_argv_len = has_equal - current_argv;
+                       has_equal++;
+               } else
+                       current_argv_len = strlen(current_argv);
+           
+               for (i = 0; long_options[i].name; i++) {
+                       /* find matching long option */
+                       if (strncmp(current_argv, long_options[i].name,
+                           current_argv_len))
+                               continue;
+
+                       if (strlen(long_options[i].name) ==
+                           (unsigned)current_argv_len) {
+                               /* exact match */
+                               match = i;
+                               ambiguous = 0;
+                               break;
+                       }
+                       if (match == -1)                /* partial match */
+                               match = i;
+                       else if (!IDENTICAL_INTERPRETATION(i, match))
+                               ambiguous = 1;
+               }
+               if (ambiguous) {
+                       /* ambiguous abbreviation */
+                       if (PRINT_ERROR)
+                               warnx(ambig, (int)current_argv_len,
+                                    current_argv);
+                       optopt = 0;
+                       return BADCH;
+               }
+               if (match != -1) {                      /* option found */
+                       if (long_options[match].has_arg == no_argument
+                           && has_equal) {
+                               if (PRINT_ERROR)
+                                       warnx(noarg, (int)current_argv_len,
+                                            current_argv);
+                               /*
+                                * XXX: GNU sets optopt to val regardless of
+                                * flag
+                                */
+                               if (long_options[match].flag == NULL)
+                                       optopt = long_options[match].val;
+                               else
+                                       optopt = 0;
+                               return BADARG;
+                       }
+                       if (long_options[match].has_arg == required_argument ||
+                           long_options[match].has_arg == optional_argument) {
+                               if (has_equal)
+                                       optarg = has_equal;
+                               else if (long_options[match].has_arg ==
+                                   required_argument) {
+                                       /*
+                                        * optional argument doesn't use
+                                        * next nargv
+                                        */
+                                       optarg = nargv[optind++];
+                               }
+                       }
+                       if ((long_options[match].has_arg == required_argument)
+                           && (optarg == NULL)) {
+                               /*
+                                * Missing argument; leading ':'
+                                * indicates no error should be generated
+                                */
+                               if (PRINT_ERROR)
+                                       warnx(recargstring, current_argv);
+                               /*
+                                * XXX: GNU sets optopt to val regardless
+                                * of flag
+                                */
+                               if (long_options[match].flag == NULL)
+                                       optopt = long_options[match].val;
+                               else
+                                       optopt = 0;
+                               --optind;
+                               return BADARG;
+                       }
+               } else {                        /* unknown option */
+                       if (PRINT_ERROR)
+                               warnx(illoptstring, current_argv);
+                       optopt = 0;
+                       return BADCH;
+               }
+               if (long_options[match].flag) {
+                       *long_options[match].flag = long_options[match].val;
+                       retval = 0;
+               } else 
+                       retval = long_options[match].val;
+               if (idx)
+                       *idx = match;
+       }
+       return retval;
+#undef IDENTICAL_INTERPRETATION
+}
index b44dd96113f36b1e90e3306288fdd26296c38753..30104f5bf330e12abe7907d6748a5000a27639b6 100644 (file)
@@ -63,7 +63,7 @@
 #include "patchlevel.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: magic.c,v 1.46 2008/01/30 20:36:13 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.47 2008/02/04 20:51:17 christos Exp $")
 #endif /* lint */
 
 #ifndef PIPE_BUF 
@@ -307,6 +307,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
                errno = 0;
                if ((fd = open(inname, flags)) < 0) {
 #ifdef __CYGWIN__
+                       /* FIXME: Do this with EXEEXT from autotools */
                        char *tmp = alloca(strlen(inname) + 5);
                        (void)strcat(strcpy(tmp, inname), ".exe");
                        if ((fd = open(tmp, flags)) < 0) {
index 6041f548c8f96278ae0c4cc61e91cc0a2f7d3240..ecdd53c1f96bf7d211d13c8365698c122ba10189 100644 (file)
 #define        MAGIC_NO_CHECK_APPTYPE  0x008000 /* Don't check application type */
 #define        MAGIC_NO_CHECK_ELF      0x010000 /* Don't check for elf details */
 #define        MAGIC_NO_CHECK_ASCII    0x020000 /* Don't check for ascii files */
-#define        MAGIC_NO_CHECK_TROFF    0x040000 /* Don't check ascii/troff */
 #define        MAGIC_NO_CHECK_TOKENS   0x100000 /* Don't check ascii/tokens */
 
-/* Defined for backwards compatibility; does nothing */
+/* Defined for backwards compatibility; do nothing */
 #define        MAGIC_NO_CHECK_FORTRAN  0x000000 /* Don't check ascii/fortran */
+#define        MAGIC_NO_CHECK_TROFF    0x000000 /* Don't check ascii/troff */
+
 
 #ifdef __cplusplus
 extern "C" {
index c7cd38e036ba7abf8b587583180303ab7dd0f777..07dd770c9bf4fb695de7d07e200273f2fbaf3da4 100644 (file)
@@ -32,7 +32,7 @@
  * appear at fixed offsets into the file. Don't make HOWMANY
  * too high unless you have a very fast CPU.
  *
- * $File: names.h,v 1.29 2007/12/27 20:30:35 christos Exp $
+ * $File: names.h,v 1.30 2008/01/26 18:45:16 christos Exp $
  */
 
 /*
@@ -144,18 +144,6 @@ static const struct names {
        {"LDFLAGS",     L_MAKE},
        {"all:",        L_MAKE},
        {".PRECIOUS",   L_MAKE},
-/* Too many files of text have these words in them.  Find another way
- * to recognize Fortrash.
- */
-#ifdef NOTDEF
-       {"subroutine",  L_FORT},
-       {"function",    L_FORT},
-       {"block",       L_FORT},
-       {"common",      L_FORT},
-       {"dimension",   L_FORT},
-       {"integer",     L_FORT},
-       {"data",        L_FORT},
-#endif /*NOTDEF*/
        {".ascii",      L_MACH},
        {".asciiz",     L_MACH},
        {".byte",       L_MACH},
index 77cc2ca7b7943f0e592d6b651c85a4967af83699..feb89543e6434cedf8a9d2e3e6592f06c4f50d90 100644 (file)
@@ -44,7 +44,7 @@ typedef uint16_t      Elf32_Half;
 typedef uint32_t       Elf32_Word;
 typedef uint8_t                Elf32_Char;
 
-#if SIZEOF_UINT64_T != 8
+#if SIZEOF_LONG_LONG != 8
 #define USE_ARRAY_FOR_64BIT_TYPES
 typedef        uint32_t        Elf64_Addr[2];
 typedef        uint32_t        Elf64_Off[2];
index 3d1a07ddb85f8dddabb64cc363e83677a7964f8f..8ed031a4945457cf1b81190790c44583abf6a112 100644 (file)
@@ -38,7 +38,7 @@
 
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.103 2007/12/27 16:35:59 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.104 2008/02/04 16:33:46 christos Exp $")
 #endif /* lint */
 
 private int match(struct magic_set *, struct magic *, uint32_t,
@@ -265,7 +265,6 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
                        returnval = 1;
                }
                if ((ms->flags & MAGIC_CONTINUE) == 0 && printed_something) {
-                       fprintf(stderr, "printed something or not continuing %d\n", printed_something);
                        return 1; /* don't keep searching */
                }                       
        }
index da870ab15e4908f7b703060d1a3d2c7d01ec976a..25b4ba7d953d22935837256e240603c6ac994cea 100644 (file)
--- a/src/tar.h
+++ b/src/tar.h
  *
  * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
  *
- * $File: tar.h,v 1.10 2007/01/12 17:38:28 christos Exp $ # checkin only
+ * $File: tar.h,v 1.11 2007/01/16 14:56:45 ljt Exp $ # checkin only
  */
 
-/*
- * Kludge for handling systems that cannot 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.
  *
@@ -78,58 +68,6 @@ union record {
        } header;
 };
 
-/* The checksum field is filled with this while the checksum is computed. */
-#define        CHKBLANKS       "        "      /* 8 blanks, no null */
-
 /* The magic field is filled with this if uname and gname are valid. */
 #define        TMAGIC          "ustar"         /* 5 chars and a null */
 #define        GNUTMAGIC       "ustar  "       /* 7 chars and a null */
-
-/* The linkflag defines the type of file */
-#define        LF_OLDNORMAL    '\0'            /* Normal disk file, Unix compat */
-#define        LF_NORMAL       '0'             /* Normal disk file */
-#define        LF_LINK         '1'             /* Link to previously dumped file */
-#define        LF_SYMLINK      '2'             /* Symbolic link */
-#define        LF_CHR          '3'             /* Character special file */
-#define        LF_BLK          '4'             /* Block special file */
-#define        LF_DIR          '5'             /* Directory */
-#define        LF_FIFO         '6'             /* FIFO special file */
-#define        LF_CONTIG       '7'             /* Contiguous file */
-/* Further link types may be defined later. */
-
-/*
- * Exit codes from the "tar" program
- */
-#define        EX_SUCCESS      0               /* success! */
-#define        EX_ARGSBAD      1               /* invalid args */
-#define        EX_BADFILE      2               /* invalid filename */
-#define        EX_BADARCH      3               /* bad archive */
-#define        EX_SYSTEM       4               /* system gave unexpected error */
-
-/*
- * Structure for keeping track of filenames and lists thereof.
- */
-struct name {
-       struct name     *next;
-       short           length;
-       char            found;
-       char            name[NAMSIZ+1];
-};
-
-/*
- *
- * Due to the next struct declaration, each routine that includes
- * "tar.h" must also include <sys/types.h>.  I tried to make it automatic,
- * but System V has no defines in <sys/types.h>, so there is no way of
- * knowing when it has been included.  In addition, it cannot be included
- * twice, but must be included exactly once.  Argghh!
- *
- * Thanks, typedef.  Thanks, USG.
- */
-struct link {
-       struct link     *next;
-       dev_t           dev;
-       ino_t           ino;
-       short           linkcount;
-       char            name[NAMSIZ+1];
-};
index 55b78d387c0d51495ad8d86e62e08a4896722bc6..94e483bfc22a97ccaed209bee059128ff78ca053 100644 (file)
@@ -34,24 +34,22 @@ main(int argc, char **argv)
     const char *m;
     int i;
 
-    if(argc < 2)
-       return 1;
-
     ms = magic_open(MAGIC_NONE);
     if (ms == NULL) {
-       (void) printf("ERROR: out of memory\n");
+       (void) printf("ERROR opening MAGIC_NONE: out of memory\n");
        return 1;
     }
     if (magic_load(ms, NULL) == -1) {
-       (void) printf("ERROR: %s\n", magic_error(ms));
-       return 1;
+       (void) printf("ERROR loading with NULL file: %s\n", magic_error(ms));
+       return 2;
     }
 
     for (i = 1; i < argc; i++) {
-       if ((m = magic_file(ms, argv[i])) == NULL)
-           (void) printf("ERROR: %s\n", magic_error(ms));
-       else
-           (void) printf("%s: %s\n", argv[i], m);
+        if ((m = magic_file(ms, argv[i])) == NULL) {
+            (void) printf("ERROR loading file %s: %s\n", argv[i], magic_error(ms));
+            return 3;
+        }      else
+            (void) printf("%s: %s\n", argv[i], m);
     }
 
     magic_close(ms);