summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cvsignore1
-rw-r--r--acinclude.m4238
-rw-r--r--configure.ac (renamed from configure.in)0
-rw-r--r--doc/file.man25
-rw-r--r--magic/Magdir/mathcad2
-rw-r--r--magic/Magdir/troff5
-rw-r--r--src/.cvsignore1
-rw-r--r--src/Makefile.am11
-rw-r--r--src/ascmagic.c27
-rw-r--r--src/compress.c3
-rw-r--r--src/file.c88
-rw-r--r--src/file.h4
-rw-r--r--src/fsmagic.c6
-rw-r--r--src/funcs.c14
-rw-r--r--src/getopt_long.c482
-rw-r--r--src/magic.c3
-rw-r--r--src/magic.h5
-rw-r--r--src/names.h14
-rw-r--r--src/readelf.h2
-rw-r--r--src/softmagic.c3
-rw-r--r--src/tar.h64
-rw-r--r--src/test.c18
22 files changed, 533 insertions, 483 deletions
diff --git a/.cvsignore b/.cvsignore
index 98b8bcd8..341d88bb 100644
--- a/.cvsignore
+++ b/.cvsignore
@@ -5,6 +5,7 @@ aclocal.m4
config.guess
config.h.in
config.sub
+configure
depcomp
install-sh
ltmain.sh
diff --git a/acinclude.m4 b/acinclude.m4
index 3a76bad1..31677b18 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -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])
-
-
diff --git a/configure.in b/configure.ac
index 7d644081..7d644081 100644
--- a/configure.in
+++ b/configure.ac
diff --git a/doc/file.man b/doc/file.man
index 64e69c9c..ddac0e22 100644
--- a/doc/file.man
+++ b/doc/file.man
@@ -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
diff --git a/magic/Magdir/mathcad b/magic/Magdir/mathcad
index 9acb3908..41801968 100644
--- a/magic/Magdir/mathcad
+++ b/magic/Magdir/mathcad
@@ -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
diff --git a/magic/Magdir/troff b/magic/Magdir/troff
index 01ad88a0..320bb619 100644
--- a/magic/Magdir/troff
+++ b/magic/Magdir/troff
@@ -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
diff --git a/src/.cvsignore b/src/.cvsignore
index e750e770..9443f144 100644
--- a/src/.cvsignore
+++ b/src/.cvsignore
@@ -10,3 +10,4 @@ stamp-h1
*.la
Makefile.in
file
+test
diff --git a/src/Makefile.am b/src/Makefile.am
index 9ab9258c..7c7de186 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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 \
diff --git a/src/ascmagic.c b/src/ascmagic.c
index ab224ac8..bcae7536 100644
--- a/src/ascmagic.c
+++ b/src/ascmagic.c
@@ -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)
diff --git a/src/compress.c b/src/compress.c
index 9eaca906..9b41e1df 100644
--- a/src/compress.c
+++ b/src/compress.c
@@ -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
diff --git a/src/file.c b/src/file.c
index 1750191b..1268a6e6 100644
--- a/src/file.c
+++ b/src/file.c
@@ -60,10 +60,9 @@
#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
diff --git a/src/file.h b/src/file.h
index cb4f7f78..f4b4575f 100644
--- a/src/file.h
+++ b/src/file.h
@@ -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
diff --git a/src/fsmagic.c b/src/fsmagic.c
index ec7d0c9c..f4866d33 100644
--- a/src/fsmagic.c
+++ b/src/fsmagic.c
@@ -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),
diff --git a/src/funcs.c b/src/funcs.c
index 3731d9ef..b0ce090e 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -36,19 +36,9 @@
#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
index 00000000..e6efd0f5
--- /dev/null
+++ b/src/getopt_long.c
@@ -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
+}
diff --git a/src/magic.c b/src/magic.c
index b44dd961..30104f5b 100644
--- a/src/magic.c
+++ b/src/magic.c
@@ -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) {
diff --git a/src/magic.h b/src/magic.h
index 6041f548..ecdd53c1 100644
--- a/src/magic.h
+++ b/src/magic.h
@@ -48,11 +48,12 @@
#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" {
diff --git a/src/names.h b/src/names.h
index c7cd38e0..07dd770c 100644
--- a/src/names.h
+++ b/src/names.h
@@ -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},
diff --git a/src/readelf.h b/src/readelf.h
index 77cc2ca7..feb89543 100644
--- a/src/readelf.h
+++ b/src/readelf.h
@@ -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];
diff --git a/src/softmagic.c b/src/softmagic.c
index 3d1a07dd..8ed031a4 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -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 */
}
}
diff --git a/src/tar.h b/src/tar.h
index da870ab1..25b4ba7d 100644
--- a/src/tar.h
+++ b/src/tar.h
@@ -32,20 +32,10 @@
*
* 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.
*
* I'm going to use traditional DP naming conventions here.
@@ -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];
-};
diff --git a/src/test.c b/src/test.c
index 55b78d38..94e483bf 100644
--- a/src/test.c
+++ b/src/test.c
@@ -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);