Deleted Added
full compact
apprentice.c (74784) apprentice.c (75937)
1/*
2 * apprentice - make one pass through /etc/magic, learning its secrets.
3 *
4 * Copyright (c) Ian F. Darwin, 1987.
5 * Written by Ian F. Darwin.
6 *
7 * This software is not subject to any license of the American Telephone
8 * and Telegraph Company or of the Regents of the University of California.

--- 24 unchanged lines hidden (view full) ---

33#ifdef QUICK
34#include <fcntl.h>
35#include <sys/stat.h>
36#include <sys/mman.h>
37#endif
38#include "file.h"
39
40#ifndef lint
1/*
2 * apprentice - make one pass through /etc/magic, learning its secrets.
3 *
4 * Copyright (c) Ian F. Darwin, 1987.
5 * Written by Ian F. Darwin.
6 *
7 * This software is not subject to any license of the American Telephone
8 * and Telegraph Company or of the Regents of the University of California.

--- 24 unchanged lines hidden (view full) ---

33#ifdef QUICK
34#include <fcntl.h>
35#include <sys/stat.h>
36#include <sys/mman.h>
37#endif
38#include "file.h"
39
40#ifndef lint
41FILE_RCSID("@(#)$Id: apprentice.c,v 1.34 2001/03/11 20:29:16 christos Exp $")
41FILE_RCSID("@(#)$Id: apprentice.c,v 1.39 2001/04/24 14:40:24 christos Exp $")
42#endif /* lint */
43
44#define EATAB {while (isascii((unsigned char) *l) && \
45 isspace((unsigned char) *l)) ++l;}
46#define LOWCASE(l) (isupper((unsigned char) (l)) ? \
47 tolower((unsigned char) (l)) : (l))
42#endif /* lint */
43
44#define EATAB {while (isascii((unsigned char) *l) && \
45 isspace((unsigned char) *l)) ++l;}
46#define LOWCASE(l) (isupper((unsigned char) (l)) ? \
47 tolower((unsigned char) (l)) : (l))
48/*
49 * Work around a bug in headers on Digital Unix.
50 * At least confirmed for: OSF1 V4.0 878
51 */
52#if defined(__osf__) && defined(__DECC)
53#ifdef MAP_FAILED
54#undef MAP_FAILED
55#endif
56#endif
48
57
58#ifndef MAP_FAILED
59#define MAP_FAILED (void *) -1
60#endif
49
61
62#ifndef MAP_FILE
63#define MAP_FILE 0
64#endif
65
50#ifdef __EMX__
51 char PATHSEP=';';
52#else
53 char PATHSEP=':';
54#endif
55
56
57static int getvalue __P((struct magic *, char **));

--- 735 unchanged lines hidden (view full) ---

793
794 if ((*magicp = mmap(0, (size_t)st.st_size, PROT_READ|PROT_WRITE,
795 MAP_PRIVATE|MAP_FILE, fd, (off_t)0)) == MAP_FAILED) {
796 (void)fprintf(stderr, "%s: Cannot map `%s' (%s)\n",
797 progname, dbname, strerror(errno));
798 goto error;
799 }
800 (void)close(fd);
66#ifdef __EMX__
67 char PATHSEP=';';
68#else
69 char PATHSEP=':';
70#endif
71
72
73static int getvalue __P((struct magic *, char **));

--- 735 unchanged lines hidden (view full) ---

809
810 if ((*magicp = mmap(0, (size_t)st.st_size, PROT_READ|PROT_WRITE,
811 MAP_PRIVATE|MAP_FILE, fd, (off_t)0)) == MAP_FAILED) {
812 (void)fprintf(stderr, "%s: Cannot map `%s' (%s)\n",
813 progname, dbname, strerror(errno));
814 goto error;
815 }
816 (void)close(fd);
817 fd = -1;
801 ptr = (uint32 *) *magicp;
802 if (*ptr != MAGICNO) {
803 if (swap4(*ptr) != MAGICNO) {
804 (void)fprintf(stderr, "%s: Bad magic in `%s'\n",
805 progname, dbname);
806 goto error;
807 }
808 needsbyteswap = 1;
809 } else
810 needsbyteswap = 0;
811 if (needsbyteswap)
812 version = swap4(ptr[1]);
813 else
814 version = ptr[1];
815 if (version != VERSIONNO) {
816 (void)fprintf(stderr,
817 "%s: version mismatch (%d != %d) in `%s'\n",
818 ptr = (uint32 *) *magicp;
819 if (*ptr != MAGICNO) {
820 if (swap4(*ptr) != MAGICNO) {
821 (void)fprintf(stderr, "%s: Bad magic in `%s'\n",
822 progname, dbname);
823 goto error;
824 }
825 needsbyteswap = 1;
826 } else
827 needsbyteswap = 0;
828 if (needsbyteswap)
829 version = swap4(ptr[1]);
830 else
831 version = ptr[1];
832 if (version != VERSIONNO) {
833 (void)fprintf(stderr,
834 "%s: version mismatch (%d != %d) in `%s'\n",
818 progname, version, VERSION, dbname);
835 progname, version, VERSIONNO, dbname);
819 goto error;
820 }
821 *nmagicp = (st.st_size / sizeof(struct magic)) - 1;
822 (*magicp)++;
823 if (needsbyteswap)
824 byteswap(*magicp, *nmagicp);
825 return 0;
826

--- 136 unchanged lines hidden ---
836 goto error;
837 }
838 *nmagicp = (st.st_size / sizeof(struct magic)) - 1;
839 (*magicp)++;
840 if (needsbyteswap)
841 byteswap(*magicp, *nmagicp);
842 return 0;
843

--- 136 unchanged lines hidden ---