dd system.h/debug.h, factor build conf into system.h.
authorjbj <devnull@localhost>
Tue, 1 Oct 2002 19:03:37 +0000 (19:03 +0000)
committerjbj <devnull@localhost>
Tue, 1 Oct 2002 19:03:37 +0000 (19:03 +0000)
CVS patchset: 5743
CVS date: 2002/10/01 19:03:37

14 files changed:
file/Makefile.am
file/apprentice.c
file/ascmagic.c
file/compress.c
file/configure.ac
file/debug.h [new file with mode: 0644]
file/file.c
file/file.h
file/fsmagic.c
file/is_tar.c
file/print.c
file/readelf.c
file/softmagic.c
file/system.h [new file with mode: 0644]

index 654cef5..667c057 100644 (file)
@@ -1,6 +1,8 @@
 # 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
index 0fc3a91..7136e37 100644 (file)
  * 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;}
@@ -942,7 +932,7 @@ apprentice_map(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
                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",
@@ -995,7 +985,7 @@ error:
                (void)close(fd);
 /*@-branchstate@*/
        if (mm != NULL) {
-#ifdef QUICK
+#ifdef HAVE_MMAP
                (void)munmap(mm, (size_t)st.st_size);
 #else
                free(mm);
index 2d7b68e..89e839a 100644 (file)
  * 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;
 
index d457ef5..6dac3d8 100644 (file)
@@ -1,20 +1,9 @@
 
+#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@*/
index 37f31cc..08539dc 100644 (file)
@@ -62,12 +62,12 @@ AC_HEADER_STDC
 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
diff --git a/file/debug.h b/file/debug.h
new file mode 100644 (file)
index 0000000..19376c0
--- /dev/null
@@ -0,0 +1,13 @@
+/**
+ * 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 */
index 84c703c..590c048 100644 (file)
  * 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
index 4625dfb..d66198b 100644 (file)
 #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
@@ -160,23 +142,6 @@ extern int optind;         /* From getopt(3)                       */
 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 @*/
@@ -198,10 +163,6 @@ extern int   fsmagic(const char *fn, /*@out@*/ struct stat *sb)
 /*@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, ...)
@@ -238,13 +199,4 @@ extern int pipe2file(int fd, void *startbuf, size_t nbytes)
        /*@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__ */
index 6970c0e..f837772 100644 (file)
  * 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)
index aa9150e..74b0284 100644 (file)
  * 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') )
 
index df133fe..f78745a 100644 (file)
  * 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]))
 
index 4909944..23881dc 100644 (file)
@@ -1,18 +1,11 @@
-#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)
@@ -646,4 +639,4 @@ tryelf(int fd, unsigned char *buf, int nbytes)
                return;
        }
 }
-#endif
+#endif /* BUILTIN_ELF */
index b87e9dd..e58de62 100644 (file)
  * 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@*/
diff --git a/file/system.h b/file/system.h
new file mode 100644 (file)
index 0000000..56244f9
--- /dev/null
@@ -0,0 +1,176 @@
+#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 */