Browse Source

Import upstream version 4.26

Christos Zoulas 11 years ago
parent
commit
2af85bfcf5
35 changed files with 717 additions and 235 deletions
  1. 15 0
      ChangeLog
  2. 3 2
      Makefile.in
  3. 9 0
      TODO
  4. 6 0
      config.h.in
  5. 224 39
      configure
  6. 29 1
      configure.ac
  7. 1 0
      doc/Makefile.in
  8. 22 2
      doc/magic.man
  9. 7 0
      magic/Magdir/graphviz
  10. 11 11
      magic/Magdir/images
  11. 3 0
      magic/Magdir/jpeg
  12. 4 0
      magic/Magdir/lua
  13. 9 0
      magic/Magdir/sgml
  14. 6 0
      magic/Magdir/warc
  15. 3 1
      magic/Makefile.am
  16. 4 1
      magic/Makefile.in
  17. 1 0
      python/Makefile.in
  18. 2 5
      src/Makefile.am
  19. 3 6
      src/Makefile.in
  20. 28 15
      src/apprentice.c
  21. 6 4
      src/ascmagic.c
  22. 2 2
      src/compress.c
  23. 3 3
      src/elfclass.h
  24. 5 1
      src/file.c
  25. 41 23
      src/file.h
  26. 84 46
      src/fsmagic.c
  27. 18 9
      src/funcs.c
  28. 17 3
      src/getopt_long.c
  29. 26 16
      src/magic.c
  30. 68 0
      src/mygetopt.h
  31. 5 2
      src/patchlevel.h
  32. 38 37
      src/readelf.c
  33. 9 5
      src/softmagic.c
  34. 4 1
      src/vasprintf.c
  35. 1 0
      tests/Makefile.in

+ 15 - 0
ChangeLog

@@ -1,3 +1,18 @@
+2008-08-30 12:54  Christos Zoulas <christos@astron.com>
+
+	* Don't eat trailing \n in magic enties.
+
+	* Cast defines to allow compilation using a c++ compiler.
+
+2008-07-26 00:59  Reuben Thomas  <rrt@sc3d.org>
+
+	* Add MIME types for special files.
+
+	* Use access to give more accurate information for files that
+	  can't be opened.
+
+	* Add a TODO list.
+
 2008-07-02 11:15  Christos Zoulas  <christos@astron.com>
 
 	* add !:strength op to adjust magic strength (experimental)

+ 3 - 2
Makefile.in

@@ -35,8 +35,8 @@ subdir = .
 DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
 	$(srcdir)/Makefile.in $(srcdir)/config.h.in \
 	$(top_srcdir)/configure AUTHORS COPYING ChangeLog INSTALL NEWS \
-	compile config.guess config.sub depcomp install-sh ltmain.sh \
-	missing
+	TODO compile config.guess config.sub depcomp install-sh \
+	ltmain.sh missing
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
 	$(top_srcdir)/configure.ac
@@ -126,6 +126,7 @@ SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
 STRIP = @STRIP@
 VERSION = @VERSION@
+WARNINGS = @WARNINGS@
 abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@

+ 9 - 0
TODO

