From 57b080d43fbc3095152e01f74d9a5b2342a400ae Mon Sep 17 00:00:00 2001 From: jbj Date: Mon, 14 Apr 2003 20:54:50 +0000 Subject: [PATCH] Compiles with file.h changes from file-4.02. CVS patchset: 6740 CVS date: 2003/04/14 20:54:50 --- file/src/Makefile.am | 58 ++++++++ file/src/acinclude.m4 | 253 ++++++++++++++++++++++++++++++++++ file/src/apprentice.c | 189 +++++++++++++------------- file/src/autogen.sh | 44 ++++++ file/src/configure.ac | 116 ++++++++++++++++ file/src/debug.h | 13 ++ file/src/file.c | 4 +- file/src/file.h | 135 +++++++++++-------- file/src/print.c | 38 +++--- file/src/softmagic.c | 366 +++++++++++++++++++++++++------------------------- file/src/system.h | 326 ++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 1193 insertions(+), 349 deletions(-) create mode 100644 file/src/Makefile.am create mode 100644 file/src/acinclude.m4 create mode 100755 file/src/autogen.sh create mode 100644 file/src/configure.ac create mode 100644 file/src/debug.h create mode 100644 file/src/system.h diff --git a/file/src/Makefile.am b/file/src/Makefile.am new file mode 100644 index 0000000..6251a5d --- /dev/null +++ b/file/src/Makefile.am @@ -0,0 +1,58 @@ +AUTOMAKE_OPTIONS = 1.4 foreign + +LINT = splint + +EXTRA_DIST = LEGAL.NOTICE MAINT Makefile.std magic2mime magic.mime \ + Localstuff Header $(magic_FRAGMENTS) file.man magic.man + +BUILT_SOURCES = listobjs $(man_MANS) + +noinst_HEADERS = debug.h names.h patchlevel.h readelf.h system.h tar.h \ + file.h + +#pkgincdir = @includedir@/fmagic +#pkginc_HEADERS = file.h + +#usrlibdir = $(libdir)@MARK64@ +#usrlib_LTLIBRARIES = libfmagic.la + +noinst_LTLIBRARIES = libfmagic.la + +libfmagic_la_SOURCES = \ + apprentice.c ascmagic.c fsmagic.c compress.c \ + print.c readelf.c softmagic.c + +#bin_PROGRAMS = file +noinst_PROGRAMS = file + +file_SOURCES = file.c +file_LDFLAGS = -all-static +file_LDADD = libfmagic.la + +#man_MANS = file.1 $(man_MAGIC) +noinst_MANS = file.1 + +pkglibdir = @prefix@/lib/rpm +MAGIC = $(pkglibdir)/magic +CPPFLAGS = -DMAGIC='"$(MAGIC)"' + +fsect = @fsect@ + +file.1: Makefile file.man + @rm -f $@ + sed -e s@__CSECTION__@1@g \ + -e s@__FSECTION__@${fsect}@g \ + -e s@__VERSION__@${VERSION}@g \ + -e s@__MAGIC__@${MAGIC}@g $(srcdir)/file.man > $@ + +listobjs: + @echo $(libfmagic_la_SOURCES:.c=.lo) > $@ + +.PHONY: lint +lint: + $(LINT) $(DEFS) $(INCLUDES) $(file_SOURCES) $(libfmagic_la_SOURCES) $(pkginc_HEADERS) $(noinst_HEADERS) + +.PHONY: sources +sources: + @echo $(libfmagic_la_SOURCES:%=file/%) + diff --git a/file/src/acinclude.m4 b/file/src/acinclude.m4 new file mode 100644 index 0000000..bd52776 --- /dev/null +++ b/file/src/acinclude.m4 @@ -0,0 +1,253 @@ +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,1,[Define if the `long long' type works.]) +fi +]) + +dnl from autoconf 2.13 acspecific.m4, with changes to check for daylight + +AC_DEFUN([AC_STRUCT_TIMEZONE_DAYLIGHT], +[AC_REQUIRE([AC_STRUCT_TM])dnl +AC_CACHE_CHECK([for tm_zone in struct tm], ac_cv_struct_tm_zone, +[AC_TRY_COMPILE([#include +#include <$ac_cv_struct_tm>], [struct tm tm; tm.tm_zone;], + ac_cv_struct_tm_zone=yes, ac_cv_struct_tm_zone=no)]) +if test "$ac_cv_struct_tm_zone" = yes; then + AC_DEFINE(HAVE_TM_ZONE,1,[HAVE_TM_ZONE]) +fi +AC_CACHE_CHECK(for tzname, ac_cv_var_tzname, +[AC_TRY_LINK( +changequote(<<, >>)dnl +<<#include +#ifndef tzname /* For SGI. */ +extern char *tzname[]; /* RS6000 and others reject char **tzname. */ +#endif>>, +changequote([, ])dnl +[atoi(*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)]) + if test $ac_cv_var_tzname = yes; then + AC_DEFINE(HAVE_TZNAME,1,[HAVE_TZNAME]) + fi + +AC_CACHE_CHECK([for tm_isdst in struct tm], ac_cv_struct_tm_isdst, +[AC_TRY_COMPILE([#include +#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,1,[Define if we have "tm_isdst" in "struct tm".]) +fi +AC_CACHE_CHECK(for daylight, ac_cv_var_daylight, +[AC_TRY_LINK( +changequote(<<, >>)dnl +<<#include +#ifndef daylight /* In case IRIX #defines this, too */ +extern int daylight; +#endif>>, +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,1,[Define if we have a global "int" variable "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 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 +#endif +#include +#if STDC_HEADERS +#include +#include +#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, $1) +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 +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, AC_TYPE_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 +#endif +#include +#ifdef STDC_HEADERS +#include +#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 +#endif +#include +#if STDC_HEADERS +#include +#include +#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, $1) +fi +]) + +dnl AC_HEADER_STDINT +AC_DEFUN([AC_HEADER_STDINT], [AC_CHECK_HEADERS(stdint.h)]) + +#serial 19 + +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 . + +dnl Internal subroutine of AC_SYS_LARGEFILE. +dnl AC_SYS_LARGEFILE_TEST_INCLUDES +AC_DEFUN([AC_SYS_LARGEFILE_TEST_INCLUDES], + [[#include + /* 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, INCLU= +DES, 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 ], [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 ], + [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]) + diff --git a/file/src/apprentice.c b/file/src/apprentice.c index 9c36dac..fdcb594 100644 --- a/file/src/apprentice.c +++ b/file/src/apprentice.c @@ -1,35 +1,44 @@ /* + * Copyright (c) Ian F. Darwin 1986-1995. + * Software written by Ian F. Darwin and others; + * maintained 1995-present by Christos Zoulas and others. + * + * 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 immediately at the beginning of the file, without modification, + * 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 Ian F. Darwin and others. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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. + */ +/* * apprentice - make one pass through /etc/magic, learning its secrets. - * - * Copyright (c) Ian F. Darwin, 1987. - * Written by Ian F. Darwin. - * - * This software is not subject to any license of the American Telephone - * and Telegraph Company or of the Regents of the University of California. - * - * Permission is granted to anyone to use this software for any purpose on - * any computer system, and to alter it and redistribute it freely, subject - * to the following restrictions: - * - * 1. The author is not responsible for the consequences of use of this - * software, no matter how awful, even if they arise from flaws in it. - * - * 2. The origin of this software must not be misrepresented, either by - * explicit claim or by omission. Since few users ever read sources, - * credits must appear in the documentation. - * - * 3. Altered versions must be plainly marked as such, and must not be - * misrepresented as being the original software. Since few users - * ever read sources, credits must appear in the documentation. - * - * 4. This notice may not be removed or altered. */ #include "system.h" #include "file.h" #include "debug.h" -FILE_RCSID("@(#)Id: apprentice.c,v 1.49 2002/07/03 19:00:41 christos Exp ") +FILE_RCSID("@(#)Id: apprentice.c,v 1.57 2003/03/28 21:02:03 christos Exp ") /*@access fmagic @*/ @@ -85,29 +94,29 @@ signextend(struct magic *m, uint32_t v) * vital. When later compared with the data, * the sign extension must have happened. */ - case BYTE: + case FILE_BYTE: v = (char) v; break; - case SHORT: - case BESHORT: - case LESHORT: + case FILE_SHORT: + case FILE_BESHORT: + case FILE_LESHORT: v = (short) v; break; - case DATE: - case BEDATE: - case LEDATE: - case LDATE: - case BELDATE: - case LELDATE: - case LONG: - case BELONG: - case LELONG: + case FILE_DATE: + case FILE_BEDATE: + case FILE_LEDATE: + case FILE_LDATE: + case FILE_BELDATE: + case FILE_LELDATE: + case FILE_LONG: + case FILE_BELONG: + case FILE_LELONG: v = (int32_t) v; break; - case STRING: - case PSTRING: + case FILE_STRING: + case FILE_PSTRING: break; - case REGEX: + case FILE_REGEX: break; default: magwarn("can't happen: m->type=%d\n", m->type); @@ -284,7 +293,7 @@ getvalue(struct magic *m, /*@out@*/ char **p) { int slen; - if (m->type == STRING || m->type == PSTRING || m->type == REGEX) { + if (m->type == FILE_STRING || m->type == FILE_PSTRING || m->type == FILE_REGEX) { *p = getstr(*p, m->value.s, sizeof(m->value.s), &slen); m->vallen = slen; } else @@ -344,7 +353,7 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp, l = t; if (m->flag & INDIR) { - m->in_type = LONG; + m->in_type = FILE_LONG; m->in_offset = 0; /* * read [.lbs][+-]nnnnn) @@ -353,24 +362,24 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp, l++; switch (*l) { case 'l': - m->in_type = LELONG; + m->in_type = FILE_LELONG; break; case 'L': - m->in_type = BELONG; + m->in_type = FILE_BELONG; break; case 'h': case 's': - m->in_type = LESHORT; + m->in_type = FILE_LESHORT; break; case 'H': case 'S': - m->in_type = BESHORT; + m->in_type = FILE_BESHORT; break; case 'c': case 'b': case 'C': case 'B': - m->in_type = BYTE; + m->in_type = FILE_BYTE; break; default: magwarn("indirect offset type %c invalid", *l); @@ -379,40 +388,40 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp, l++; } if (*l == '~') { - m->in_op = OPINVERSE; + m->in_op = FILE_OPINVERSE; l++; } switch (*l) { case '&': - m->in_op |= OPAND; + m->in_op |= FILE_OPAND; l++; break; case '|': - m->in_op |= OPOR; + m->in_op |= FILE_OPOR; l++; break; case '^': - m->in_op |= OPXOR; + m->in_op |= FILE_OPXOR; l++; break; case '+': - m->in_op |= OPADD; + m->in_op |= FILE_OPADD; l++; break; case '-': - m->in_op |= OPMINUS; + m->in_op |= FILE_OPMINUS; l++; break; case '*': - m->in_op |= OPMULTIPLY; + m->in_op |= FILE_OPMULTIPLY; l++; break; case '/': - m->in_op |= OPDIVIDE; + m->in_op |= FILE_OPDIVIDE; l++; break; case '%': - m->in_op |= OPMODULO; + m->in_op |= FILE_OPMODULO; l++; break; } @@ -454,55 +463,55 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp, /* get type, skip it */ if (strncmp(l, "char", NBYTE)==0) { /* HP/UX compat */ - m->type = BYTE; + m->type = FILE_BYTE; l += NBYTE; } else if (strncmp(l, "byte", NBYTE)==0) { - m->type = BYTE; + m->type = FILE_BYTE; l += NBYTE; } else if (strncmp(l, "short", NSHORT)==0) { - m->type = SHORT; + m->type = FILE_SHORT; l += NSHORT; } else if (strncmp(l, "long", NLONG)==0) { - m->type = LONG; + m->type = FILE_LONG; l += NLONG; } else if (strncmp(l, "string", NSTRING)==0) { - m->type = STRING; + m->type = FILE_STRING; l += NSTRING; } else if (strncmp(l, "date", NDATE)==0) { - m->type = DATE; + m->type = FILE_DATE; l += NDATE; } else if (strncmp(l, "beshort", NBESHORT)==0) { - m->type = BESHORT; + m->type = FILE_BESHORT; l += NBESHORT; } else if (strncmp(l, "belong", NBELONG)==0) { - m->type = BELONG; + m->type = FILE_BELONG; l += NBELONG; } else if (strncmp(l, "bedate", NBEDATE)==0) { - m->type = BEDATE; + m->type = FILE_BEDATE; l += NBEDATE; } else if (strncmp(l, "leshort", NLESHORT)==0) { - m->type = LESHORT; + m->type = FILE_LESHORT; l += NLESHORT; } else if (strncmp(l, "lelong", NLELONG)==0) { - m->type = LELONG; + m->type = FILE_LELONG; l += NLELONG; } else if (strncmp(l, "ledate", NLEDATE)==0) { - m->type = LEDATE; + m->type = FILE_LEDATE; l += NLEDATE; } else if (strncmp(l, "pstring", NPSTRING)==0) { - m->type = PSTRING; + m->type = FILE_PSTRING; l += NPSTRING; } else if (strncmp(l, "ldate", NLDATE)==0) { - m->type = LDATE; + m->type = FILE_LDATE; l += NLDATE; } else if (strncmp(l, "beldate", NBELDATE)==0) { - m->type = BELDATE; + m->type = FILE_BELDATE; l += NBELDATE; } else if (strncmp(l, "leldate", NLELDATE)==0) { - m->type = LELDATE; + m->type = FILE_LELDATE; l += NLELDATE; } else if (strncmp(l, "regex", NREGEX)==0) { - m->type = REGEX; + m->type = FILE_REGEX; l += sizeof("regex"); } else { magwarn("type %s invalid", l); @@ -511,56 +520,56 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp, /* New-style anding: "0 byte&0x80 =0x80 dynamically linked" */ /* New and improved: ~ & | ^ + - * / % -- exciting, isn't it? */ if (*l == '~') { - if (STRING != m->type && PSTRING != m->type) - m->mask_op = OPINVERSE; + if (FILE_STRING != m->type && FILE_PSTRING != m->type) + m->mask_op = FILE_OPINVERSE; ++l; } switch (*l) { case '&': - m->mask_op |= OPAND; + m->mask_op |= FILE_OPAND; ++l; m->mask = signextend(m, strtoul(l, &l, 0)); eatsize(&l); break; case '|': - m->mask_op |= OPOR; + m->mask_op |= FILE_OPOR; ++l; m->mask = signextend(m, strtoul(l, &l, 0)); eatsize(&l); break; case '^': - m->mask_op |= OPXOR; + m->mask_op |= FILE_OPXOR; ++l; m->mask = signextend(m, strtoul(l, &l, 0)); eatsize(&l); break; case '+': - m->mask_op |= OPADD; + m->mask_op |= FILE_OPADD; ++l; m->mask = signextend(m, strtoul(l, &l, 0)); eatsize(&l); break; case '-': - m->mask_op |= OPMINUS; + m->mask_op |= FILE_OPMINUS; ++l; m->mask = signextend(m, strtoul(l, &l, 0)); eatsize(&l); break; case '*': - m->mask_op |= OPMULTIPLY; + m->mask_op |= FILE_OPMULTIPLY; ++l; m->mask = signextend(m, strtoul(l, &l, 0)); eatsize(&l); break; case '%': - m->mask_op |= OPMODULO; + m->mask_op |= FILE_OPMODULO; ++l; m->mask = signextend(m, strtoul(l, &l, 0)); eatsize(&l); break; case '/': - if (STRING != m->type && PSTRING != m->type) { - m->mask_op |= OPDIVIDE; + if (FILE_STRING != m->type && FILE_PSTRING != m->type) { + m->mask_op |= FILE_OPDIVIDE; ++l; m->mask = signextend(m, strtoul(l, &l, 0)); eatsize(&l); @@ -606,7 +615,7 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp, } break; case '!': - if (m->type != STRING && m->type != PSTRING) { + if (m->type != FILE_STRING && m->type != FILE_PSTRING) { m->reln = *l; ++l; break; @@ -650,7 +659,7 @@ GetDesc: {}; #ifndef COMPILE_ONLY - if (action == CHECK) { + if (action == FILE_CHECK) { mdump(m); } #endif @@ -761,7 +770,7 @@ void bs1(struct magic *m) m->cont_level = swap2(m->cont_level); m->offset = swap4(m->offset); m->in_offset = swap4(m->in_offset); - if (m->type != STRING) + if (m->type != FILE_STRING) m->value.l = swap4(m->value.l); m->mask = swap4(m->mask); } @@ -829,7 +838,7 @@ apprentice_file(fmagic fm, /*@out@*/ struct magic **magicp, *magicp = (struct magic *) xcalloc(sizeof(**magicp), maxmagic); /* parse it */ - if (action == CHECK) /* print silly verbose header for USG compat. */ + if (action == FILE_CHECK) /* print silly verbose header for USG compat. */ (void) printf("%s\n", hdr); for (fm->lineno = 1; fgets(line, BUFSIZ, f) != NULL; fm->lineno++) { @@ -1014,7 +1023,7 @@ apprentice_1(fmagic fm, const char *fn, int action) struct mlist *ml; int rv = -1; - if (action == COMPILE) { + if (action == FILE_COMPILE) { rv = apprentice_file(fm, &magic, &nmagic, fn, action); if (rv) return rv; @@ -1087,7 +1096,7 @@ fmagicSetup(fmagic fm, const char *fn, int action) if (errs == -1) (void) fprintf(stderr, "%s: couldn't find any magic files!\n", __progname); - if (action == CHECK && errs) + if (action == FILE_CHECK && errs) exit(EXIT_FAILURE); free(mfn); diff --git a/file/src/autogen.sh b/file/src/autogen.sh new file mode 100755 index 0000000..b35834f --- /dev/null +++ b/file/src/autogen.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +export CFLAGS +export LDFLAGS + +LTV="libtoolize (GNU libtool) 1.4.3" +ACV="autoconf (GNU Autoconf) 2.57" +AMV="automake (GNU automake) 1.7.3" +USAGE=" +This script documents the versions of the tools I'm using to build rpm: + libtool-1.4.3 + autoconf-2.57 + automake-1.7.3 +Simply edit this script to change the libtool/autoconf/automake versions +checked if you need to, as rpm should build (and has built) with all +recent versions of libtool/autoconf/automake. +" + +[ "`libtoolize --version`" != "$LTV" ] && echo "$USAGE" && exit 1 +[ "`autoconf --version | head -1`" != "$ACV" ] && echo "$USAGE" && exit 1 +[ "`automake --version | head -1 | sed -e 's/1\.4[a-z]/1.4/'`" != "$AMV" ] && echo "$USAGE" && exit 1 + +libtoolize --copy --force +aclocal +autoheader +automake -a -c +autoconf + +if [ "$1" = "--noconfigure" ]; then + exit 0; +fi + +if [ X"$@" = X -a "X`uname -s`" = "XLinux" ]; then + if [ -d /usr/share/man ]; then + mandir=/usr/share/man + infodir=/usr/share/info + else + mandir=/usr/man + infodir=/usr/info + fi + ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --infodir=${infodir} --mandir=${mandir} --enable-static "$@" +else + ./configure "$@" +fi diff --git a/file/src/configure.ac b/file/src/configure.ac new file mode 100644 index 0000000..890b50f --- /dev/null +++ b/file/src/configure.ac @@ -0,0 +1,116 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(file, 3.39) +AC_CANONICAL_TARGET +AM_INIT_AUTOMAKE +AM_CONFIG_HEADER([config.h]) + +AC_MSG_CHECKING(for builtin ELF support) +AC_ARG_ENABLE(elf, +[ --disable-elf disable builtin ELF support], +AH_TEMPLATE([BUILTIN_ELF], [Define if builtin ELF support is enabled.]) +[if test "${enableval}" = yes; then + AC_MSG_RESULT(yes) + AC_DEFINE([BUILTIN_ELF],1) +else + AC_MSG_RESULT(no) +fi], [ + # enable by default + AC_MSG_RESULT(yes) + AC_DEFINE([BUILTIN_ELF], 1) +]) + +AC_MSG_CHECKING(for ELF core file support) +AC_ARG_ENABLE(elf-core, +[ --disable-elf-core disable ELF core file support], +AH_TEMPLATE([ELFCORE], [Define if ELF core file support is enabled.]) +[if test "${enableval}" = yes; then + AC_MSG_RESULT(yes) + AC_DEFINE([ELFCORE], 1) +else + AC_MSG_RESULT(no) +fi], [ + # enable by default + AC_MSG_RESULT(yes) + AC_DEFINE([ELFCORE], 1) +]) + +AC_MSG_CHECKING(for file formats in man section 5) +AC_ARG_ENABLE(fsect-man5, +[ --enable-fsect-man5 enable file formats in man section 5], +[if test "${enableval}" = yes; then + AC_MSG_RESULT(yes) + fsect=5 +else + AC_MSG_RESULT(no) + fsect=4 +fi], [ + # disable by default + AC_MSG_RESULT(no) + fsect=4 +]) +AC_SUBST(fsect) + +dnl Checks for programs. +AC_PROG_CC +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_LIBTOOL +if test "$ac_cv_prog_gcc" = yes; then + CFLAGS="$CFLAGS -D_GNU_SOURCE -D_REENTRANT -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wno-char-subscripts" +fi +export CFLAGS + +dnl XXX Choose /usr/lib or /usr/lib64 for library installs. +MARK64= +case "${target_cpu}" in +x86_64*) MARK64=64 ;; +esac +AC_SUBST(MARK64) + +dnl Checks for headers +AC_HEADER_STDC +AC_HEADER_STDINT +AC_HEADER_MAJOR +AC_HEADER_SYS_WAIT +AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h) +AC_CHECK_HEADERS(error.h) +AC_CHECK_HEADERS(fcntl.h) +AC_CHECK_HEADERS(getopt.h) +AC_CHECK_HEADERS(locale.h) +AC_CHECK_HEADERS(mcheck.h) +AC_CHECK_HEADERS(regex.h) +AC_CHECK_HEADERS(unistd.h) + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_OFF_T +AC_TYPE_SIZE_T +AC_STRUCT_ST_RDEV +AC_STRUCT_TIMEZONE_DAYLIGHT +AC_SYS_LARGEFILE + +AC_CHECK_TYPE_STDC(uint8_t, unsigned char) +AC_CHECK_TYPE_STDC(uint16_t, unsigned short) +AC_CHECK_TYPE_STDC(uint32_t, unsigned int) +AC_C_LONG_LONG +if test $ac_cv_c_long_long = yes; then + long64='unsigned long long'; +else + long64='unsigned long'; +fi +dnl This needs a patch to autoconf 2.13 acgeneral.m4 +AC_CHECK_TYPE2_STDC(uint64_t, $long64) + +AC_CHECK_SIZEOF_STDC_HEADERS(uint8_t, 0) +AC_CHECK_SIZEOF_STDC_HEADERS(uint16_t, 0) +AC_CHECK_SIZEOF_STDC_HEADERS(uint32_t, 0) +AC_CHECK_SIZEOF_STDC_HEADERS(uint64_t, 0) + +dnl Checks for functions +AC_CHECK_FUNCS(error mtrace mkstemp mmap strdup strerror strtoul) + +dnl Checks for libraries +AC_CHECK_LIB(z, gzopen) +dnl AC_CHECK_LIB(bz2, BZ2_bzReadOpen) + +AC_OUTPUT(Makefile) diff --git a/file/src/debug.h b/file/src/debug.h new file mode 100644 index 0000000..19376c0 --- /dev/null +++ b/file/src/debug.h @@ -0,0 +1,13 @@ +/** + * To be included after all other includes. + */ +#ifndef H_DEBUG +#define H_DEBUG + +#include + +#ifdef DMALLOC +#include +#endif + +#endif /* H_DEBUG */ diff --git a/file/src/file.c b/file/src/file.c index ee69d21..a146e36 100644 --- a/file/src/file.c +++ b/file/src/file.c @@ -246,10 +246,10 @@ main(int argc, char **argv) fm->flags |= FMAGIC_FLAGS_BRIEF; /*@switchbreak@*/ break; case 'c': - action = CHECK; + action = FILE_CHECK; /*@switchbreak@*/ break; case 'C': - action = COMPILE; + action = FILE_COMPILE; /*@switchbreak@*/ break; case 'd': fm->flags |= FMAGIC_FLAGS_DEBUG; diff --git a/file/src/file.h b/file/src/file.h index 72b9e8c..fb843a5 100644 --- a/file/src/file.h +++ b/file/src/file.h @@ -1,29 +1,38 @@ + /* + * Copyright (c) Ian F. Darwin 1986-1995. + * Software written by Ian F. Darwin and others; + * maintained 1995-present by Christos Zoulas and others. + * + * 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 immediately at the beginning of the file, without modification, + * 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 Ian F. Darwin and others. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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. + */ /* * file.h - definitions for file(1) program - * @(#)Id: file.h,v 1.43 2002/07/03 18:57:52 christos Exp - * - * Copyright (c) Ian F. Darwin, 1987. - * Written by Ian F. Darwin. - * - * This software is not subject to any license of the American Telephone - * and Telegraph Company or of the Regents of the University of California. - * - * Permission is granted to anyone to use this software for any purpose on - * any computer system, and to alter it and redistribute it freely, subject - * to the following restrictions: - * - * 1. The author is not responsible for the consequences of use of this - * software, no matter how awful, even if they arise from flaws in it. - * - * 2. The origin of this software must not be misrepresented, either by - * explicit claim or by omission. Since few users ever read sources, - * credits must appear in the documentation. - * - * 3. Altered versions must be plainly marked as such, and must not be - * misrepresented as being the original software. Since few users - * ever read sources, credits must appear in the documentation. - * - * 4. This notice may not be removed or altered. + * @(#) Id: file.h,v 1.53 2003/03/28 21:02:03 christos Exp */ #ifndef __file_h__ @@ -35,55 +44,68 @@ # define HOWMANY 65536 /* how much of the file to look at */ #endif #define MAXMAGIS 4096 /* max entries in /etc/magic */ -#define MAXDESC 50 /* max leng of text description */ +#define MAXDESC 64 /* max leng of text description */ #define MAXstring 32 /* max leng of "string" types */ #define MAGICNO 0xF11E041C -#define VERSIONNO 1 +#define VERSIONNO 2 +#define FILE_MAGICSIZE (32 * 4) -#define CHECK 1 -#define COMPILE 2 +#define FILE_CHECK 1 +#define FILE_COMPILE 2 struct magic { + /* Word 1 */ uint16_t cont_level; /* level of ">" */ uint8_t nospflag; /* supress space character */ uint8_t flag; #define INDIR 1 /* if '>(...)' appears, */ #define UNSIGNED 2 /* comparison is unsigned */ #define OFFADD 4 /* if '>&' appears, */ + /* Word 2 */ uint8_t reln; /* relation (0=eq, '>'=gt, etc) */ uint8_t vallen; /* length of string value, if any */ uint8_t type; /* int, short, long or string. */ uint8_t in_type; /* type of indirrection */ -#define BYTE 1 -#define SHORT 2 -#define LONG 4 -#define STRING 5 -#define DATE 6 -#define BESHORT 7 -#define BELONG 8 -#define BEDATE 9 -#define LESHORT 10 -#define LELONG 11 -#define LEDATE 12 -#define PSTRING 13 -#define LDATE 14 -#define BELDATE 15 -#define LELDATE 16 -#define REGEX 17 +#define FILE_BYTE 1 +#define FILE_SHORT 2 +#define FILE_LONG 4 +#define FILE_STRING 5 +#define FILE_DATE 6 +#define FILE_BESHORT 7 +#define FILE_BELONG 8 +#define FILE_BEDATE 9 +#define FILE_LESHORT 10 +#define FILE_LELONG 11 +#define FILE_LEDATE 12 +#define FILE_PSTRING 13 +#define FILE_LDATE 14 +#define FILE_BELDATE 15 +#define FILE_LELDATE 16 +#define FILE_REGEX 17 + /* Word 3 */ uint8_t in_op; /* operator for indirection */ uint8_t mask_op; /* operator for mask */ -#define OPAND 1 -#define OPOR 2 -#define OPXOR 3 -#define OPADD 4 -#define OPMINUS 5 -#define OPMULTIPLY 6 -#define OPDIVIDE 7 -#define OPMODULO 8 -#define OPINVERSE 0x80 +#define FILE_OPAND 1 +#define FILE_OPOR 2 +#define FILE_OPXOR 3 +#define FILE_OPADD 4 +#define FILE_OPMINUS 5 +#define FILE_OPMULTIPLY 6 +#define FILE_OPDIVIDE 7 +#define FILE_OPMODULO 8 +#define FILE_OPINVERSE 0x80 + /* Word 4 */ int32_t offset; /* offset to magic number */ + /* Word 5 */ int32_t in_offset; /* offset from indirection */ + /* Word 6 */ + uint32_t mask; /* mask before comparison with value */ + /* Word 7 */ + uint32_t dummy3; + /* Word 8 */ + uint32_t dummp4; + /* Words 9-16 */ union VALUETYPE { uint8_t b; uint16_t h; @@ -93,9 +115,9 @@ struct magic { uint8_t hs[2]; /* 2 bytes of a fixed-endian "short" */ uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */ } value; /* either number or string */ - uint32_t mask; /* mask before comparison with value */ + /* Words 17..31 */ char desc[MAXDESC]; /* description */ -} __attribute__((__packed__)); +}; #define BIT(A) (1 << (A)) #define STRING_IGNORE_LOWERCASE BIT(0) @@ -110,6 +132,9 @@ struct magic { struct mlist { struct magic *magic; /* array of magic entries */ uint32_t nmagic; /* number of entries in array */ + int mapped; /* allocation type: 0 => apprentice_file + * 1 => apprentice_map + malloc + * 2 => apprentice_map + mmap */ /*@relnull@*/ struct mlist *next; /*@relnull@*/ diff --git a/file/src/print.c b/file/src/print.c index 6a18b8b..9954ff9 100644 --- a/file/src/print.c +++ b/file/src/print.c @@ -65,7 +65,7 @@ mdump(struct magic *m) /* Note: type is unsigned */ (m->in_type < SZOF(typ)) ? typ[m->in_type] : "*bad*"); - if (m->in_op & OPINVERSE) + if (m->in_op & FILE_OPINVERSE) (void) fputc('~', stderr); (void) fprintf(stderr, "%c%d),", ((m->in_op&0x7F) < SZOF(optyp)) ? @@ -75,13 +75,13 @@ mdump(struct magic *m) (void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "", /* Note: type is unsigned */ (m->type < SZOF(typ)) ? typ[m->type] : "*bad*"); - if (m->mask_op & OPINVERSE) + if (m->mask_op & FILE_OPINVERSE) (void) fputc('~', stderr); if (m->mask) { ((m->mask_op&0x7F) < SZOF(optyp)) ? (void) fputc(optyp[m->mask_op&0x7F], stderr) : (void) fputc('?', stderr); - if(STRING != m->type || PSTRING != m->type) + if (FILE_STRING != m->type || FILE_PSTRING != m->type) (void) fprintf(stderr, "%.8x", m->mask); else { if (m->mask & STRING_IGNORE_LOWERCASE) @@ -98,28 +98,28 @@ mdump(struct magic *m) if (m->reln != 'x') { switch (m->type) { - case BYTE: - case SHORT: - case LONG: - case LESHORT: - case LELONG: - case BESHORT: - case BELONG: + case FILE_BYTE: + case FILE_SHORT: + case FILE_LONG: + case FILE_LESHORT: + case FILE_LELONG: + case FILE_BESHORT: + case FILE_BELONG: (void) fprintf(stderr, "%d", m->value.l); break; - case STRING: - case PSTRING: - case REGEX: + case FILE_STRING: + case FILE_PSTRING: + case FILE_REGEX: showstr(stderr, m->value.s, -1); break; - case DATE: - case LEDATE: - case BEDATE: + case FILE_DATE: + case FILE_LEDATE: + case FILE_BEDATE: (void)fprintf(stderr, "%s,", fmttime(m->value.l, 1)); break; - case LDATE: - case LELDATE: - case BELDATE: + case FILE_LDATE: + case FILE_LELDATE: + case FILE_BELDATE: (void)fprintf(stderr, "%s,", fmttime(m->value.l, 0)); break; default: diff --git a/file/src/softmagic.c b/file/src/softmagic.c index 9a42076..220d506 100644 --- a/file/src/softmagic.c +++ b/file/src/softmagic.c @@ -44,7 +44,7 @@ fmagicSPrint(const fmagic fm, struct magic *m) int32_t t = 0; switch (m->type) { - case BYTE: + case FILE_BYTE: v = signextend(m, p->b); fmagicPrintf(fm, m->desc, (unsigned char) v); /*@-sizeoftype@*/ @@ -52,9 +52,9 @@ fmagicSPrint(const fmagic fm, struct magic *m) /*@=sizeoftype@*/ break; - case SHORT: - case BESHORT: - case LESHORT: + case FILE_SHORT: + case FILE_BESHORT: + case FILE_LESHORT: v = signextend(m, p->h); fmagicPrintf(fm, m->desc, (unsigned short) v); /*@-sizeoftype@*/ @@ -62,9 +62,9 @@ fmagicSPrint(const fmagic fm, struct magic *m) /*@=sizeoftype@*/ break; - case LONG: - case BELONG: - case LELONG: + case FILE_LONG: + case FILE_BELONG: + case FILE_LELONG: v = signextend(m, p->l); fmagicPrintf(fm, m->desc, (uint32_t) v); /*@-sizeoftype@*/ @@ -72,8 +72,8 @@ fmagicSPrint(const fmagic fm, struct magic *m) /*@=sizeoftype@*/ break; - case STRING: - case PSTRING: + case FILE_STRING: + case FILE_PSTRING: if (m->reln == '=') { fmagicPrintf(fm, m->desc, m->value.s); t = m->offset + strlen(m->value.s); @@ -88,25 +88,25 @@ fmagicSPrint(const fmagic fm, struct magic *m) } break; - case DATE: - case BEDATE: - case LEDATE: + case FILE_DATE: + case FILE_BEDATE: + case FILE_LEDATE: fmagicPrintf(fm, m->desc, fmttime(p->l, 1)); /*@-sizeoftype@*/ t = m->offset + sizeof(time_t); /*@=sizeoftype@*/ break; - case LDATE: - case BELDATE: - case LELDATE: + case FILE_LDATE: + case FILE_BELDATE: + case FILE_LELDATE: fmagicPrintf(fm, m->desc, fmttime(p->l, 0)); /*@-sizeoftype@*/ t = m->offset + sizeof(time_t); /*@=sizeoftype@*/ break; - case REGEX: + case FILE_REGEX: fmagicPrintf(fm, m->desc, p->s); t = m->offset + strlen(p->s); break; @@ -133,102 +133,102 @@ fmagicSConvert(fmagic fm, struct magic *m) union VALUETYPE * p = &fm->val; switch (m->type) { - case BYTE: + case FILE_BYTE: if (m->mask) switch (m->mask_op&0x7F) { - case OPAND: + case FILE_OPAND: p->b &= m->mask; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: p->b |= m->mask; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: p->b ^= m->mask; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: p->b += m->mask; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: p->b -= m->mask; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: p->b *= m->mask; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: p->b /= m->mask; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: p->b %= m->mask; /*@innerbreak@*/ break; } - if (m->mask_op & OPINVERSE) + if (m->mask_op & FILE_OPINVERSE) p->b = ~p->b; return 1; - case SHORT: + case FILE_SHORT: if (m->mask) switch (m->mask_op&0x7F) { - case OPAND: + case FILE_OPAND: p->h &= m->mask; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: p->h |= m->mask; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: p->h ^= m->mask; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: p->h += m->mask; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: p->h -= m->mask; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: p->h *= m->mask; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: p->h /= m->mask; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: p->h %= m->mask; /*@innerbreak@*/ break; } - if (m->mask_op & OPINVERSE) + if (m->mask_op & FILE_OPINVERSE) p->h = ~p->h; return 1; - case LONG: - case DATE: - case LDATE: + case FILE_LONG: + case FILE_DATE: + case FILE_LDATE: if (m->mask) switch (m->mask_op&0x7F) { - case OPAND: + case FILE_OPAND: p->l &= m->mask; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: p->l |= m->mask; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: p->l ^= m->mask; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: p->l += m->mask; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: p->l -= m->mask; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: p->l *= m->mask; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: p->l /= m->mask; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: p->l %= m->mask; /*@innerbreak@*/ break; } - if (m->mask_op & OPINVERSE) + if (m->mask_op & FILE_OPINVERSE) p->l = ~p->l; return 1; - case STRING: + case FILE_STRING: { int n; @@ -239,7 +239,7 @@ fmagicSConvert(fmagic fm, struct magic *m) p->s[n] = '\0'; return 1; } - case PSTRING: + case FILE_PSTRING: { char *ptr1 = p->s, *ptr2 = ptr1 + 1; int n = *p->s; @@ -253,141 +253,141 @@ fmagicSConvert(fmagic fm, struct magic *m) p->s[n] = '\0'; return 1; } - case BESHORT: + case FILE_BESHORT: p->h = (short)((p->hs[0]<<8)|(p->hs[1])); if (m->mask) switch (m->mask_op&0x7F) { - case OPAND: + case FILE_OPAND: p->h &= m->mask; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: p->h |= m->mask; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: p->h ^= m->mask; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: p->h += m->mask; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: p->h -= m->mask; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: p->h *= m->mask; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: p->h /= m->mask; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: p->h %= m->mask; /*@innerbreak@*/ break; } - if (m->mask_op & OPINVERSE) + if (m->mask_op & FILE_OPINVERSE) p->h = ~p->h; return 1; - case BELONG: - case BEDATE: - case BELDATE: + case FILE_BELONG: + case FILE_BEDATE: + case FILE_BELDATE: p->l = (int32_t) ((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3])); if (m->mask) switch (m->mask_op&0x7F) { - case OPAND: + case FILE_OPAND: p->l &= m->mask; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: p->l |= m->mask; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: p->l ^= m->mask; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: p->l += m->mask; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: p->l -= m->mask; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: p->l *= m->mask; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: p->l /= m->mask; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: p->l %= m->mask; /*@innerbreak@*/ break; } - if (m->mask_op & OPINVERSE) + if (m->mask_op & FILE_OPINVERSE) p->l = ~p->l; return 1; - case LESHORT: + case FILE_LESHORT: p->h = (short)((p->hs[1]<<8)|(p->hs[0])); if (m->mask) switch (m->mask_op&0x7F) { - case OPAND: + case FILE_OPAND: p->h &= m->mask; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: p->h |= m->mask; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: p->h ^= m->mask; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: p->h += m->mask; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: p->h -= m->mask; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: p->h *= m->mask; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: p->h /= m->mask; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: p->h %= m->mask; /*@innerbreak@*/ break; } - if (m->mask_op & OPINVERSE) + if (m->mask_op & FILE_OPINVERSE) p->h = ~p->h; return 1; - case LELONG: - case LEDATE: - case LELDATE: + case FILE_LELONG: + case FILE_LEDATE: + case FILE_LELDATE: p->l = (int32_t) ((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0])); if (m->mask) switch (m->mask_op&0x7F) { - case OPAND: + case FILE_OPAND: p->l &= m->mask; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: p->l |= m->mask; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: p->l ^= m->mask; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: p->l += m->mask; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: p->l -= m->mask; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: p->l *= m->mask; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: p->l /= m->mask; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: p->l %= m->mask; /*@innerbreak@*/ break; } - if (m->mask_op & OPINVERSE) + if (m->mask_op & FILE_OPINVERSE) p->l = ~p->l; return 1; - case REGEX: + case FILE_REGEX: return 1; default: error(EXIT_FAILURE, 0, "invalid type %d in fmagicSConvert().\n", m->type); @@ -421,7 +421,7 @@ fmagicSGet(fmagic fm, struct magic *m) int32_t offset = m->offset; /*@-branchstate@*/ - if (m->type == REGEX) { + if (m->type == FILE_REGEX) { /* * offset is interpreted as last line to search, * (starting at 1), not as bytes-from start-of-file @@ -455,265 +455,265 @@ fmagicSGet(fmagic fm, struct magic *m) if (m->flag & INDIR) { switch (m->in_type) { - case BYTE: + case FILE_BYTE: if (m->in_offset) switch (m->in_op&0x7F) { - case OPAND: + case FILE_OPAND: offset = p->b & m->in_offset; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: offset = p->b | m->in_offset; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: offset = p->b ^ m->in_offset; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: offset = p->b + m->in_offset; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: offset = p->b - m->in_offset; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: offset = p->b * m->in_offset; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: offset = p->b / m->in_offset; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: offset = p->b % m->in_offset; /*@innerbreak@*/ break; } - if (m->in_op & OPINVERSE) + if (m->in_op & FILE_OPINVERSE) offset = ~offset; break; - case BESHORT: + case FILE_BESHORT: if (m->in_offset) switch (m->in_op&0x7F) { - case OPAND: + case FILE_OPAND: offset = (short)((p->hs[0]<<8) | (p->hs[1])) & m->in_offset; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: offset = (short)((p->hs[0]<<8) | (p->hs[1])) | m->in_offset; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: offset = (short)((p->hs[0]<<8) | (p->hs[1])) ^ m->in_offset; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: offset = (short)((p->hs[0]<<8) | (p->hs[1])) + m->in_offset; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: offset = (short)((p->hs[0]<<8) | (p->hs[1])) - m->in_offset; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: offset = (short)((p->hs[0]<<8) | (p->hs[1])) * m->in_offset; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: offset = (short)((p->hs[0]<<8) | (p->hs[1])) / m->in_offset; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: offset = (short)((p->hs[0]<<8) | (p->hs[1])) % m->in_offset; /*@innerbreak@*/ break; } - if (m->in_op & OPINVERSE) + if (m->in_op & FILE_OPINVERSE) offset = ~offset; break; - case LESHORT: + case FILE_LESHORT: if (m->in_offset) switch (m->in_op&0x7F) { - case OPAND: + case FILE_OPAND: offset = (short)((p->hs[1]<<8) | (p->hs[0])) & m->in_offset; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: offset = (short)((p->hs[1]<<8) | (p->hs[0])) | m->in_offset; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: offset = (short)((p->hs[1]<<8) | (p->hs[0])) ^ m->in_offset; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: offset = (short)((p->hs[1]<<8) | (p->hs[0])) + m->in_offset; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: offset = (short)((p->hs[1]<<8) | (p->hs[0])) - m->in_offset; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: offset = (short)((p->hs[1]<<8) | (p->hs[0])) * m->in_offset; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: offset = (short)((p->hs[1]<<8) | (p->hs[0])) / m->in_offset; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: offset = (short)((p->hs[1]<<8) | (p->hs[0])) % m->in_offset; /*@innerbreak@*/ break; } - if (m->in_op & OPINVERSE) + if (m->in_op & FILE_OPINVERSE) offset = ~offset; break; - case SHORT: + case FILE_SHORT: if (m->in_offset) switch (m->in_op&0x7F) { - case OPAND: + case FILE_OPAND: offset = p->h & m->in_offset; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: offset = p->h | m->in_offset; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: offset = p->h ^ m->in_offset; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: offset = p->h + m->in_offset; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: offset = p->h - m->in_offset; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: offset = p->h * m->in_offset; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: offset = p->h / m->in_offset; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: offset = p->h % m->in_offset; /*@innerbreak@*/ break; } - if (m->in_op & OPINVERSE) + if (m->in_op & FILE_OPINVERSE) offset = ~offset; break; - case BELONG: + case FILE_BELONG: if (m->in_offset) switch (m->in_op&0x7F) { - case OPAND: + case FILE_OPAND: offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) | (p->hl[2]<< 8) | (p->hl[3])) & m->in_offset; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) | (p->hl[2]<< 8) | (p->hl[3])) | m->in_offset; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) | (p->hl[2]<< 8) | (p->hl[3])) ^ m->in_offset; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) | (p->hl[2]<< 8) | (p->hl[3])) + m->in_offset; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) | (p->hl[2]<< 8) | (p->hl[3])) - m->in_offset; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) | (p->hl[2]<< 8) | (p->hl[3])) * m->in_offset; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) | (p->hl[2]<< 8) | (p->hl[3])) / m->in_offset; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: offset = (int32_t)( (p->hl[0]<<24) | (p->hl[1]<<16) | (p->hl[2]<< 8) | (p->hl[3])) % m->in_offset; /*@innerbreak@*/ break; } - if (m->in_op & OPINVERSE) + if (m->in_op & FILE_OPINVERSE) offset = ~offset; break; - case LELONG: + case FILE_LELONG: if (m->in_offset) switch (m->in_op&0x7F) { - case OPAND: + case FILE_OPAND: offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) | (p->hl[1]<< 8) | (p->hl[0])) & m->in_offset; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) | (p->hl[1]<< 8) | (p->hl[0])) | m->in_offset; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) | (p->hl[1]<< 8) | (p->hl[0])) ^ m->in_offset; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) | (p->hl[1]<< 8) | (p->hl[0])) + m->in_offset; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) | (p->hl[1]<< 8) | (p->hl[0])) - m->in_offset; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) | (p->hl[1]<< 8) | (p->hl[0])) * m->in_offset; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) | (p->hl[1]<< 8) | (p->hl[0])) / m->in_offset; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: offset = (int32_t)( (p->hl[3]<<24) | (p->hl[2]<<16) | (p->hl[1]<< 8) | (p->hl[0])) % m->in_offset; /*@innerbreak@*/ break; } - if (m->in_op & OPINVERSE) + if (m->in_op & FILE_OPINVERSE) offset = ~offset; break; - case LONG: + case FILE_LONG: if (m->in_offset) switch (m->in_op&0x7F) { - case OPAND: + case FILE_OPAND: offset = p->l & m->in_offset; /*@innerbreak@*/ break; - case OPOR: + case FILE_OPOR: offset = p->l | m->in_offset; /*@innerbreak@*/ break; - case OPXOR: + case FILE_OPXOR: offset = p->l ^ m->in_offset; /*@innerbreak@*/ break; - case OPADD: + case FILE_OPADD: offset = p->l + m->in_offset; /*@innerbreak@*/ break; - case OPMINUS: + case FILE_OPMINUS: offset = p->l - m->in_offset; /*@innerbreak@*/ break; - case OPMULTIPLY: + case FILE_OPMULTIPLY: offset = p->l * m->in_offset; /*@innerbreak@*/ break; - case OPDIVIDE: + case FILE_OPDIVIDE: offset = p->l / m->in_offset; /*@innerbreak@*/ break; - case OPMODULO: + case FILE_OPMODULO: offset = p->l % m->in_offset; /*@innerbreak@*/ break; /* case TOOMANYSWITCHBLOCKS: @@ -724,7 +724,7 @@ fmagicSGet(fmagic fm, struct magic *m) * sleep; */ } - if (m->in_op & OPINVERSE) + if (m->in_op & FILE_OPINVERSE) offset = ~offset; break; } @@ -766,30 +766,30 @@ fmagicSCheck(const fmagic fm, struct magic *m) } switch (m->type) { - case BYTE: + case FILE_BYTE: v = p->b; break; - case SHORT: - case BESHORT: - case LESHORT: + case FILE_SHORT: + case FILE_BESHORT: + case FILE_LESHORT: v = p->h; break; - case LONG: - case BELONG: - case LELONG: - case DATE: - case BEDATE: - case LEDATE: - case LDATE: - case BELDATE: - case LELDATE: + case FILE_LONG: + case FILE_BELONG: + case FILE_LELONG: + case FILE_DATE: + case FILE_BEDATE: + case FILE_LEDATE: + case FILE_LDATE: + case FILE_BELDATE: + case FILE_LELDATE: v = p->l; break; - case STRING: - case PSTRING: + case FILE_STRING: + case FILE_PSTRING: { /* * What we want here is: @@ -834,7 +834,7 @@ fmagicSCheck(const fmagic fm, struct magic *m) } break; } - case REGEX: + case FILE_REGEX: { int rc; regex_t rx; @@ -857,7 +857,7 @@ fmagicSCheck(const fmagic fm, struct magic *m) return 0; } - if(m->type != STRING && m->type != PSTRING) + if(m->type != FILE_STRING && m->type != FILE_PSTRING) v = signextend(m, v); switch (m->reln) { diff --git a/file/src/system.h b/file/src/system.h new file mode 100644 index 0000000..7ea2793 --- /dev/null +++ b/file/src/system.h @@ -0,0 +1,326 @@ +#ifndef H_SYSTEM +#define H_SYSTEM +/*@-redef@*/ + +#ifndef __linux__ +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE +#define _FILE_OFFSET_BITS 64 +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#ifdef HAVE_SYS_PARAM_H +#include +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif + +#ifdef HAVE_STRING_H +# if !STDC_HEADERS && HAVE_MEMORY_H +# include +# endif +# include +#else +# include +char *memchr (); +#endif + +#include +#ifndef errno +/*@-declundef @*/ +extern int errno; +/*@=declundef @*/ +#endif + +#if defined(__LCLINT__) +/*@-declundef @*/ +/*@exits@*/ +extern void error(int status, int errnum, const char *format, ...) + __attribute__ ((__format__ (__printf__, 3, 4))) + /*@globals fileSystem @*/ + /*@modifies fileSystem @*/; +/*@=declundef @*/ +#else +#if HAVE_ERROR && HAVE_ERROR_H +#include +#endif +#endif + +#ifdef STDC_HEADERS +#include +#ifdef HAVE_STDINT_H +#include +#endif +#include +#else +#include +#endif /* STDC_HEADERS */ + +#if defined(__LCLINT__) +/*@-declundef@*/ +/*@-exportfcn@*/ +extern __const unsigned short int **__ctype_b_loc (void) + __attribute__ ((__const)) /*@*/; +extern __const __int32_t **__ctype_tolower_loc (void) + __attribute__ ((__const)) /*@*/; +extern __const __int32_t **__ctype_toupper_loc (void) + __attribute__ ((__const)) /*@*/; +/*@=exportfcn@*/ +/*@-exportvar@*/ +/*@unchecked@*/ +extern __const __int32_t *__ctype_tolower; +/*@unchecked@*/ +extern __const __int32_t *__ctype_toupper; +/*@=exportvar@*/ +/*@=declundef@*/ +#endif + +#include + +#if defined (__GLIBC__) && defined(__LCLINT__) +/*@-exportlocal@*/ +extern int isalnum(int) __THROW /*@*/; +extern int isalpha(int) __THROW /*@*/; +extern int isascii(int) __THROW /*@*/; +extern int iscntrl(int) __THROW /*@*/; +extern int isdigit(int) __THROW /*@*/; +extern int isgraph(int) __THROW /*@*/; +extern int islower(int) __THROW /*@*/; +extern int isprint(int) __THROW /*@*/; +extern int ispunct(int) __THROW /*@*/; +extern int isspace(int) __THROW /*@*/; +extern int isupper(int) __THROW /*@*/; +extern int isxdigit(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) && !defined(__LCLINT__) +#define EXIT_FAILURE 1 +#endif + +#ifdef HAVE_FCNTL_H +#include +#else +#include +#endif + +#if HAVE_SYS_WAIT_H +#include +#endif + +#if HAVE_SYS_MMAN_H && !defined(__LCLINT__) +#include +#endif + +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + +#ifdef RESTORE_TIME +# if (__COHERENT__ >= 0x420) +# include +# else +# ifdef USE_UTIMES +# include +# else +# include +# endif +# endif +#endif + +/* Since major is a function on SVR4, we can't use `ifndef major'. */ +#if MAJOR_IN_MKDEV +#include +#define HAVE_MAJOR +#endif +#if MAJOR_IN_SYSMACROS +#include +#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 +#if defined(__LCLINT__) +/*@-declundef -exportfcn @*/ +extern int getopt_long (int ___argc, char *const *___argv, + const char *__shortopts, const struct option *__longopts, + int * __longind) + /*@*/; +/*@=declundef =exportfcn @*/ +#endif +#include /* for long options (is this portable?)*/ +#endif + +#ifdef NEED_GETOPT +/*@unchecked@*/ +extern int optind; /* From getopt(3) */ +/*@unchecked@*/ +extern char *optarg; +#endif + +#if HAVE_REGEX_H +#include +#endif + +#ifdef HAVE_LIBZ +#include +#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 + +/*@-declundef -exportfcn -incondefs @*/ +/** + */ +/*@mayexit@*/ /*@only@*/ /*@out@*/ +void * xmalloc (size_t size) + /*@globals errno @*/ + /*@ensures maxSet(result) == (size - 1) @*/ + /*@modifies errno @*/; + +/** + */ +/*@mayexit@*/ /*@only@*/ +void * xcalloc (size_t nmemb, size_t size) + /*@ensures maxSet(result) == (nmemb - 1) @*/ + /*@*/; + +/** + * @todo Annotate ptr with returned/out. + */ +/*@mayexit@*/ /*@only@*/ +void * xrealloc (/*@null@*/ /*@only@*/ void * ptr, size_t size) + /*@ensures maxSet(result) == (size - 1) @*/ + /*@modifies *ptr @*/; + +/** + */ +/*@-fcnuse@*/ +/*@mayexit@*/ /*@only@*/ +char * xstrdup (const char *str) + /*@*/; +/*@=fcnuse@*/ +/*@=declundef =exportfcn=incondefs @*/ + +/** + */ +/*@-shadow@*/ +/*@unused@*/ /*@exits@*/ /*@only@*/ +static inline void * vmefail(/*@unused@*/ size_t nb) + /*@globals fileSystem @*/ + /*@modifies fileSystem @*/ +{ + error(EXIT_FAILURE, 0, "out of memory"); + /*@notreached@*/ +/*@-nullret@*/ + return NULL; +/*@=nullret@*/ +} +/*@=shadow@*/ + +#if HAVE_MCHECK_H +#include +#if defined(__LCLINT__) +/*@-declundef -incondefs @*/ /* LCL: missing annotations */ +extern int mcheck (void (*__abortfunc) (enum mcheck_status)) __THROW + /*@globals internalState@*/ + /*@modifies internalState @*/; +extern int mcheck_pedantic (void (*__abortfunc) (enum mcheck_status)) __THROW + /*@globals internalState@*/ + /*@modifies internalState @*/; +extern void mcheck_check_all (void) + /*@globals internalState@*/ + /*@modifies internalState @*/; +extern enum mcheck_status mprobe (void *__ptr) __THROW + /*@globals internalState@*/ + /*@modifies internalState @*/; +extern void mtrace (void) __THROW + /*@globals internalState@*/ + /*@modifies internalState @*/; +extern void muntrace (void) __THROW + /*@globals internalState@*/ + /*@modifies internalState @*/; +/*@=declundef =incondefs @*/ +#endif /* defined(__LCLINT__) */ +#endif /* HAVE_MCHECK_H */ + +#if !defined(__LCLINT__) +/* Memory allocation via macro defs to get meaningful locations from mtrace() */ +#define xmalloc(_size) (malloc(_size) ? : vmefail(0)) +#define xcalloc(_nmemb, _size) (calloc((_nmemb), (_size)) ? : vmefail(0)) +#define xrealloc(_ptr, _size) (realloc((_ptr), (_size)) ? : vmefail(0)) +#define xstrdup(_str) (strcpy(xmalloc(strlen(_str)+1), (_str))) +#endif + +/* Retrofit glibc __progname */ +#if defined __GLIBC__ && __GLIBC__ >= 2 +#if __GLIBC_MINOR__ >= 1 +#define __progname __assert_program_name +#endif +#define setprogname(pn) +#else +#define __progname program_name +#define setprogname(pn) \ + { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \ + else __progname = pn; \ + } +#endif +/*@unchecked@*/ +const char *__progname; + +#if HAVE_LOCALE_H +# include +#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 + +/*@=redef@*/ + +#endif /* H_SYSTEM */ -- 2.7.4