# don't enforce GNU packaging standards
AUTOMAKE_OPTIONS = foreign no-dependencies
+noinst_HEADERS = debug.h system.h
+
bin_PROGRAMS = file
data_DATA = magic magic.mime magic.mgc magic.mime.mgc
* 4. This notice may not be removed or altered.
*/
+#include "system.h"
#include "file.h"
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <ctype.h>
-#include <fcntl.h>
-#ifdef QUICK
-#include <sys/mman.h>
-#endif
+#include "debug.h"
-#ifndef lint
FILE_RCSID("@(#)Id: apprentice.c,v 1.49 2002/07/03 19:00:41 christos Exp ")
-#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
isspace((unsigned char) *l)) ++l;}
goto error;
}
-#ifdef QUICK
+#ifdef HAVE_MMAP
if ((mm = mmap(0, (size_t)st.st_size, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FILE, fd, (off_t)0)) == MAP_FAILED) {
(void)fprintf(stderr, "%s: Cannot map `%s' (%s)\n",
(void)close(fd);
/*@-branchstate@*/
if (mm != NULL) {
-#ifdef QUICK
+#ifdef HAVE_MMAP
(void)munmap(mm, (size_t)st.st_size);
#else
free(mm);
* 4. This notice may not be removed or altered.
*/
+#include "system.h"
#include "file.h"
-#include <string.h>
-#include <memory.h>
-#include <ctype.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
#include "names.h"
+#include "debug.h"
-#ifndef lint
FILE_RCSID("@(#)Id: ascmagic.c,v 1.32 2002/07/03 18:26:37 christos Exp ")
-#endif /* lint */
typedef unsigned long unichar;
+#include "system.h"
#include "file.h"
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif
-#ifdef HAVE_LIBZ
-#include <zlib.h>
-#endif
+#include "debug.h"
-#ifndef lint
FILE_RCSID("@(#)Id: compress.c,v 1.25 2002/07/03 18:26:37 christos Exp ")
-#endif
/*@-nullassign@*/
/*@unchecked@*/
AC_HEADER_MAJOR
AC_HEADER_SYS_WAIT
AC_HEADER_STDINT
-AC_CHECK_HEADERS(fcntl.h locale.h)
AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h)
-AC_CHECK_HEADERS(unistd.h)
+AC_CHECK_HEADERS(fcntl.h)
AC_CHECK_HEADERS(getopt.h)
AC_CHECK_HEADERS(locale.h)
-AC_CHECK_HEADERS(stdint.h)
+AC_CHECK_HEADERS(regex.h)
+AC_CHECK_HEADERS(unistd.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
--- /dev/null
+/**
+ * To be included after all other includes.
+ */
+#ifndef H_DEBUG
+#define H_DEBUG
+
+#include <assert.h>
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
+
+#endif /* H_DEBUG */
* 4. This notice may not be removed or altered.
*/
+#include "system.h"
#include "file.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/param.h> /* for MAXPATHLEN */
-#include <fcntl.h> /* for open() */
-#ifdef RESTORE_TIME
-# if (__COHERENT__ >= 0x420)
-# include <sys/utime.h>
-# else
-# ifdef USE_UTIMES
-# include <sys/time.h>
-# else
-# include <utime.h>
-# endif
-# endif
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h> /* for read() */
-#endif
-#ifdef HAVE_LOCALE_H
-#include <locale.h>
-#endif
-
-#ifdef HAVE_GETOPT_H
-#include <getopt.h> /* for long options (is this portable?)*/
-#endif
-
#include "patchlevel.h"
+#include "debug.h"
-#ifndef lint
FILE_RCSID("@(#)Id: file.c,v 1.66 2002/07/03 19:00:41 christos Exp ")
-#endif /* lint */
#ifdef S_IFLNK
#ifndef __file_h__
#define __file_h__
-#ifndef __linux__
-#define _LARGEFILE_SOURCE
-#define _LARGEFILE64_SOURCE
-#define _FILE_OFFSET_BITS 64
-#endif
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdio.h>
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
-/* Do this here and now, because struct stat gets re-defined on solaris */
-#include <sys/stat.h>
-
#ifndef HOWMANY
# define HOWMANY 65536 /* how much of the file to look at */
#endif
extern char *optarg;
#endif
-#ifndef HAVE_STRERROR
-/*@unchecked@*/
-extern int sys_nerr;
-/*@unchecked@*/
-extern char *sys_errlist[];
-#define strerror(e) \
- (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
-#endif
-
-#ifndef HAVE_STRTOUL
-#define strtoul(a, b, c) strtol(a, b, c)
-#endif
-
-#if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK)
-#define QUICK
-#endif
-
/*@mayexit@*/
extern int apprentice(const char *fn, int action)
/*@globals lineno, mlist, fileSystem, internalState @*/
/*@observer@*/
extern char *fmttime(long v, int local)
/*@*/;
-#if 0
-extern int is_compress(const unsigned char *, int *)
- /*@*/;
-#endif
extern int is_tar(unsigned char *buf, int nbytes)
/*@*/;
extern void magwarn(const char *f, ...)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
-#if defined(__LCLINT__)
-#define FILE_RCSID(id)
-#else
-#define FILE_RCSID(id) \
-static inline const char *rcsid(const char *p) { \
- return rcsid(p = id); \
-}
-#endif
-
#endif /* __file_h__ */
* 4. This notice may not be removed or altered.
*/
+#include "system.h"
#include "file.h"
-#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <stdlib.h>
-/* Since major is a function on SVR4, we can't use `ifndef major'. */
-#ifdef MAJOR_IN_MKDEV
-# include <sys/mkdev.h>
-# define HAVE_MAJOR
-#endif
-#ifdef MAJOR_IN_SYSMACROS
-# include <sys/sysmacros.h>
-# define HAVE_MAJOR
-#endif
-#ifdef major /* Might be defined in sys/types.h. */
-# define HAVE_MAJOR
-#endif
-
-#ifndef HAVE_MAJOR
-# define major(dev) (((dev) >> 8) & 0xff)
-# define minor(dev) ((dev) & 0xff)
-#endif
-#undef HAVE_MAJOR
+#include "debug.h"
-#ifndef lint
FILE_RCSID("@(#)Id: fsmagic.c,v 1.36 2002/07/03 19:00:41 christos Exp ")
-#endif /* lint */
int
fsmagic(const char *fn, struct stat *sb)
* for file command by Ian Darwin.
*/
+#include "system.h"
#include "file.h"
-#include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
#include "tar.h"
+#include "debug.h"
-#ifndef lint
FILE_RCSID("@(#)Id: is_tar.c,v 1.17 2002/07/03 18:26:38 christos Exp ")
-#endif
#define isodigit(c) ( ((c) >= '0') && ((c) <= '7') )
* 4. This notice may not be removed or altered.
*/
+#include "system.h"
#include "file.h"
-#include <string.h>
-#ifdef __STDC__
-# include <stdarg.h>
-#else
-# include <varargs.h>
-#endif
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <time.h>
+#include "debug.h"
-#ifndef lint
FILE_RCSID("@(#)Id: print.c,v 1.38 2002/07/03 18:37:44 christos Exp ")
-#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
-#include "file.h"
+#include "system.h"
#ifdef BUILTIN_ELF
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
+#include "file.h"
#include "readelf.h"
+#include "debug.h"
-#ifndef lint
FILE_RCSID("@(#)Id: readelf.c,v 1.22 2002/07/03 18:26:38 christos Exp ")
-#endif
static uint16_t
getu16(int swap, uint16_t value)
return;
}
}
-#endif
+#endif /* BUILTIN_ELF */
* 4. This notice may not be removed or altered.
*/
+#include "system.h"
#include "file.h"
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <time.h>
-#include <regex.h>
+#include "debug.h"
-#ifndef lint
FILE_RCSID("@(#)Id: softmagic.c,v 1.51 2002/07/03 18:26:38 christos Exp ")
-#endif /* lint */
/*@-redecl@*/
/*@unchecked@*/
--- /dev/null
+#ifndef H_SYSTEM
+#define H_SYSTEM
+
+#ifndef __linux__
+#define _LARGEFILE_SOURCE
+#define _LARGEFILE64_SOURCE
+#define _FILE_OFFSET_BITS 64
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <sys/stat.h>
+#include <stdio.h>
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_STRING_H
+# if !STDC_HEADERS && HAVE_MEMORY_H
+# include <memory.h>
+# endif
+# include <string.h>
+#else
+# include <strings.h>
+char *memchr ();
+#endif
+
+#include <errno.h>
+#ifndef errno
+/*@-declundef @*/
+extern int errno;
+/*@=declundef @*/
+#endif
+
+#ifdef STDC_HEADERS
+#include <stdlib.h>
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif /* STDC_HEADERS */
+
+#if defined (__GLIBC__) && defined(__LCLINT__)
+/*@-declundef@*/
+/*@unchecked@*/
+extern __const __int32_t *__ctype_tolower;
+/*@unchecked@*/
+extern __const __int32_t *__ctype_toupper;
+/*@=declundef@*/
+#endif
+
+#include <ctype.h>
+
+#if defined (__GLIBC__) && defined(__LCLINT__)
+/*@-exportlocal@*/
+extern int isalnum(int) __THROW /*@*/;
+extern int iscntrl(int) __THROW /*@*/;
+extern int isgraph(int) __THROW /*@*/;
+extern int islower(int) __THROW /*@*/;
+extern int ispunct(int) __THROW /*@*/;
+extern int isxdigit(int) __THROW /*@*/;
+extern int isascii(int) __THROW /*@*/;
+extern int toascii(int) __THROW /*@*/;
+extern int _toupper(int) __THROW /*@*/;
+extern int _tolower(int) __THROW /*@*/;
+/*@=exportlocal@*/
+#endif
+
+/* XXX solaris2.5.1 has not */
+#if !defined(EXIT_FAILURE)
+#define EXIT_FAILURE 1
+#endif
+
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#else
+#include <sys/file.h>
+#endif
+
+#if HAVE_SYS_MMAN_H && !defined(__LCLINT__)
+#include <sys/mman.h>
+#endif
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
+#ifdef RESTORE_TIME
+# if (__COHERENT__ >= 0x420)
+# include <sys/utime.h>
+# else
+# ifdef USE_UTIMES
+# include <sys/time.h>
+# else
+# include <utime.h>
+# endif
+# endif
+#endif
+
+/* Since major is a function on SVR4, we can't use `ifndef major'. */
+#if MAJOR_IN_MKDEV
+#include <sys/mkdev.h>
+#define HAVE_MAJOR
+#endif
+#if MAJOR_IN_SYSMACROS
+#include <sys/sysmacros.h>
+#define HAVE_MAJOR
+#endif
+#ifdef major /* Might be defined in sys/types.h. */
+#define HAVE_MAJOR
+#endif
+
+#ifndef HAVE_MAJOR
+#define major(dev) (((dev) >> 8) & 0xff)
+#define minor(dev) ((dev) & 0xff)
+#define makedev(maj, min) (((maj) << 8) | (min))
+#endif
+#undef HAVE_MAJOR
+
+#ifdef HAVE_GETOPT_H
+#include <getopt.h> /* for long options (is this portable?)*/
+#endif
+
+#if HAVE_REGEX_H
+#include <regex.h>
+#endif
+
+#ifdef HAVE_LIBZ
+#include <zlib.h>
+#endif
+
+#ifndef HAVE_STRERROR
+/*@unchecked@*/
+extern int sys_nerr;
+/*@unchecked@*/
+extern char *sys_errlist[];
+#define strerror(e) \
+ (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
+#endif
+
+#ifndef HAVE_STRTOUL
+#define strtoul(a, b, c) strtol(a, b, c)
+#endif
+
+#if HAVE_LOCALE_H
+# include <locale.h>
+#endif
+
+#if defined(__LCLINT__)
+#define FILE_RCSID(id)
+#else
+#define FILE_RCSID(id) \
+static inline const char *rcsid(const char *p) { \
+ return rcsid(p = id); \
+}
+#endif
+
+#endif /* H_SYSTEM */