@@ -0,0 +1,9 @@
+Continue to squash all magic bugs. See Debian BTS for a good source.
+
+Store arbitrarily long strings, for example for %s patterns, so that
+they can be printed out. Fixes Debian bug #271672.
+
+Add syntax for other sorts of counted string (Debian bug #466032). Use
+to fix bug #283760.
+
+Add syntax for relative offsets after current level (Debian bug #466037).

+ 6 - 0
config.h.in

@@ -15,12 +15,18 @@
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
+/* Define to 1 if you have the <err.h> header file. */
+#undef HAVE_ERR_H
+
 /* Define to 1 if you have the <fcntl.h> header file. */
 #undef HAVE_FCNTL_H
 
 /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
 #undef HAVE_FSEEKO
 
+/* Define to 1 if you have the <getopt.h> header file. */
+#undef HAVE_GETOPT_H
+
 /* Define to 1 if you have the `getopt_long' function. */
 #undef HAVE_GETOPT_LONG
 

+ 224 - 39
configure

@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.61 for file 4.25.
+# Generated by GNU Autoconf 2.61 for file 4.26.
 #
 # Report bugs to <christos@astron.com>.
 #
@@ -728,8 +728,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
 # Identity of this package.
 PACKAGE_NAME='file'
 PACKAGE_TARNAME='file'
-PACKAGE_VERSION='4.25'
-PACKAGE_STRING='file 4.25'
+PACKAGE_VERSION='4.26'
+PACKAGE_STRING='file 4.26'
 PACKAGE_BUGREPORT='christos@astron.com'
 
 # Factoring default headers for most tests.
@@ -830,6 +830,7 @@ am__untar
 fsect
 FSECT5_TRUE
 FSECT5_FALSE
+WARNINGS
 CC
 CFLAGS
 LDFLAGS
@@ -1394,7 +1395,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures file 4.25 to adapt to many kinds of systems.
+\`configure' configures file 4.26 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1464,7 +1465,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of file 4.25:";;
+     short | recursive ) echo "Configuration of file 4.26:";;
    esac
   cat <<\_ACEOF
 
@@ -1482,6 +1483,7 @@ Optional Features:
                           optimize for fast installation [default=yes]
   --disable-libtool-lock  avoid locking (might break parallel builds)
   --disable-largefile     omit support for large files
+  --disable-warnings	disable compiler warnings
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -1570,7 +1572,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-file configure 4.25
+file configure 4.26
 generated by GNU Autoconf 2.61
 
 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1584,7 +1586,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by file $as_me 4.25, which was
+It was created by file $as_me 4.26, which was
 generated by GNU Autoconf 2.61.  Invocation command line was
 
   $ $0 $@
@@ -2274,7 +2276,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='file'
- VERSION='4.25'
+ VERSION='4.26'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -2506,6 +2508,7 @@ echo "${ECHO_T}no" >&6; }
 fi
 
 
+
  if test x$fsect = x5; then
   FSECT5_TRUE=
   FSECT5_FALSE='#'
@@ -2515,6 +2518,8 @@ else
 fi
 
 
+
+
 cat >>confdefs.h <<\_ACEOF
 #define _GNU_SOURCE 1
 _ACEOF
@@ -4598,7 +4603,7 @@ ia64-*-hpux*)
   ;;
 *-*-irix6*)
   # Find out which ABI we are using.
-  echo '#line 4601 "configure"' > conftest.$ac_ext
+  echo '#line 4606 "configure"' > conftest.$ac_ext
   if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
@@ -7344,11 +7349,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:7347: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:7352: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:7351: \$? = $ac_status" >&5
+   echo "$as_me:7356: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -7606,11 +7611,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:7609: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:7614: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:7613: \$? = $ac_status" >&5
+   echo "$as_me:7618: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -7668,11 +7673,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:7671: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:7676: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:7675: \$? = $ac_status" >&5
+   echo "$as_me:7680: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -9871,7 +9876,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 9874 "configure"
+#line 9879 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -9969,7 +9974,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 9972 "configure"
+#line 9977 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12213,11 +12218,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:12216: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:12221: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:12220: \$? = $ac_status" >&5
+   echo "$as_me:12225: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -12275,11 +12280,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:12278: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:12283: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:12282: \$? = $ac_status" >&5
+   echo "$as_me:12287: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -13611,7 +13616,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 13614 "configure"
+#line 13619 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13709,7 +13714,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 13712 "configure"
+#line 13717 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -14594,11 +14599,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:14597: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:14602: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:14601: \$? = $ac_status" >&5
+   echo "$as_me:14606: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -14656,11 +14661,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:14659: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:14664: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:14663: \$? = $ac_status" >&5
+   echo "$as_me:14668: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -16773,11 +16778,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:16776: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:16781: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:16780: \$? = $ac_status" >&5
+   echo "$as_me:16785: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -17035,11 +17040,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:17038: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:17043: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:17042: \$? = $ac_status" >&5
+   echo "$as_me:17047: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -17097,11 +17102,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:17100: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:17105: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:17104: \$? = $ac_status" >&5
+   echo "$as_me:17109: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -19300,7 +19305,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 19303 "configure"
+#line 19308 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19398,7 +19403,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 19401 "configure"
+#line 19406 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -21326,6 +21331,152 @@ done
 
 
 
+for ac_header in getopt.h err.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  { echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+ac_res=`eval echo '${'$as_ac_Header'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <$ac_header>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
+    ( cat <<\_ASBOX
+## ---------------------------------- ##
+## Report this to christos@astron.com ##
+## ---------------------------------- ##
+_ASBOX
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+{ echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  eval "$as_ac_Header=\$ac_header_preproc"
+fi
+ac_res=`eval echo '${'$as_ac_Header'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+
 
 
 
@@ -23562,6 +23713,39 @@ _ACEOF
 
 
 
+{ echo "$as_me:$LINENO: checking for gcc compiler warnings" >&5
+echo $ECHO_N "checking for gcc compiler warnings... $ECHO_C" >&6; }
+# Check whether --enable-warnings was given.
+if test "${enable_warnings+set}" = set; then
+  enableval=$enable_warnings; if test "${enableval}" = no -o $GCC = no; then
+   { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+   WARNINGS=
+else
+   { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+   WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
+       -Wmissing-declarations -Wredundant-decls -Wnested-externs \
+       -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
+       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter"
+fi
+else
+
+if test $GCC = no; then
+   WARNINGS=
+   { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+else
+   { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+   WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
+       -Wmissing-declarations -Wredundant-decls -Wnested-externs \
+       -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
+       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter"
+fi
+fi
+
+
 
 
 
@@ -24285,7 +24469,7 @@ exec 6>&1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by file $as_me 4.25, which was
+This file was extended by file $as_me 4.26, which was
 generated by GNU Autoconf 2.61.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -24338,7 +24522,7 @@ Report bugs to <bug-autoconf@gnu.org>."
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF
 ac_cs_version="\\
-file config.status 4.25
+file config.status 4.26
 configured by $0, generated by GNU Autoconf 2.61,
   with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 
@@ -24584,6 +24768,7 @@ am__untar!$am__untar$ac_delim
 fsect!$fsect$ac_delim
 FSECT5_TRUE!$FSECT5_TRUE$ac_delim
 FSECT5_FALSE!$FSECT5_FALSE$ac_delim
+WARNINGS!$WARNINGS$ac_delim
 CC!$CC$ac_delim
 CFLAGS!$CFLAGS$ac_delim
 LDFLAGS!$LDFLAGS$ac_delim
@@ -24618,7 +24803,6 @@ CPP!$CPP$ac_delim
 CXX!$CXX$ac_delim
 CXXFLAGS!$CXXFLAGS$ac_delim
 ac_ct_CXX!$ac_ct_CXX$ac_delim
-CXXDEPMODE!$CXXDEPMODE$ac_delim
 _ACEOF
 
   if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
@@ -24660,6 +24844,7 @@ _ACEOF
 ac_delim='%!_!# '
 for ac_last_try in false false false false false :; do
   cat >conf$$subs.sed <<_ACEOF
+CXXDEPMODE!$CXXDEPMODE$ac_delim
 am__fastdepCXX_TRUE!$am__fastdepCXX_TRUE$ac_delim
 am__fastdepCXX_FALSE!$am__fastdepCXX_FALSE$ac_delim
 CXXCPP!$CXXCPP$ac_delim
@@ -24673,7 +24858,7 @@ IS_CROSS_COMPILE_FALSE!$IS_CROSS_COMPILE_FALSE$ac_delim
 LTLIBOBJS!$LTLIBOBJS$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 11; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 12; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5

+ 29 - 1
configure.ac

@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-AC_INIT(file, 4.25, christos@astron.com)
+AC_INIT(file, 4.26, christos@astron.com)
 AM_INIT_AUTOMAKE
 AM_CONFIG_HEADER(config.h)
 
@@ -45,8 +45,11 @@ fi], [
   AC_MSG_RESULT(no)
   fsect=4
 ])
+
 AC_SUBST(fsect)
 AM_CONDITIONAL(FSECT5, test x$fsect = x5)
+
+AC_SUBST(WARNINGS)
 AC_GNU_SOURCE
 
 dnl Checks for programs.
@@ -62,6 +65,7 @@ AC_HEADER_MAJOR
 AC_HEADER_SYS_WAIT
 AC_CHECK_HEADERS(stdint.h fcntl.h locale.h stdint.h inttypes.h unistd.h)
 AC_CHECK_HEADERS(utime.h wchar.h wctype.h limits.h)
+AC_CHECK_HEADERS(getopt.h err.h)
 AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h)
 AC_CHECK_HEADERS(zlib.h)
 
@@ -107,6 +111,30 @@ typedef long int64_t;
 #endif
 ])
 
+AC_MSG_CHECKING(for gcc compiler warnings)
+AC_ARG_ENABLE(warnings,
+[  --disable-warnings	disable compiler warnings],
+[if test "${enableval}" = no -o $GCC = no; then
+   AC_MSG_RESULT(no)
+   WARNINGS=
+else
+   AC_MSG_RESULT(yes)
+   WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
+       -Wmissing-declarations -Wredundant-decls -Wnested-externs \
+       -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
+       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter"
+fi], [
+if test $GCC = no; then
+   WARNINGS=
+   AC_MSG_RESULT(no)
+else
+   AC_MSG_RESULT(yes)
+   WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
+       -Wmissing-declarations -Wredundant-decls -Wnested-externs \
+       -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
+       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter"
+fi])
+
 dnl Checks for functions
 AC_CHECK_FUNCS(mmap strerror strndup strtoul mbrtowc mkstemp utimes utime wcwidth strtof)
 

+ 1 - 0
doc/Makefile.in

@@ -106,6 +106,7 @@ SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
 STRIP = @STRIP@
 VERSION = @VERSION@
+WARNINGS = @WARNINGS@
 abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@

+ 22 - 2
doc/magic.man

@@ -1,5 +1,5 @@
-.\" $File: magic.man,v 1.56 2008/03/01 22:21:48 rrt Exp $
-.Dd January 10, 2007
+.\" $File: magic.man,v 1.57 2008/08/30 09:50:20 christos Exp $
+.Dd August 30, 2008
 .Dt MAGIC __FSECTION__
 .Os
 .\" install as magic.4 on USG, magic.5 on V7, Berkeley and Linux systems.
@@ -301,6 +301,26 @@ i.e. the literal string
 .Dq !:mime
 followed by the MIME type.
 .Pp
+An optional strength can be supplied on a separate line which refers to
+the current magic description using the following format:
+.Bd -literal -offset indent 
+!:strength OP VALUE
+.Ed
+.Pp
+The operand
+.Dv OP
+can be: 
+.Dv + ,
+.Dv - ,
+.Dv * ,
+or
+.Dv /
+and
+.Dv VALUE
+is a constant between 0 and 255.
+This constant is applied using the specified operand
+to the currently computed default magic strength.
+.Pp
 Some file formats contain additional information which is to be printed
 along with the file type or need additional tests to determine the true
 file type.

+ 7 - 0
magic/Magdir/graphviz

@@ -0,0 +1,7 @@
+
+#------------------------------------------------------------------------------
+# graphviz:  file(1) magic for http://www.graphviz.org/
+0	regex/100	[\r\n\t\ ]*graph[\r\n\t\ ]*.*\\{	graphviz graph text
+!:mime	text/vnd.graphviz
+0	regex/100	[\r\n\t\ ]*digraph[\r\n\t\ ]*.*\\{	graphviz digraph text
+!:mime	text/vnd.graphviz

+ 11 - 11
magic/Magdir/images

@@ -77,17 +77,17 @@
 #
 0	string		\x89PNG\x0d\x0a\x1a\x0a		PNG image
 !:mime	image/png
->>16	belong		x		\b, %ld x
->>20	belong		x		%ld,
->>24	byte		x		%d-bit
->>25	byte		0		grayscale,
->>25	byte		2		\b/color RGB,
->>25	byte		3		colormap,
->>25	byte		4		gray+alpha,
->>25	byte		6		\b/color RGBA,
-#>>26	byte		0		deflate/32K,
->>28	byte		0		non-interlaced
->>28	byte		1		interlaced
+>16	belong		x		\b, %ld x
+>20	belong		x		%ld,
+>24	byte		x		%d-bit
+>25	byte		0		grayscale,
+>25	byte		2		\b/color RGB,
+>25	byte		3		colormap,
+>25	byte		4		gray+alpha,
+>25	byte		6		\b/color RGBA,
+#>26	byte		0		deflate/32K,
+>28	byte		0		non-interlaced
+>28	byte		1		interlaced
 
 # possible GIF replacements; none yet released!
 # (Greg Roelofs, newt@uchicago.edu)

+ 3 - 0
magic/Magdir/jpeg

@@ -10,6 +10,7 @@
 #
 0	beshort		0xffd8		JPEG image data
 !:mime	image/jpeg
+!:strength +1
 >6	string		JFIF		\b, JFIF standard
 # The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
 # in a vain attempt to add image size reporting for JFIF.  Note that these
@@ -126,6 +127,8 @@
 # At least we can show a comment if no other segments got inserted before:
 >(4.S+5)	byte		0xFE
 >>(4.S+8)	string		>\0		\b, comment: "%s"
+# FIXME: When we can do non-byte counted strings, we can use that to get
+# the string's count, and fix Debian bug #283760
 #>(4.S+5)	byte		0xFE		\b, comment
 #>>(4.S+6)	beshort		x		\b length=%d
 #>>(4.S+8)	string		>\0		\b, "%s"

+ 4 - 0
magic/Magdir/lua

@@ -5,9 +5,13 @@
 
 # Lua scripts
 0	search/1/b	#!\ /usr/bin/lua	Lua script text executable
+!:mime	text/x-lua
 0	search/1/b	#!\ /usr/local/bin/lua	Lua script text executable
+!:mime	text/x-lua
 0	search/1	#!/usr/bin/env\ lua	Lua script text executable
+!:mime	text/x-lua
 0	search/1	#!\ /usr/bin/env\ lua	Lua script text executable
+!:mime	text/x-lua
 
 # Lua bytecode
 0	string		\033Lua			Lua bytecode,

+ 9 - 0
magic/Magdir/sgml

@@ -8,6 +8,12 @@
 >>23	search/400	\<gnc-v2		GnuCash file
 !:mime	application/x-gnucash
 
+# Sitemap file
+0	string		\<?xml\ version="
+>15	string		>\0
+>>23	search/400	\<urlset		XML Sitemap document text
+!:mime	application/xml-sitemap
+
 #------------------------------------------------------------------------------
 # sgml:  file(1) magic for Standard Generalized Markup Language
 # HyperText Markup Language (HTML) is an SGML document type,
@@ -30,6 +36,9 @@
 !:mime	application/xml
 0	string		\<?xml\ version="	XML
 !:mime	application/xml
+>15	search/1	>\0			%.3s document text
+>>23	search/1	\<xsl:stylesheet	(XSL stylesheet)
+>>24	search/1	\<xsl:stylesheet	(XSL stylesheet)
 0	string		\<?xml\ version='	XML
 !:mime	application/xml
 >15	search/1	>\0			%.3s document text

+ 6 - 0
magic/Magdir/warc

@@ -0,0 +1,6 @@
+
+#------------------------------------------------------------------------------
+# warc:  file(1) magic for WARC files
+
+0	string	WARC/	WARC Archive
+>5	string	x	version %.4s

+ 3 - 1
magic/Makefile.am

@@ -1,5 +1,5 @@
 #
-# $File: Makefile.am,v 1.41 2008/06/17 17:49:11 christos Exp $
+# $File: Makefile.am,v 1.43 2008/08/08 08:24:06 christos Exp $
 #
 MAGIC_FRAGMENT_BASE = Magdir
 MAGIC_FRAGMENT_DIR = $(top_srcdir)/magic/$(MAGIC_FRAGMENT_BASE)
@@ -79,6 +79,7 @@ $(MAGIC_FRAGMENT_DIR)/gnome-keyring \
 $(MAGIC_FRAGMENT_DIR)/gnu \
 $(MAGIC_FRAGMENT_DIR)/gnumeric \
 $(MAGIC_FRAGMENT_DIR)/grace \
+$(MAGIC_FRAGMENT_DIR)/graphviz \
 $(MAGIC_FRAGMENT_DIR)/gringotts \
 $(MAGIC_FRAGMENT_DIR)/hitachi-sh \
 $(MAGIC_FRAGMENT_DIR)/hp \
@@ -205,6 +206,7 @@ $(MAGIC_FRAGMENT_DIR)/vms \
 $(MAGIC_FRAGMENT_DIR)/vmware \
 $(MAGIC_FRAGMENT_DIR)/vorbis \
 $(MAGIC_FRAGMENT_DIR)/vxl \
+$(MAGIC_FRAGMENT_DIR)/warc \
 $(MAGIC_FRAGMENT_DIR)/weak \
 $(MAGIC_FRAGMENT_DIR)/windows \
 $(MAGIC_FRAGMENT_DIR)/wordprocessors \

+ 4 - 1
magic/Makefile.in

@@ -108,6 +108,7 @@ SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
 STRIP = @STRIP@
 VERSION = @VERSION@
+WARNINGS = @WARNINGS@
 abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
@@ -162,7 +163,7 @@ top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 
 #
-# $File: Makefile.am,v 1.41 2008/06/17 17:49:11 christos Exp $
+# $File: Makefile.am,v 1.43 2008/08/08 08:24:06 christos Exp $
 #
 MAGIC_FRAGMENT_BASE = Magdir
 MAGIC_FRAGMENT_DIR = $(top_srcdir)/magic/$(MAGIC_FRAGMENT_BASE)
@@ -240,6 +241,7 @@ $(MAGIC_FRAGMENT_DIR)/gnome-keyring \
 $(MAGIC_FRAGMENT_DIR)/gnu \
 $(MAGIC_FRAGMENT_DIR)/gnumeric \
 $(MAGIC_FRAGMENT_DIR)/grace \
+$(MAGIC_FRAGMENT_DIR)/graphviz \
 $(MAGIC_FRAGMENT_DIR)/gringotts \
 $(MAGIC_FRAGMENT_DIR)/hitachi-sh \
 $(MAGIC_FRAGMENT_DIR)/hp \
@@ -366,6 +368,7 @@ $(MAGIC_FRAGMENT_DIR)/vms \
 $(MAGIC_FRAGMENT_DIR)/vmware \
 $(MAGIC_FRAGMENT_DIR)/vorbis \
 $(MAGIC_FRAGMENT_DIR)/vxl \
+$(MAGIC_FRAGMENT_DIR)/warc \
 $(MAGIC_FRAGMENT_DIR)/weak \
 $(MAGIC_FRAGMENT_DIR)/windows \
 $(MAGIC_FRAGMENT_DIR)/wordprocessors \

+ 1 - 0
python/Makefile.in

@@ -98,6 +98,7 @@ SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
 STRIP = @STRIP@
 VERSION = @VERSION@
+WARNINGS = @WARNINGS@
 abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@

+ 2 - 5
src/Makefile.am

@@ -5,15 +5,12 @@ include_HEADERS = magic.h
 bin_PROGRAMS = file
 
 AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"'
-AM_CFLAGS = -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
-    -Wmissing-declarations -Wredundant-decls -Wnested-externs \
-    -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
-    -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter
+AM_CFLAGS = @WARNINGS@
 
 libmagic_la_SOURCES = magic.c apprentice.c softmagic.c ascmagic.c \
 	compress.c is_tar.c readelf.c print.c fsmagic.c \
 	funcs.c file.h names.h patchlevel.h readelf.h tar.h apptype.c \
-	file_opts.h elfclass.h
+	file_opts.h elfclass.h mygetopt.h
 libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0
 libmagic_la_LIBADD = $(LTLIBOBJS)
 

+ 3 - 6
src/Makefile.in

@@ -142,6 +142,7 @@ SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
 STRIP = @STRIP@
 VERSION = @VERSION@
+WARNINGS = @WARNINGS@
 abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
@@ -198,15 +199,11 @@ MAGIC = $(pkgdatadir)/magic
 lib_LTLIBRARIES = libmagic.la
 include_HEADERS = magic.h
 AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"'
-AM_CFLAGS = -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
-    -Wmissing-declarations -Wredundant-decls -Wnested-externs \
-    -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
-    -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter
-
+AM_CFLAGS = @WARNINGS@
 libmagic_la_SOURCES = magic.c apprentice.c softmagic.c ascmagic.c \
 	compress.c is_tar.c readelf.c print.c fsmagic.c \
 	funcs.c file.h names.h patchlevel.h readelf.h tar.h apptype.c \
-	file_opts.h elfclass.h
+	file_opts.h elfclass.h mygetopt.h
 
 libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0
 libmagic_la_LIBADD = $(LTLIBOBJS)

+ 28 - 15
src/apprentice.c

@@ -49,7 +49,7 @@
 #include <dirent.h>
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.137 2008/07/02 15:22:47 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.140 2008/07/20 04:02:15 christos Exp $")
 #endif	/* lint */
 
 #define	EATAB {while (isascii((unsigned char) *l) && \
@@ -297,7 +297,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action,
 		return -1;
 	}
 
-	if ((ml = malloc(sizeof(*ml))) == NULL) {
+	if ((ml = CAST(struct mlist *, malloc(sizeof(*ml)))) == NULL) {
 		file_delmagic(magic, mapped, nmagic);
 		file_oomem(ms, sizeof(*ml));
 		return -1;
@@ -360,7 +360,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
 	}
 	fn = mfn;
 
-	if ((mlist = malloc(sizeof(*mlist))) == NULL) {
+	if ((mlist = CAST(struct mlist *, malloc(sizeof(*mlist)))) == NULL) {
 		free(mfn);
 		file_oomem(ms, sizeof(*mlist));
 		return NULL;
@@ -516,6 +516,13 @@ apprentice_magic_strength(const struct magic *m)
 	default:
 		abort();
 	}
+
+	/*
+	 * Magic entries with no description get a bonus because they depend
+	 * on subsequent magic entries to print something.
+	 */
+	if (m->desc[0] == '\0')
+		val++;
 	return val;
 }
 
@@ -525,8 +532,8 @@ apprentice_magic_strength(const struct magic *m)
 private int
 apprentice_sort(const void *a, const void *b)
 {
-	const struct magic_entry *ma = a;
-	const struct magic_entry *mb = b;
+	const struct magic_entry *ma = CAST(const struct magic_entry *, a);
+	const struct magic_entry *mb = CAST(const struct magic_entry *, b);
 	size_t sa = apprentice_magic_strength(ma->mp);
 	size_t sb = apprentice_magic_strength(mb->mp);
 	if (sa == sb)
@@ -676,6 +683,7 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 	int errs = 0;
 	struct magic_entry *marray;
 	uint32_t marraycount, i, mentrycount = 0, starttest;
+	size_t slen;
 	char subfn[MAXPATHLEN];
 	struct stat st;
 	DIR *dir;
@@ -684,7 +692,8 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 	ms->flags |= MAGIC_CHECK;	/* Enable checks for parsed files */
 
         maxmagic = MAXMAGIS;
-	if ((marray = calloc(maxmagic, sizeof(*marray))) == NULL) {
+	if ((marray = CAST(struct magic_entry *, calloc(maxmagic,
+	    sizeof(*marray)))) == NULL) {
 		file_oomem(ms, maxmagic * sizeof(*marray));
 		return -1;
 	}
@@ -772,8 +781,9 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 	for (i = 0; i < marraycount; i++)
 		mentrycount += marray[i].cont_count;
 
-	if ((*magicp = malloc(sizeof(**magicp) * mentrycount)) == NULL) {
-		file_oomem(ms, sizeof(**magicp) * mentrycount);
+	slen = sizeof(**magicp) * mentrycount;
+	if ((*magicp = CAST(struct magic *, malloc(slen))) == NULL) {
+		file_oomem(ms, slen);
 		errs++;
 		goto out;
 	}
@@ -1061,7 +1071,8 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 		if (me->cont_count == me->max_count) {
 			struct magic *nm;
 			size_t cnt = me->max_count + ALLOC_CHUNK;
-			if ((nm = realloc(me->mp, sizeof(*nm) * cnt)) == NULL) {
+			if ((nm = CAST(struct magic *, realloc(me->mp,
+			    sizeof(*nm) * cnt))) == NULL) {
 				file_oomem(ms, sizeof(*nm) * cnt);
 				return -1;
 			}
@@ -1076,7 +1087,8 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 			struct magic_entry *mp;
 
 			maxmagic += ALLOC_INCR;
-			if ((mp = realloc(*mentryp, sizeof(*mp) * maxmagic)) ==
+			if ((mp = CAST(struct magic_entry *,
+			    realloc(*mentryp, sizeof(*mp) * maxmagic))) ==
 			    NULL) {
 				file_oomem(ms, sizeof(*mp) * maxmagic);
 				return -1;
@@ -1087,8 +1099,9 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 		}
 		me = &(*mentryp)[*nmentryp];
 		if (me->mp == NULL) {
-			if ((m = malloc(sizeof(*m) * ALLOC_CHUNK)) == NULL) {
-				file_oomem(ms, sizeof(*m) * ALLOC_CHUNK);
+			size_t len = sizeof(*m) * ALLOC_CHUNK;
+			if ((m = CAST(struct magic *, malloc(len))) == NULL) {
+				file_oomem(ms, len);
 				return -1;
 			}
 			me->mp = m;
@@ -2025,7 +2038,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 	}
 #define RET	2
 #else
-	if ((mm = malloc((size_t)st.st_size)) == NULL) {
+	if ((mm = CAST(void *, malloc((size_t)st.st_size))) == NULL) {
 		file_oomem(ms, (size_t)st.st_size);
 		goto error1;
 	}
@@ -2035,7 +2048,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 	}
 #define RET	1
 #endif
-	*magicp = mm;
+	*magicp = CAST(struct magic *, mm);
 	(void)close(fd);
 	fd = -1;
 	ptr = (uint32_t *)(void *)*magicp;
@@ -2203,7 +2216,7 @@ swap4(uint32_t sv)
 private uint64_t
 swap8(uint64_t sv)
 {
-	uint32_t rv;
+	uint64_t rv;
 	uint8_t *s = (uint8_t *)(void *)&sv; 
 	uint8_t *d = (uint8_t *)(void *)&rv; 
 #if 0

+ 6 - 4
src/ascmagic.c

@@ -49,7 +49,7 @@
 #include "names.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.63 2008/05/09 14:20:28 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.64 2008/07/16 18:00:57 christos Exp $")
 #endif	/* lint */
 
 #define MAXLINELEN 300	/* longest sane line length */
@@ -103,9 +103,11 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
 	while (nbytes > 1 && buf[nbytes - 1] == '\0')
 		nbytes--;
 
-	if ((nbuf = calloc(1, (nbytes + 1) * sizeof(nbuf[0]))) == NULL)
+	if ((nbuf = CAST(unsigned char *, calloc((size_t)1,
+	    (nbytes + 1) * sizeof(nbuf[0])))) == NULL)
 		goto done;
-	if ((ubuf = calloc(1, (nbytes + 1) * sizeof(ubuf[0]))) == NULL)
+	if ((ubuf = CAST(unichar *, calloc((size_t)1,
+	    (nbytes + 1) * sizeof(ubuf[0])))) == NULL)
 		goto done;
 
 	/*
@@ -171,7 +173,7 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
 	   re-converting improved, or at least realloced after
 	   re-converting conversion. */
 	mlen = ulen * 6;
-	if ((utf8_buf = malloc(mlen)) == NULL) {
+	if ((utf8_buf = CAST(unsigned char *, malloc(mlen))) == NULL) {
 		file_oomem(ms, mlen);
 		goto done;
 	}

+ 2 - 2
src/compress.c

@@ -56,7 +56,7 @@
 
 
 #ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.56 2008/02/07 00:58:52 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.57 2008/07/16 18:00:57 christos Exp $")
 #endif
 
 private const struct {
@@ -330,7 +330,7 @@ uncompressgzipped(struct magic_set *ms, const unsigned char *old,
 
 	if (data_start >= n)
 		return 0;
-	if ((*newch = (unsigned char *)malloc(HOWMANY + 1)) == NULL) {
+	if ((*newch = CAST(unsigned char *, malloc(HOWMANY + 1))) == NULL) {
 		return 0;
 	}
 	

+ 3 - 3
src/elfclass.h

@@ -35,7 +35,7 @@
 	switch (type) {
 #ifdef ELFCORE
 	case ET_CORE:
-		if (dophn_core(ms, class, swap, fd,
+		if (dophn_core(ms, clazz, swap, fd,
 		    (off_t)elf_getu(swap, elfhdr.e_phoff),
 		    elf_getu16(swap, elfhdr.e_phnum), 
 		    (size_t)elf_getu16(swap, elfhdr.e_phentsize),
@@ -45,7 +45,7 @@
 #endif
 	case ET_EXEC:
 	case ET_DYN:
-		if (dophn_exec(ms, class, swap, fd,
+		if (dophn_exec(ms, clazz, swap, fd,
 		    (off_t)elf_getu(swap, elfhdr.e_phoff),
 		    elf_getu16(swap, elfhdr.e_phnum), 
 		    (size_t)elf_getu16(swap, elfhdr.e_phentsize),
@@ -54,7 +54,7 @@
 			return -1;
 		/*FALLTHROUGH*/
 	case ET_REL:
-		if (doshn(ms, class, swap, fd,
+		if (doshn(ms, clazz, swap, fd,
 		    (off_t)elf_getu(swap, elfhdr.e_shoff),
 		    elf_getu16(swap, elfhdr.e_shnum),
 		    (size_t)elf_getu16(swap, elfhdr.e_shentsize),

+ 5 - 1
src/file.c

@@ -60,7 +60,11 @@
 #include <wchar.h>
 #endif
 
+#ifdef HAVE_GETOPT_H
 #include <getopt.h>
+#else
+#include "mygetopt.h"
+#endif
 #ifndef HAVE_GETOPT_LONG
 int getopt_long(int argc, char * const *argv, const char *optstring, const struct option *longopts, int *longindex);
 #endif
@@ -70,7 +74,7 @@ int getopt_long(int argc, char * const *argv, const char *optstring, const struc
 #include "patchlevel.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: file.c,v 1.120 2008/05/18 23:21:17 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.121 2008/07/03 15:48:18 christos Exp $")
 #endif	/* lint */
 
 

+ 41 - 23
src/file.h

@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.106 2008/07/02 15:22:47 christos Exp $
+ * @(#)$File: file.h,v 1.108 2008/07/16 18:00:57 christos Exp $
  */
 
 #ifndef __file_h__
@@ -80,6 +80,12 @@
 #endif
 #endif
 
+#ifndef __GNUC__
+#ifndef __attribute__
+#define __attribute__(a)
+#endif
+#endif
+
 #ifndef MIN
 #define	MIN(a,b)	(((a) < (b)) ? (a) : (b))
 #endif
@@ -104,6 +110,20 @@
 #define FILE_CHECK	1
 #define FILE_COMPILE	2
 
+union VALUETYPE {
+	uint8_t b;
+	uint16_t h;
+	uint32_t l;
+	uint64_t q;
+	uint8_t hs[2];	/* 2 bytes of a fixed-endian "short" */
+	uint8_t hl[4];	/* 4 bytes of a fixed-endian "long" */
+	uint8_t hq[8];	/* 8 bytes of a fixed-endian "quad" */
+	char s[MAXstring];	/* the search string or regex pattern */
+	unsigned char us[MAXstring];
+	float f;
+	double d;
+}; 
+
 struct magic {
 	/* Word 1 */
 	uint16_t cont_level;	/* level of ">" */
@@ -236,21 +256,8 @@ struct magic {
 #define num_mask _u._mask
 #define str_range _u._s._count
 #define str_flags _u._s._flags
-
 	/* Words 9-16 */
-	union VALUETYPE {
-		uint8_t b;
-		uint16_t h;
-		uint32_t l;
-		uint64_t q;
-		uint8_t hs[2];	/* 2 bytes of a fixed-endian "short" */
-		uint8_t hl[4];	/* 4 bytes of a fixed-endian "long" */
-		uint8_t hq[8];	/* 8 bytes of a fixed-endian "quad" */
-		char s[MAXstring];	/* the search string or regex pattern */
-		unsigned char us[MAXstring];
-		float f;
-		double d;
-	} value;		/* either number or string */
+	union VALUETYPE value;		/* either number or string */
 	/* Words 17..31 */
 	char desc[MAXDESC];	/* description */
 	/* Words 32..47 */
@@ -282,18 +289,25 @@ struct mlist {
 	struct mlist *next, *prev;
 };
 
+#ifdef __cplusplus
+#define CAST(T, b)	static_cast<T>(b)
+#else
+#define CAST(T, b)	(b)
+#endif
+
+struct level_info {
+	int32_t off;
+	int got_match;
+#ifdef ENABLE_CONDITIONALS
+	int last_match;
+	int last_cond;	/* used for error checking by parse() */
+#endif
+} *li;
 struct magic_set {
 	struct mlist *mlist;
 	struct cont {
 		size_t len;
-		struct level_info {
-			int32_t off;
-			int got_match;
-#ifdef ENABLE_CONDITIONALS
-			int last_match;
-			int last_cond;	/* used for error checking by parse() */
-#endif
-		} *li;
+		struct level_info *li;
 	} c;
 	struct out {
 		char *buf;		/* Accumulation buffer */
@@ -391,6 +405,7 @@ int asprintf(char **ptr, const char *format_string, ...);
 #define O_BINARY	0
 #endif
 
+#ifndef __cplusplus
 #ifdef __GNUC__
 static const char *rcsid(const char *) __attribute__((__used__));
 #endif
@@ -398,5 +413,8 @@ static const char *rcsid(const char *) __attribute__((__used__));
 static const char *rcsid(const char *p) { \
 	return rcsid(p = id); \
 }
+#else
+#define FILE_RCSID(id)
+#endif
 
 #endif /* __file_h__ */

+ 84 - 46
src/fsmagic.c

@@ -57,23 +57,30 @@
 #undef HAVE_MAJOR
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.51 2008/05/09 14:20:28 christos Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.52 2008/07/25 23:59:01 rrt Exp $")
 #endif	/* lint */
 
 private int
 bad_link(struct magic_set *ms, int err, char *buf)
 {
 	const char *errfmt;
-	if (err == ELOOP)
-		errfmt = "symbolic link in a loop";
-	else
-		errfmt = "broken symbolic link to `%s'";
-	if (ms->flags & MAGIC_ERROR) {
-		file_error(ms, err, errfmt, buf);
-		return -1;
-	} 
-	if (file_printf(ms, errfmt, buf) == -1)
+	int mime = ms->flags & MAGIC_MIME;
+	if ((mime & MAGIC_MIME_TYPE) &&
+	    file_printf(ms, "application/x-symlink")
+	    == -1)
 		return -1;
+	else if (!mime) {
+		if (err == ELOOP)
+			errfmt = "symbolic link in a loop";
+		else
+			errfmt = "broken symbolic link to `%s'";
+		if (ms->flags & MAGIC_ERROR) {
+			file_error(ms, err, errfmt, buf);
+			return -1;
+		} 
+		if (file_printf(ms, errfmt, buf) == -1)
+			return -1;
+	}
 	return 1;
 }
 
@@ -113,16 +120,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 		return 1;
 	}
 
-	if (mime) {
-		if ((sb->st_mode & S_IFMT) != S_IFREG) {
-			if ((mime & MAGIC_MIME_TYPE) &&
-			    file_printf(ms, "application/x-not-regular-file")
-			    == -1)
-				    return -1;
-			return 1;
-		}
-	}
-	else {
+	if (!mime) {
 #ifdef S_ISUID
 		if (sb->st_mode & S_ISUID) 
 			if (file_printf(ms, "setuid ") == -1)
@@ -142,7 +140,11 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 	
 	switch (sb->st_mode & S_IFMT) {
 	case S_IFDIR:
-		if (file_printf(ms, "directory") == -1)
+		if ((mime & MAGIC_MIME_TYPE) &&
+		    file_printf(ms, "application/x-directory")
+		    == -1)
+			return -1;
+		if (!mime && file_printf(ms, "directory") == -1)
 			return -1;
 		return 1;
 #ifdef S_IFCHR
@@ -154,21 +156,27 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 		 */
 		if ((ms->flags & MAGIC_DEVICES) != 0)
 			break;
+		if ((mime & MAGIC_MIME_TYPE) &&
+		    file_printf(ms, "application/x-character-device")
+		    == -1)
+			return -1;
+		if (!mime) {
 #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),
-		    dv_subunit(sb->st_rdev)) == -1)
-			return -1;
+			if (file_printf(ms, "character special (%d/%d/%d)",
+					major(sb->st_rdev), dv_unit(sb->st_rdev),
+					dv_subunit(sb->st_rdev)) == -1)
+				return -1;
 # else
-		if (file_printf(ms, "character special (%ld/%ld)",
-		    (long) major(sb->st_rdev), (long) minor(sb->st_rdev)) == -1)
-			return -1;
+			if (file_printf(ms, "character special (%ld/%ld)",
+					(long) major(sb->st_rdev), (long) minor(sb->st_rdev)) == -1)
+				return -1;
 # endif
 #else
-		if (file_printf(ms, "character special") == -1)
-			return -1;
+			if (file_printf(ms, "character special") == -1)
+				return -1;
 #endif
+		}
 		return 1;
 #endif
 #ifdef S_IFBLK
@@ -180,21 +188,27 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 		 */
 		if ((ms->flags & MAGIC_DEVICES) != 0)
 			break;
+		if ((mime & MAGIC_MIME_TYPE) &&
+		    file_printf(ms, "application/x-block-device")
+		    == -1)
+			return -1;
+		if (!mime) {
 #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),
-		    dv_subunit(sb->st_rdev)) == -1)
-			return -1;
+			if (file_printf(ms, "block special (%d/%d/%d)",
+					major(sb->st_rdev), dv_unit(sb->st_rdev),
+					dv_subunit(sb->st_rdev)) == -1)
+				return -1;
 # else
-		if (file_printf(ms, "block special (%ld/%ld)",
-		    (long)major(sb->st_rdev), (long)minor(sb->st_rdev)) == -1)
-			return -1;
+			if (file_printf(ms, "block special (%ld/%ld)",
+					(long)major(sb->st_rdev), (long)minor(sb->st_rdev)) == -1)
+				return -1;
 # endif
 #else
-		if (file_printf(ms, "block special") == -1)
-			return -1;
+			if (file_printf(ms, "block special") == -1)
+				return -1;
 #endif
+		}
 		return 1;
 #endif
 	/* TODO add code to handle V7 MUX and Blit MUX files */
@@ -202,13 +216,21 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 	case S_IFIFO:
 		if((ms->flags & MAGIC_DEVICES) != 0)
 			break;
-		if (file_printf(ms, "fifo (named pipe)") == -1)
+		if ((mime & MAGIC_MIME_TYPE) &&
+		    file_printf(ms, "application/x-fifo")
+		    == -1)
+			return -1;
+		if (!mime && file_printf(ms, "fifo (named pipe)") == -1)
 			return -1;
 		return 1;
 #endif
 #ifdef	S_IFDOOR
 	case S_IFDOOR:
-		if (file_printf(ms, "door") == -1)
+		if ((mime & MAGIC_MIME_TYPE) &&
+		    file_printf(ms, "application/x-door")
+		    == -1)
+			return -1;
+		if (!mime && file_printf(ms, "door") == -1)
 			return -1;
 		return 1;
 #endif
@@ -220,7 +242,11 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 				fn);
 			    return -1;
 			}
