12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28
29 /* Copyright (c) 1987, 1988 Microsoft Corporation */
30 /* All Rights Reserved */
31
32 #pragma ident "%Z%%M% %I% %E% SMI"
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <ctype.h>
38 #include <errno.h>
39 #include <limits.h>
40 #include <inttypes.h>
41 #include <sys/types.h>
42 #include <libintl.h>
43
44 /*
45 * Types
46 */
47
48 #define BYTE 1
49 #define SHORT 2
50 #define LONG 4
51 #define LLONG 8
52 #define UBYTE 16
53 #define USHORT 32
226 Entry *ep; /* current magic table entry */
227 Entry *mend; /* one past last-allocated entry of mtab */
228 FILE *fp;
229 int lcnt = 0;
230 char buf[BSZ];
231 size_t tbsize;
232 size_t oldsize;
233
234 if (first) {
235 mtab = mtab1;
236 mend = mend1;
237 ep = ep1;
238 } else {
239 mtab = mtab2;
240 mend = mend2;
241 ep = ep2;
242 }
243
244 /* mtab may have been allocated on a previous f_mkmtab call */
245 if (mtab == (Entry *)NULL) {
246 if ((mtab = calloc(sizeof (Entry), NENT)) == NULL) {
247 int err = errno;
248 (void) fprintf(stderr, gettext("%s: malloc "
249 "failed: %s\n"), File, strerror(err));
250 return (-1);
251 }
252
253 ep = mtab;
254 mend = &mtab[NENT];
255 }
256
257 errno = 0;
258 if ((fp = fopen(magfile, "r")) == NULL) {
259 int err = errno;
260 (void) fprintf(stderr, gettext("%s: %s: cannot open magic "
261 "file: %s\n"), File, magfile, err ? strerror(err) : "");
262 return (-1);
263 }
264 while (fgets(buf, BSZ, fp) != NULL) {
265 char *p = buf;
266 char *p2;
|
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28
29 /* Copyright (c) 1987, 1988 Microsoft Corporation */
30 /* All Rights Reserved */
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <ctype.h>
36 #include <errno.h>
37 #include <limits.h>
38 #include <inttypes.h>
39 #include <sys/types.h>
40 #include <libintl.h>
41
42 /*
43 * Types
44 */
45
46 #define BYTE 1
47 #define SHORT 2
48 #define LONG 4
49 #define LLONG 8
50 #define UBYTE 16
51 #define USHORT 32
224 Entry *ep; /* current magic table entry */
225 Entry *mend; /* one past last-allocated entry of mtab */
226 FILE *fp;
227 int lcnt = 0;
228 char buf[BSZ];
229 size_t tbsize;
230 size_t oldsize;
231
232 if (first) {
233 mtab = mtab1;
234 mend = mend1;
235 ep = ep1;
236 } else {
237 mtab = mtab2;
238 mend = mend2;
239 ep = ep2;
240 }
241
242 /* mtab may have been allocated on a previous f_mkmtab call */
243 if (mtab == (Entry *)NULL) {
244 if ((mtab = calloc(NENT, sizeof (Entry))) == NULL) {
245 int err = errno;
246 (void) fprintf(stderr, gettext("%s: malloc "
247 "failed: %s\n"), File, strerror(err));
248 return (-1);
249 }
250
251 ep = mtab;
252 mend = &mtab[NENT];
253 }
254
255 errno = 0;
256 if ((fp = fopen(magfile, "r")) == NULL) {
257 int err = errno;
258 (void) fprintf(stderr, gettext("%s: %s: cannot open magic "
259 "file: %s\n"), File, magfile, err ? strerror(err) : "");
260 return (-1);
261 }
262 while (fgets(buf, BSZ, fp) != NULL) {
263 char *p = buf;
264 char *p2;
|