fi
done
+for ac_hdr in sys/mman.h
+do
+ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
+echo "configure:1561: checking for $ac_hdr" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1566 "configure"
+#include "confdefs.h"
+#include <$ac_hdr>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1571: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=yes"
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
+ cat >> confdefs.h <<EOF
+#define $ac_tr_hdr 1
+EOF
+
+else
+ echo "$ac_t""no" 1>&6
+fi
+done
+
echo $ac_n "checking for working const""... $ac_c" 1>&6
-echo "configure:1559: checking for working const" >&5
+echo "configure:1599: checking for working const" >&5
if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1564 "configure"
+#line 1604 "configure"
#include "confdefs.h"
int main() {
; return 0; }
EOF
-if { (eval echo configure:1613: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1653: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
ac_cv_c_const=yes
else
fi
echo $ac_n "checking for off_t""... $ac_c" 1>&6
-echo "configure:1634: checking for off_t" >&5
+echo "configure:1674: checking for off_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_off_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1639 "configure"
+#line 1679 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
fi
echo $ac_n "checking for size_t""... $ac_c" 1>&6
-echo "configure:1667: checking for size_t" >&5
+echo "configure:1707: checking for size_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1672 "configure"
+#line 1712 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
fi
echo $ac_n "checking for st_rdev in struct stat""... $ac_c" 1>&6
-echo "configure:1700: checking for st_rdev in struct stat" >&5
+echo "configure:1740: checking for st_rdev in struct stat" >&5
if eval "test \"`echo '$''{'ac_cv_struct_st_rdev'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1705 "configure"
+#line 1745 "configure"
#include "confdefs.h"
#include <sys/types.h>
#include <sys/stat.h>
struct stat s; s.st_rdev;
; return 0; }
EOF
-if { (eval echo configure:1713: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1753: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
ac_cv_struct_st_rdev=yes
else
echo $ac_n "checking for uint8_t""... $ac_c" 1>&6
-echo "configure:1735: checking for uint8_t" >&5
+echo "configure:1775: checking for uint8_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_uint8_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1740 "configure"
+#line 1780 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
fi
echo $ac_n "checking for uint16_t""... $ac_c" 1>&6
-echo "configure:1768: checking for uint16_t" >&5
+echo "configure:1808: checking for uint16_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_uint16_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1773 "configure"
+#line 1813 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
fi
echo $ac_n "checking for uint32_t""... $ac_c" 1>&6
-echo "configure:1801: checking for uint32_t" >&5
+echo "configure:1841: checking for uint32_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_uint32_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1806 "configure"
+#line 1846 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
echo $ac_n "checking for long long""... $ac_c" 1>&6
-echo "configure:1835: checking for long long" >&5
+echo "configure:1875: checking for long long" >&5
if eval "test \"`echo '$''{'ac_cv_c_long_long'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
{ echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
else
cat > conftest.$ac_ext <<EOF
-#line 1846 "configure"
+#line 1886 "configure"
#include "confdefs.h"
int main() {
long long foo = 0;
exit(sizeof(long long) < sizeof(long)); }
EOF
-if { (eval echo configure:1852: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1892: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_c_long_long=yes
else
long64='unsigned long';
fi
echo $ac_n "checking for uint64_t""... $ac_c" 1>&6
-echo "configure:1881: checking for uint64_t" >&5
+echo "configure:1921: checking for uint64_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_uint64_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1886 "configure"
+#line 1926 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
echo $ac_n "checking size of uint8_t""... $ac_c" 1>&6
-echo "configure:1917: checking size of uint8_t" >&5
+echo "configure:1957: checking size of uint8_t" >&5
if eval "test \"`echo '$''{'ac_cv_sizeof_uint8_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_cv_sizeof_uint8_t=0
else
cat > conftest.$ac_ext <<EOF
-#line 1925 "configure"
+#line 1965 "configure"
#include "confdefs.h"
#include <sys/types.h>
#ifdef STDC_HEADERS
exit(0);
}
EOF
-if { (eval echo configure:1941: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1981: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_sizeof_uint8_t=`cat conftestval`
else
echo $ac_n "checking size of uint16_t""... $ac_c" 1>&6
-echo "configure:1962: checking size of uint16_t" >&5
+echo "configure:2002: checking size of uint16_t" >&5
if eval "test \"`echo '$''{'ac_cv_sizeof_uint16_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_cv_sizeof_uint16_t=0
else
cat > conftest.$ac_ext <<EOF
-#line 1970 "configure"
+#line 2010 "configure"
#include "confdefs.h"
#include <sys/types.h>
#ifdef STDC_HEADERS
exit(0);
}
EOF
-if { (eval echo configure:1986: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:2026: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_sizeof_uint16_t=`cat conftestval`
else
echo $ac_n "checking size of uint32_t""... $ac_c" 1>&6
-echo "configure:2007: checking size of uint32_t" >&5
+echo "configure:2047: checking size of uint32_t" >&5
if eval "test \"`echo '$''{'ac_cv_sizeof_uint32_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_cv_sizeof_uint32_t=0
else
cat > conftest.$ac_ext <<EOF
-#line 2015 "configure"
+#line 2055 "configure"
#include "confdefs.h"
#include <sys/types.h>
#ifdef STDC_HEADERS
exit(0);
}
EOF
-if { (eval echo configure:2031: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:2071: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_sizeof_uint32_t=`cat conftestval`
else
echo $ac_n "checking size of uint64_t""... $ac_c" 1>&6
-echo "configure:2052: checking size of uint64_t" >&5
+echo "configure:2092: checking size of uint64_t" >&5
if eval "test \"`echo '$''{'ac_cv_sizeof_uint64_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_cv_sizeof_uint64_t=0
else
cat > conftest.$ac_ext <<EOF
-#line 2060 "configure"
+#line 2100 "configure"
#include "confdefs.h"
#include <sys/types.h>
#ifdef STDC_HEADERS
exit(0);
}
EOF
-if { (eval echo configure:2076: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:2116: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_sizeof_uint64_t=`cat conftestval`
else
-for ac_func in strerror strtoul
+for ac_func in mmap strerror strtoul
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2100: checking for $ac_func" >&5
+echo "configure:2140: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 2105 "configure"
+#line 2145 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:2128: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2168: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
* 4. This notice may not be removed or altered.
*/
+#include "file.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifdef QUICK
#include <fcntl.h>
+#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#endif
-#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: apprentice.c,v 1.39 2001/04/24 14:40:24 christos Exp $")
+FILE_RCSID("@(#)$Id: apprentice.c,v 1.40 2001/04/27 23:59:51 christos Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
static int apprentice_1 __P((const char *, int));
static int apprentice_file __P((struct magic **, uint32 *,
const char *, int));
-#ifdef QUICK
static void byteswap __P((struct magic *, uint32));
static void bs1 __P((struct magic *));
static uint16 swap2 __P((uint16));
static uint32 swap4 __P((uint32));
-static char * mkdbname __P((const char *));
+static char *mkdbname __P((const char *));
static int apprentice_map __P((struct magic **, uint32 *,
const char *, int));
static int apprentice_compile __P((struct magic **, uint32 *,
const char *, int));
-#endif
static int maxmagic = 0;
struct mlist *ml;
int rv = -1;
-#ifdef QUICK
if (action == COMPILE) {
rv = apprentice_file(&magic, &nmagic, fn, action);
if (rv == 0)
if ((rv = apprentice_map(&magic, &nmagic, fn, action)) != 0)
(void)fprintf(stderr, "%s: Using regular magic file `%s'\n",
progname, fn);
-#endif
if (rv != 0)
rv = apprentice_file(&magic, &nmagic, fn, action);
return rv;
if ((ml = malloc(sizeof(*ml))) == NULL) {
- (void) fprintf(stderr, "%s: Out of memory.\n", progname);
+ (void) fprintf(stderr, "%s: Out of memory (%s).\n", progname,
+ strerror(errno));
if (action == CHECK)
return -1;
}
mlist.next = mlist.prev = &mlist;
mfn = malloc(strlen(fn)+1);
if (mfn == NULL) {
- (void) fprintf(stderr, "%s: Out of memory.\n", progname);
+ (void) fprintf(stderr, "%s: Out of memory (%s).\n", progname,
+ strerror(errno));
if (action == CHECK)
return -1;
else
maxmagic = MAXMAGIS;
*magicp = (struct magic *) calloc(sizeof(struct magic), maxmagic);
if (*magicp == NULL) {
- (void) fprintf(stderr, "%s: Out of memory.\n", progname);
+ (void) fprintf(stderr, "%s: Out of memory (%s).\n", progname,
+ strerror(errno));
if (action == CHECK)
return -1;
}
maxmagic += ALLOC_INCR;
if ((m = (struct magic *) realloc(*magicp,
sizeof(struct magic) * maxmagic)) == NULL) {
- (void) fprintf(stderr, "%s: Out of memory.\n",
- progname);
+ (void) fprintf(stderr, "%s: Out of memory (%s).\n",
+ progname, strerror(errno));
if (*magicp)
free(*magicp);
if (action == CHECK)
*p = l;
}
-#ifdef QUICK
/*
* handle an mmaped file.
*/
int needsbyteswap;
char *dbname = mkdbname(fn);
+ if (dbname == NULL)
+ return -1;
+
if ((fd = open(dbname, O_RDONLY)) == -1)
return -1;
goto error;
}
+#ifdef QUICK
if ((*magicp = 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",
progname, dbname, strerror(errno));
goto error;
}
+#else
+ if ((*magicp = malloc((size_t)st.st_size)) == NULL) {
+ (void) fprintf(stderr, "%s: Out of memory (%s).\n", progname,
+ strerror(errno));
+ goto error;
+ }
+ if (read(fd, *magicp, (size_t)st.st_size) != (size_t)st.st_size) {
+ (void) fprintf(stderr, "%s: Read failed (%s).\n", progname,
+ strerror(errno));
+ goto error;
+ }
+#endif
(void)close(fd);
fd = -1;
ptr = (uint32 *) *magicp;
error:
if (fd != -1)
(void)close(fd);
- if (*magicp)
+ if (*magicp) {
+#ifdef QUICK
(void)munmap(*magicp, (size_t)st.st_size);
- else {
+#else
+ free(*magicp);
+#endif
+ } else {
*magicp = NULL;
*nmagicp = 0;
}
MAGICNO, VERSIONNO
};
+ if (dbname == NULL)
+ return -1;
+
if ((fd = open(dbname, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) {
(void)fprintf(stderr, "%s: Cannot open `%s' (%s)\n",
progname, dbname, strerror(errno));
buf = malloc(len);
else
buf = realloc(buf, len);
+ if (buf == NULL) {
+ (void) fprintf(stderr, "%s: Out of memory (%s).\n", progname,
+ strerror(errno));
+ return NULL;
+ }
(void)strcpy(buf, fn);
(void)strcat(buf, ext);
return buf;
m->value.l = swap4(m->value.l);
m->mask = swap4(m->mask);
}
-#endif