-			if (file_printf(ms,
+			if ((mime & MAGIC_MIME_TYPE) &&
+			    file_printf(ms, "application/x-symlink")
+			    == -1)
+				return -1;
+			if (!mime && file_printf(ms,
 			    "unreadable symlink `%s' (%s)", fn,
 			    strerror(errno)) == -1)
 				return -1;
@@ -245,7 +271,11 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 						    "path too long: `%s'", buf);
 						return -1;
 					}
-					if (file_printf(ms,
+					if ((mime & MAGIC_MIME_TYPE) &&
+					    file_printf(ms, "application/x-path-too-long")
+					    == -1)
+						return -1;
+					if (!mime && file_printf(ms,
 					    "path too long: `%s'", fn) == -1)
 						return -1;
 					return 1;
@@ -267,16 +297,24 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 			ms->flags |= MAGIC_SYMLINK;
 			return p != NULL ? 1 : -1;
 		} else { /* just print what it points to */
-			if (file_printf(ms, "symbolic link to `%s'",
+			if ((mime & MAGIC_MIME_TYPE) &&
+			    file_printf(ms, "application/x-symlink")
+			    == -1)
+				return -1;
+			if (!mime && file_printf(ms, "symbolic link to `%s'",
 			    buf) == -1)
 				return -1;
 		}
-	return 1;
+		return 1;
 #endif
 #ifdef	S_IFSOCK
 #ifndef __COHERENT__
 	case S_IFSOCK:
-		if (file_printf(ms, "socket") == -1)
+		if ((mime & MAGIC_MIME_TYPE) &&
+		    file_printf(ms, "application/x-socket")
+		    == -1)
+			return -1;
+		if (!mime && file_printf(ms, "socket") == -1)
 			return -1;
 		return 1;
 #endif

+ 18 - 9
src/funcs.c

@@ -36,11 +36,18 @@
 #if defined(HAVE_WCTYPE_H)
 #include <wctype.h>
 #endif
+#if defined(HAVE_LIMITS_H)
+#include <limits.h>
+#endif
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.41 2008/05/16 14:25:01 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.44 2008/07/16 18:00:57 christos Exp $")
 #endif	/* lint */
 
+#ifndef SIZE_MAX
+#define SIZE_MAX	((size_t)~0)
+#endif
+
 /*
  * Like printf, only we append to a buffer.
  */
@@ -152,6 +159,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname, const void *buf,
 {
 	int m;
 	int mime = ms->flags & MAGIC_MIME;
+	const unsigned char *ubuf = CAST(const unsigned char *, buf);
 
 	if (nb == 0) {
 		if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
@@ -182,16 +190,16 @@ file_buffer(struct magic_set *ms, int fd, const char *inname, const void *buf,
 
 	/* try compression stuff */
 	if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) != 0 ||
-	    (m = file_zmagic(ms, fd, inname, buf, nb)) == 0) {
+	    (m = file_zmagic(ms, fd, inname, ubuf, nb)) == 0) {
 	    /* Check if we have a tar file */
 	    if ((ms->flags & MAGIC_NO_CHECK_TAR) != 0 ||
-		(m = file_is_tar(ms, buf, nb)) == 0) {
+		(m = file_is_tar(ms, ubuf, nb)) == 0) {
 		/* try tests in /etc/magic (or surrogate magic file) */
 		if ((ms->flags & MAGIC_NO_CHECK_SOFT) != 0 ||
-		    (m = file_softmagic(ms, buf, nb, BINTEST)) == 0) {
+		    (m = file_softmagic(ms, ubuf, nb, BINTEST)) == 0) {
 		    /* try known keywords, check whether it is ASCII */
 		    if ((ms->flags & MAGIC_NO_CHECK_ASCII) != 0 ||
-			(m = file_ascmagic(ms, buf, nb)) == 0) {
+			(m = file_ascmagic(ms, ubuf, nb)) == 0) {
 			/* abandon hope, all ye who remain here */
 			if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
 			    file_printf(ms, mime ? "application/octet-stream" :
@@ -213,7 +221,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname, const void *buf,
 		 * information from the ELF headers that cannot easily
 		 * be extracted with rules in the magic file.
 		 */
-		(void)file_tryelf(ms, fd, buf, nb);
+		(void)file_tryelf(ms, fd, ubuf, nb);
 	}
 #endif
 	return m;
@@ -260,7 +268,7 @@ file_getbuffer(struct magic_set *ms)
 		return NULL;
 	}
 	psize = len * 4 + 1;
-	if ((pbuf = realloc(ms->o.pbuf, psize)) == NULL) {
+	if ((pbuf = CAST(char *, realloc(ms->o.pbuf, psize))) == NULL) {
 		file_oomem(ms, psize);
 		return NULL;
 	}
@@ -323,8 +331,9 @@ file_check_mem(struct magic_set *ms, unsigned int level)
 
 	if (level >= ms->c.len) {
 		len = (ms->c.len += 20) * sizeof(*ms->c.li);
-		ms->c.li = (ms->c.li == NULL) ? malloc(len) :
-		    realloc(ms->c.li, len);
+		ms->c.li = CAST(struct level_info *, (ms->c.li == NULL) ?
+		    malloc(len) :
+		    realloc(ms->c.li, len));
 		if (ms->c.li == NULL) {
 			file_oomem(ms, len);
 			return -1;

+ 17 - 3
src/getopt_long.c

@@ -29,16 +29,30 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include <assert.h>
+#ifdef HAVE_ERR_H
 #include <err.h>
+#else
+#include <stdio.h>
+#define warnx printf
+#endif
 #include <errno.h>
+#ifdef HAVE_GETOPT_H
 #include <getopt.h>
+#else
+#include "mygetopt.h"
+#endif
 #include <stdlib.h>
 #include <string.h>
 
 #define REPLACE_GETOPT
 
+#ifndef _DIAGASSERT
 #define _DIAGASSERT assert
+#endif
 
 #ifdef REPLACE_GETOPT
 #ifdef __weak_alias
@@ -73,9 +87,9 @@ __weak_alias(getopt_long,_getopt_long)
 
 #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 int getopt_internal(int, char **, const char *);
+static int gcd(int, int);
+static void permute_args(int, int, int, char **);
 
 static const char *place = EMSG; /* option letter processing */
 

+ 26 - 16
src/magic.c

@@ -1,7 +1,7 @@
 /*
  * Copyright (c) Christos Zoulas 2003.
  * All Rights Reserved.
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -11,7 +11,7 @@
  * 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 AUTHOR 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
@@ -38,7 +38,9 @@
 #ifdef QUICK
 #include <sys/mman.h>
 #endif
+#ifdef HAVE_LIMITS_H
 #include <limits.h>	/* for PIPE_BUF */
+#endif
 
 #if defined(HAVE_UTIMES)
 # include <sys/time.h>
@@ -63,10 +65,10 @@
 #include "patchlevel.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: magic.c,v 1.51 2008/05/16 14:25:01 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.54 2008/07/25 23:30:32 rrt Exp $")
 #endif	/* lint */
 
-#ifndef PIPE_BUF 
+#ifndef PIPE_BUF
 /* Get the PIPE_BUF from pathconf */
 #ifdef _PC_PIPE_BUF
 #define PIPE_BUF pathconf(".", _PC_PIPE_BUF)
@@ -84,7 +86,7 @@ protected int file_os2_apptype(struct magic_set *ms, const char *fn,
 private void free_mlist(struct mlist *);
 private void close_and_restore(const struct magic_set *, const char *, int,
     const struct stat *);
-private int info_from_stat(struct magic_set *, mode_t);
+private int unreadable_info(struct magic_set *, mode_t, const char *);
 #ifndef COMPILE_ONLY
 private const char *file_or_fd(struct magic_set *, const char *, int);
 #endif
@@ -97,8 +99,10 @@ public struct magic_set *
 magic_open(int flags)
 {
 	struct magic_set *ms;
+	size_t len;
 
-	if ((ms = calloc((size_t)1, sizeof(struct magic_set))) == NULL)
+	if ((ms = CAST(magic_set *, calloc((size_t)1,
+	    sizeof(struct magic_set)))) == NULL)
 		return NULL;
 
 	if (magic_setflags(ms, flags) == -1) {
@@ -107,11 +111,11 @@ magic_open(int flags)
 	}
 
 	ms->o.buf = ms->o.pbuf = NULL;
+	len = (ms->c.len = 10) * sizeof(*ms->c.li);
 
-	ms->c.li = malloc((ms->c.len = 10) * sizeof(*ms->c.li));
-	if (ms->c.li == NULL)
+	if ((ms->c.li = CAST(struct level_info *, malloc(len))) == NULL)
 		goto free;
-	
+
 	ms->haderr = 0;
 	ms->error = -1;
 	ms->mlist = NULL;
@@ -142,13 +146,13 @@ free_mlist(struct mlist *mlist)
 }
 
 private int
-info_from_stat(struct magic_set *ms, mode_t md)
+unreadable_info(struct magic_set *ms, mode_t md, const char *file)
 {
 	/* We cannot open it, but we were able to stat it. */
-	if (md & 0222)
+	if (access(file, W_OK) == 0)
 		if (file_printf(ms, "writable, ") == -1)
 			return -1;
-	if (md & 0111)
+	if (access(file, X_OK) == 0)
 		if (file_printf(ms, "executable, ") == -1)
 			return -1;
 	if (S_ISREG(md))
@@ -267,7 +271,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
 	 * some overlapping space for matches near EOF
 	 */
 #define SLOP (1 + sizeof(union VALUETYPE))
-	if ((buf = malloc(HOWMANY + SLOP)) == NULL)
+	if ((buf = CAST(unsigned char *, malloc(HOWMANY + SLOP))) == NULL)
 		return NULL;
 
 	if (file_reset(ms) == -1)
@@ -302,7 +306,13 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
 			(void)strcat(strcpy(tmp, inname), ".exe");
 			if ((fd = open(tmp, flags)) < 0) {
 #endif
-				if (info_from_stat(ms, sb.st_mode) == -1)
+				if (unreadable_info(ms, sb.st_mode,
+#ifdef __CYGWIN
+						    tmp
+#else
+						    inname
+#endif
+						    ) == -1)
 					goto done;
 				rv = 0;
 				goto done;
@@ -332,7 +342,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
 
 		if (nbytes == 0) {
 			/* We can not read it, but we were able to stat it. */
-			if (info_from_stat(ms, sb.st_mode) == -1)
+			if (unreadable_info(ms, sb.st_mode, inname) == -1)
 				goto done;
 			rv = 0;
 			goto done;
@@ -363,7 +373,7 @@ magic_buffer(struct magic_set *ms, const void *buf, size_t nb)
 		return NULL;
 	/*
 	 * The main work is done here!
-	 * We have the file name and/or the data buffer to be identified. 
+	 * We have the file name and/or the data buffer to be identified.
 	 */
 	if (file_buffer(ms, -1, NULL, buf, nb) == -1) {
 		return NULL;

+ 68 - 0
src/mygetopt.h

@@ -0,0 +1,68 @@
+/*	$NetBSD: getopt.h,v 1.8 2007/11/06 19:21:18 christos 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * 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.
+ */
+
+#ifndef _GETOPT_H_
+#define _GETOPT_H_
+
+#include <unistd.h>
+
+/*
+ * Gnu like getopt_long() and BSD4.4 getsubopt()/optreset extensions
+ */
+#define no_argument        0
+#define required_argument  1
+#define optional_argument  2
+
+struct option {
+	/* name of long option */
+	const char *name;
+	/*
+	 * one of no_argument, required_argument, and optional_argument:
+	 * whether option takes an argument
+	 */
+	int has_arg;
+	/* if not NULL, set *flag to val when option found */
+	int *flag;
+	/* if flag not NULL, value to set *flag to; else return value */
+	int val;
+};
+
+int getopt_long(int, char * const *, const char *,
+    const struct option *, int *);
+ 
+#endif /* !_GETOPT_H_ */

+ 5 - 2
src/patchlevel.h

@@ -1,11 +1,14 @@
 #define	FILE_VERSION_MAJOR	4
-#define	patchlevel		25
+#define	patchlevel		26
 
 /*
  * Patchlevel file for Ian Darwin's MAGIC command.
- * $File: patchlevel.h,v 1.69 2008/07/02 15:27:05 christos Exp $
+ * $File: patchlevel.h,v 1.70 2008/08/30 10:01:01 christos Exp $
  *
  * $Log: patchlevel.h,v $
+ * Revision 1.70  2008/08/30 10:01:01  christos
+ * file 4.26
+ *
  * Revision 1.69  2008/07/02 15:27:05  christos
  * welcome to 4.25
  *

+ 38 - 37
src/readelf.c

@@ -38,7 +38,7 @@
 #include "magic.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.75 2008/06/05 12:59:15 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.76 2008/07/16 18:00:57 christos Exp $")
 #endif
 
 #ifdef	ELFCORE
@@ -49,7 +49,7 @@ private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,
     off_t, int *, int);
 private int doshn(struct magic_set *, int, int, int, off_t, int, size_t, int *,
     int);
-private size_t donote(struct magic_set *, unsigned char *, size_t, size_t, int,
+private size_t donote(struct magic_set *, void *, size_t, size_t, int,
     int, size_t, int *);
 
 #define	ELF_ALIGN(a)	((((a) + align - 1) / align) * align)
@@ -135,72 +135,72 @@ getu64(int swap, uint64_t value)
 # define elf_getu64(swap, value) getu64(swap, value)
 #endif
 
-#define xsh_addr	(class == ELFCLASS32			\
+#define xsh_addr	(clazz == ELFCLASS32			\
 			 ? (void *) &sh32			\
 			 : (void *) &sh64)
-#define xsh_sizeof	(class == ELFCLASS32			\
+#define xsh_sizeof	(clazz == ELFCLASS32			\
 			 ? sizeof sh32				\
 			 : sizeof sh64)
-#define xsh_size	(class == ELFCLASS32			\
+#define xsh_size	(clazz == ELFCLASS32			\
 			 ? elf_getu32(swap, sh32.sh_size)	\
 			 : elf_getu64(swap, sh64.sh_size))
-#define xsh_offset	(class == ELFCLASS32			\
+#define xsh_offset	(clazz == ELFCLASS32			\
 			 ? elf_getu32(swap, sh32.sh_offset)	\
 			 : elf_getu64(swap, sh64.sh_offset))
-#define xsh_type	(class == ELFCLASS32			\
+#define xsh_type	(clazz == ELFCLASS32			\
 			 ? elf_getu32(swap, sh32.sh_type)	\
 			 : elf_getu32(swap, sh64.sh_type))
-#define xph_addr	(class == ELFCLASS32			\
+#define xph_addr	(clazz == ELFCLASS32			\
 			 ? (void *) &ph32			\
 			 : (void *) &ph64)
-#define xph_sizeof	(class == ELFCLASS32			\
+#define xph_sizeof	(clazz == ELFCLASS32			\
 			 ? sizeof ph32				\
 			 : sizeof ph64)
-#define xph_type	(class == ELFCLASS32			\
+#define xph_type	(clazz == ELFCLASS32			\
 			 ? elf_getu32(swap, ph32.p_type)	\
 			 : elf_getu32(swap, ph64.p_type))
-#define xph_offset	(off_t)(class == ELFCLASS32		\
+#define xph_offset	(off_t)(clazz == ELFCLASS32		\
 			 ? elf_getu32(swap, ph32.p_offset)	\
 			 : elf_getu64(swap, ph64.p_offset))
-#define xph_align	(size_t)((class == ELFCLASS32		\
+#define xph_align	(size_t)((clazz == ELFCLASS32		\
 			 ? (off_t) (ph32.p_align ? 		\
 			    elf_getu32(swap, ph32.p_align) : 4) \
 			 : (off_t) (ph64.p_align ?		\
 			    elf_getu64(swap, ph64.p_align) : 4)))
-#define xph_filesz	(size_t)((class == ELFCLASS32		\
+#define xph_filesz	(size_t)((clazz == ELFCLASS32		\
 			 ? elf_getu32(swap, ph32.p_filesz)	\
 			 : elf_getu64(swap, ph64.p_filesz)))
-#define xnh_addr	(class == ELFCLASS32			\
+#define xnh_addr	(clazz == ELFCLASS32			\
 			 ? (void *) &nh32			\
 			 : (void *) &nh64)
-#define xph_memsz	(size_t)((class == ELFCLASS32		\
+#define xph_memsz	(size_t)((clazz == ELFCLASS32		\
 			 ? elf_getu32(swap, ph32.p_memsz)	\
 			 : elf_getu64(swap, ph64.p_memsz)))
-#define xnh_sizeof	(class == ELFCLASS32			\
+#define xnh_sizeof	(clazz == ELFCLASS32			\
 			 ? sizeof nh32				\
 			 : sizeof nh64)
-#define xnh_type	(class == ELFCLASS32			\
+#define xnh_type	(clazz == ELFCLASS32			\
 			 ? elf_getu32(swap, nh32.n_type)	\
 			 : elf_getu32(swap, nh64.n_type))
-#define xnh_namesz	(class == ELFCLASS32			\
+#define xnh_namesz	(clazz == ELFCLASS32			\
 			 ? elf_getu32(swap, nh32.n_namesz)	\
 			 : elf_getu32(swap, nh64.n_namesz))
-#define xnh_descsz	(class == ELFCLASS32			\
+#define xnh_descsz	(clazz == ELFCLASS32			\
 			 ? elf_getu32(swap, nh32.n_descsz)	\
 			 : elf_getu32(swap, nh64.n_descsz))
-#define prpsoffsets(i)	(class == ELFCLASS32			\
+#define prpsoffsets(i)	(clazz == ELFCLASS32			\
 			 ? prpsoffsets32[i]			\
 			 : prpsoffsets64[i])
-#define xcap_addr	(class == ELFCLASS32			\
+#define xcap_addr	(clazz == ELFCLASS32			\
 			 ? (void *) &cap32			\
 			 : (void *) &cap64)
-#define xcap_sizeof	(class == ELFCLASS32			\
+#define xcap_sizeof	(clazz == ELFCLASS32			\
 			 ? sizeof cap32				\
 			 : sizeof cap64)
-#define xcap_tag	(class == ELFCLASS32			\
+#define xcap_tag	(clazz == ELFCLASS32			\
 			 ? elf_getu32(swap, cap32.c_tag)	\
 			 : elf_getu64(swap, cap64.c_tag))
-#define xcap_val	(class == ELFCLASS32			\
+#define xcap_val	(clazz == ELFCLASS32			\
 			 ? elf_getu32(swap, cap32.c_un.c_val)	\
 			 : elf_getu64(swap, cap64.c_un.c_val))
 
@@ -242,7 +242,7 @@ static const size_t	prpsoffsets64[] = {
 #define	NOFFSETS32	(sizeof prpsoffsets32 / sizeof prpsoffsets32[0])
 #define NOFFSETS64	(sizeof prpsoffsets64 / sizeof prpsoffsets64[0])
 
-#define NOFFSETS	(class == ELFCLASS32 ? NOFFSETS32 : NOFFSETS64)
+#define NOFFSETS	(clazz == ELFCLASS32 ? NOFFSETS32 : NOFFSETS64)
 
 /*
  * Look through the program headers of an executable image, searching
@@ -288,7 +288,7 @@ private const char os_style_names[][8] = {
 #define FLAGS_DID_CORE_STYLE	4
 
 private int
-dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
+dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
     int num, size_t size, off_t fsize, int *flags)
 {
 	Elf32_Phdr ph32;
@@ -353,7 +353,7 @@ dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
 			if (offset >= (size_t)bufsize)
 				break;
 			offset = donote(ms, nbuf, offset, (size_t)bufsize,
-			    class, swap, 4, flags);
+			    clazz, swap, 4, flags);
 			if (offset == 0)
 				break;
 
@@ -364,8 +364,8 @@ dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
 #endif
 
 private size_t
-donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
-    int class, int swap, size_t align, int *flags)
+donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
+    int clazz, int swap, size_t align, int *flags)
 {
 	Elf32_Nhdr nh32;
 	Elf64_Nhdr nh64;
@@ -374,6 +374,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
 	int os_style = -1;
 #endif
 	uint32_t namesz, descsz;
+	unsigned char *nbuf = CAST(unsigned char *, vbuf);
 
 	(void)memcpy(xnh_addr, &nbuf[offset], xnh_sizeof);
 	offset += xnh_sizeof;
@@ -814,7 +815,7 @@ static const cap_desc_t cap_desc_386[] = {
 };
 
 private int
-doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
+doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
     size_t size, int *flags, int mach)
 {
 	Elf32_Shdr sh32;
@@ -877,7 +878,7 @@ doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
 				if (noff >= (size_t)xsh_size)
 					break;
 				noff = donote(ms, nbuf, (size_t)noff,
-				    (size_t)xsh_size, class, swap, 4,
+				    (size_t)xsh_size, clazz, swap, 4,
 				    flags);
 				if (noff == 0)
 					break;
@@ -1007,7 +1008,7 @@ doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
  * otherwise it's statically linked.
  */
 private int
-dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
+dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
     int num, size_t size, off_t fsize, int *flags, int sh_num)
 {
 	Elf32_Phdr ph32;
@@ -1099,7 +1100,7 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
 				if (offset >= (size_t)bufsize)
 					break;
 				offset = donote(ms, nbuf, offset,
-				    (size_t)bufsize, class, swap, align,
+				    (size_t)bufsize, clazz, swap, align,
 				    flags);
 				if (offset == 0)
 					break;
@@ -1128,7 +1129,7 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
 		int32_t l;
 		char c[sizeof (int32_t)];
 	} u;
-	int class;
+	int clazz;
 	int swap;
 	struct stat st;
 	off_t fsize;
@@ -1163,9 +1164,9 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
 	}
 	fsize = st.st_size;
 
-	class = buf[EI_CLASS];
+	clazz = buf[EI_CLASS];
 
-	switch (class) {
+	switch (clazz) {
 	case ELFCLASS32:
 #undef elf_getu
 #define elf_getu(a, b)	elf_getu32(a, b)
@@ -1179,7 +1180,7 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
 #define elfhdr elf64hdr
 #include "elfclass.h"
 	default:
-	    if (file_printf(ms, ", unknown class %d", class) == -1)
+	    if (file_printf(ms, ", unknown class %d", clazz) == -1)
 		    return -1;
 	    break;
 	}

+ 9 - 5
src/softmagic.c

@@ -38,7 +38,7 @@
 
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.117 2008/03/01 22:21:49 rrt Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.120 2008/07/28 17:25:21 christos Exp $")
 #endif	/* lint */
 
 private int match(struct magic_set *, struct magic *, uint32_t,
@@ -660,13 +660,14 @@ mconvert(struct magic_set *ms, struct magic *m)
 	case FILE_STRING:
 	case FILE_BESTRING16:
 	case FILE_LESTRING16: {
-		size_t len;
-		
 		/* Null terminate and eat *trailing* return */
 		p->s[sizeof(p->s) - 1] = '\0';
+#if 0
+		/* Why? breaks magic numbers that end with \xa */
 		len = strlen(p->s);
 		if (len-- && p->s[len] == '\n')
 			p->s[len] = '\0';
+#endif
 		return 1;
 	}
 	case FILE_PSTRING: {
@@ -677,9 +678,12 @@ mconvert(struct magic_set *ms, struct magic *m)
 		while (len--)
 			*ptr1++ = *ptr2++;
 		*ptr1 = '\0';
+#if 0
+		/* Why? breaks magic numbers that end with \xa */
 		len = strlen(p->s);
 		if (len-- && p->s[len] == '\n')
 			p->s[len] = '\0';
+#endif
 		return 1;
 	}
 	case FILE_BESHORT:
@@ -906,8 +910,8 @@ mget(struct magic_set *ms, const unsigned char *s,
 	if (m->flag & INDIR) {
 		int off = m->in_offset;
 		if (m->in_op & FILE_OPINDIRECT) {
-			const union VALUETYPE *q =
-			    ((const void *)(s + offset + off));
+			const union VALUETYPE *q = CAST(const union VALUETYPE *,
+			    ((const void *)(s + offset + off)));
 			switch (m->in_type) {
 			case FILE_BYTE:
 				off = q->b;

+ 4 - 1
src/vasprintf.c

@@ -105,8 +105,9 @@ A buffer overflow can only occur if your sprintf() do strange things or when
 you use strange formats.
 
 */
-
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
 
 #include <assert.h>
 #include <stdio.h>
@@ -114,7 +115,9 @@ you use strange formats.
 #include <stdlib.h>
 #include <stdarg.h>
 #include <ctype.h>
+#ifdef HAVE_LIMITS_H
 #include <limits.h>
+#endif
 
 #define ALLOC_CHUNK 2048
 #define ALLOC_SECURITY_MARGIN 1024   /* big value because some platforms have very big 'G' exponent */

+ 1 - 0
tests/Makefile.in

@@ -116,6 +116,7 @@ SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
 STRIP = @STRIP@
 VERSION = @VERSION@
+WARNINGS = @WARNINGS@
 abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@