17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
59a411307Srie * Common Development and Distribution License (the "License").
69a411307Srie * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
229a411307Srie * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate /* Copyright (c) 1987, 1988 Microsoft Corporation */
307c478bd9Sstevel@tonic-gate /* All Rights Reserved */
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include <stdio.h>
337c478bd9Sstevel@tonic-gate #include <stdlib.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <ctype.h>
367c478bd9Sstevel@tonic-gate #include <errno.h>
377c478bd9Sstevel@tonic-gate #include <limits.h>
387c478bd9Sstevel@tonic-gate #include <inttypes.h>
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate #include <libintl.h>
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate * Types
447c478bd9Sstevel@tonic-gate */
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate #define BYTE 1
477c478bd9Sstevel@tonic-gate #define SHORT 2
487c478bd9Sstevel@tonic-gate #define LONG 4
497c478bd9Sstevel@tonic-gate #define LLONG 8
507c478bd9Sstevel@tonic-gate #define UBYTE 16
517c478bd9Sstevel@tonic-gate #define USHORT 32
527c478bd9Sstevel@tonic-gate #define ULONG 64
537c478bd9Sstevel@tonic-gate #define ULLONG 128
547c478bd9Sstevel@tonic-gate #define STR 256
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate * Opcodes
587c478bd9Sstevel@tonic-gate */
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate #define EQ 0
617c478bd9Sstevel@tonic-gate #define GT 1
627c478bd9Sstevel@tonic-gate #define LT 2
637c478bd9Sstevel@tonic-gate #define STRC 3 /* string compare */
647c478bd9Sstevel@tonic-gate #define ANY 4
657c478bd9Sstevel@tonic-gate #define AND 5
667c478bd9Sstevel@tonic-gate #define NSET 6 /* True if bit is not set */
677c478bd9Sstevel@tonic-gate #define SUB 64 /* or'ed in, SUBstitution string, for example */
687c478bd9Sstevel@tonic-gate /* %ld, %s, %lo mask: with bit 6 on, used to locate */
697c478bd9Sstevel@tonic-gate /* print formats */
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate * Misc
727c478bd9Sstevel@tonic-gate */
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate #define BSZ 128
757c478bd9Sstevel@tonic-gate #define NENT 200
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate * Structure of magic file entry
797c478bd9Sstevel@tonic-gate */
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate struct entry {
827c478bd9Sstevel@tonic-gate char e_level; /* 0 or 1 */
837c478bd9Sstevel@tonic-gate off_t e_off; /* in bytes */
847c478bd9Sstevel@tonic-gate uint32_t e_type; /* BYTE, SHORT, STR, et al */
857c478bd9Sstevel@tonic-gate char e_opcode; /* EQ, GT, LT, ANY, AND, NSET */
867c478bd9Sstevel@tonic-gate uint64_t e_mask; /* if non-zero, mask value with this */
877c478bd9Sstevel@tonic-gate union {
887c478bd9Sstevel@tonic-gate uint64_t num;
897c478bd9Sstevel@tonic-gate char *str;
907c478bd9Sstevel@tonic-gate } e_value;
917c478bd9Sstevel@tonic-gate const char *e_str;
927c478bd9Sstevel@tonic-gate };
937c478bd9Sstevel@tonic-gate
949a411307Srie /* Non-localized string giving name of command. Defined in file.c */
959a411307Srie extern const char *File;
969a411307Srie
977c478bd9Sstevel@tonic-gate typedef struct entry Entry;
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate static Entry *mtab1; /* 1st magic table, applied before default tests */
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate * 2nd magic table, includes default tests and magic entries
1037c478bd9Sstevel@tonic-gate * to be applied after default position-sensitive tests
1047c478bd9Sstevel@tonic-gate */
1057c478bd9Sstevel@tonic-gate static Entry *mtab2;
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate static Entry *mend1; /* one past last-allocated entry in mtab1 */
1087c478bd9Sstevel@tonic-gate static Entry *mend2; /* one past last-allocated entry in mtab2 */
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate static Entry *ep1; /* current entry in mtab1 */
1117c478bd9Sstevel@tonic-gate static Entry *ep2; /* current entry in mtab2 */
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate static char *
getstr(char * p,char * file)1149a411307Srie getstr(char *p, char *file)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate char *newstr;
1177c478bd9Sstevel@tonic-gate char *s;
1187c478bd9Sstevel@tonic-gate long val;
1197c478bd9Sstevel@tonic-gate int base;
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate newstr = (char *)malloc((strlen(p) + 1) * sizeof (char));
1227c478bd9Sstevel@tonic-gate if (newstr == NULL) {
1239a411307Srie int err = errno;
1249a411307Srie (void) fprintf(stderr, gettext("%s: malloc failed: %s\n"),
1259a411307Srie File, strerror(err));
1267c478bd9Sstevel@tonic-gate return (NULL);
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate s = newstr;
1307c478bd9Sstevel@tonic-gate while (*p != '\0') {
1317c478bd9Sstevel@tonic-gate if (*p != '\\') {
1327c478bd9Sstevel@tonic-gate *s++ = *p++;
1337c478bd9Sstevel@tonic-gate continue;
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate p++;
1367c478bd9Sstevel@tonic-gate if (*p == '\0')
1377c478bd9Sstevel@tonic-gate break;
1387c478bd9Sstevel@tonic-gate if (isdigit(*p)) {
1397c478bd9Sstevel@tonic-gate if (*p == '0' && (*(p+1) == 'x' || *(p+1) == 'X')) {
1407c478bd9Sstevel@tonic-gate /* hex */
1417c478bd9Sstevel@tonic-gate base = 16;
1427c478bd9Sstevel@tonic-gate } else {
1437c478bd9Sstevel@tonic-gate base = 8;
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate errno = 0;
1467c478bd9Sstevel@tonic-gate val = strtol(p, &p, base);
1477c478bd9Sstevel@tonic-gate if (val > UCHAR_MAX || val < 0 || errno != 0) {
1489a411307Srie (void) fprintf(stderr, gettext("%s: %s: magic "
1499a411307Srie "table invalid string value\n"), File,
1509a411307Srie file);
1517c478bd9Sstevel@tonic-gate return (NULL);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate *s++ = (char)val;
1547c478bd9Sstevel@tonic-gate } else {
1557c478bd9Sstevel@tonic-gate /* escape the character */
1567c478bd9Sstevel@tonic-gate switch (*p) {
1577c478bd9Sstevel@tonic-gate case 'n':
1587c478bd9Sstevel@tonic-gate *s = '\n';
1597c478bd9Sstevel@tonic-gate break;
1607c478bd9Sstevel@tonic-gate case 'r':
1617c478bd9Sstevel@tonic-gate *s = '\r';
1627c478bd9Sstevel@tonic-gate break;
1637c478bd9Sstevel@tonic-gate case 'a':
1647c478bd9Sstevel@tonic-gate *s = '\a';
1657c478bd9Sstevel@tonic-gate break;
1667c478bd9Sstevel@tonic-gate case 'b':
1677c478bd9Sstevel@tonic-gate *s = '\b';
1687c478bd9Sstevel@tonic-gate break;
1697c478bd9Sstevel@tonic-gate case 'f':
1707c478bd9Sstevel@tonic-gate *s = '\f';
1717c478bd9Sstevel@tonic-gate break;
1727c478bd9Sstevel@tonic-gate case 't':
1737c478bd9Sstevel@tonic-gate *s = '\t';
1747c478bd9Sstevel@tonic-gate break;
1757c478bd9Sstevel@tonic-gate case 'v':
1767c478bd9Sstevel@tonic-gate *s = '\v';
1777c478bd9Sstevel@tonic-gate break;
1787c478bd9Sstevel@tonic-gate default:
1797c478bd9Sstevel@tonic-gate *s = *p;
1807c478bd9Sstevel@tonic-gate break;
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate p++;
1837c478bd9Sstevel@tonic-gate s++;
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate }
1867c478bd9Sstevel@tonic-gate *s = '\0';
1877c478bd9Sstevel@tonic-gate return (newstr);
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate /*
1917c478bd9Sstevel@tonic-gate * f_mkmtab - fills mtab array of magic table entries with
1927c478bd9Sstevel@tonic-gate * values from the file magfile.
1937c478bd9Sstevel@tonic-gate * May be called more than once if multiple magic
1947c478bd9Sstevel@tonic-gate * files were specified.
1957c478bd9Sstevel@tonic-gate * Stores entries sequentially in one of two magic
1967c478bd9Sstevel@tonic-gate * tables: mtab1, if first = 1; mtab2 otherwise.
1977c478bd9Sstevel@tonic-gate *
1987c478bd9Sstevel@tonic-gate * If -c option is specified, cflg is non-zero, and
1997c478bd9Sstevel@tonic-gate * f_mkmtab() reports on errors in the magic file.
2007c478bd9Sstevel@tonic-gate *
2017c478bd9Sstevel@tonic-gate * Two magic tables may need to be created. The first
2027c478bd9Sstevel@tonic-gate * one (mtab1) contains magic entries to be checked before
2037c478bd9Sstevel@tonic-gate * the programmatic default position-sensitive tests in
2047c478bd9Sstevel@tonic-gate * def_position_tests().
2057c478bd9Sstevel@tonic-gate * The second one (mtab2) should start with the default
2067c478bd9Sstevel@tonic-gate * /etc/magic file entries and is to be checked after
2077c478bd9Sstevel@tonic-gate * the programmatic default position-sensitive tests in
2087c478bd9Sstevel@tonic-gate * def_position_tests(). The parameter "first" would
2097c478bd9Sstevel@tonic-gate * be 1 for the former set of tables, 0 for the latter
2107c478bd9Sstevel@tonic-gate * set of magic tables.
2117c478bd9Sstevel@tonic-gate * No mtab2 should be created if file will not be
2127c478bd9Sstevel@tonic-gate * applying default tests; in that case, all magic table
2137c478bd9Sstevel@tonic-gate * entries should be in mtab1.
2147c478bd9Sstevel@tonic-gate *
2157c478bd9Sstevel@tonic-gate * f_mkmtab returns 0 on success, -1 on error. The calling
2167c478bd9Sstevel@tonic-gate * program is not expected to proceed after f_mkmtab()
2177c478bd9Sstevel@tonic-gate * returns an error.
2187c478bd9Sstevel@tonic-gate */
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate int
f_mkmtab(char * magfile,int cflg,int first)2217c478bd9Sstevel@tonic-gate f_mkmtab(char *magfile, int cflg, int first)
2227c478bd9Sstevel@tonic-gate {
2237c478bd9Sstevel@tonic-gate Entry *mtab; /* generic magic table pointer */
2247c478bd9Sstevel@tonic-gate Entry *ep; /* current magic table entry */
2257c478bd9Sstevel@tonic-gate Entry *mend; /* one past last-allocated entry of mtab */
2267c478bd9Sstevel@tonic-gate FILE *fp;
2277c478bd9Sstevel@tonic-gate int lcnt = 0;
2287c478bd9Sstevel@tonic-gate char buf[BSZ];
2297c478bd9Sstevel@tonic-gate size_t tbsize;
2307c478bd9Sstevel@tonic-gate size_t oldsize;
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate if (first) {
2337c478bd9Sstevel@tonic-gate mtab = mtab1;
2347c478bd9Sstevel@tonic-gate mend = mend1;
2357c478bd9Sstevel@tonic-gate ep = ep1;
2367c478bd9Sstevel@tonic-gate } else {
2377c478bd9Sstevel@tonic-gate mtab = mtab2;
2387c478bd9Sstevel@tonic-gate mend = mend2;
2397c478bd9Sstevel@tonic-gate ep = ep2;
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate /* mtab may have been allocated on a previous f_mkmtab call */
2437c478bd9Sstevel@tonic-gate if (mtab == (Entry *)NULL) {
2449b8f1941SRichard Lowe if ((mtab = calloc(NENT, sizeof (Entry))) == NULL) {
2459a411307Srie int err = errno;
2469a411307Srie (void) fprintf(stderr, gettext("%s: malloc "
2479a411307Srie "failed: %s\n"), File, strerror(err));
2487c478bd9Sstevel@tonic-gate return (-1);
2497c478bd9Sstevel@tonic-gate }
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gate ep = mtab;
2527c478bd9Sstevel@tonic-gate mend = &mtab[NENT];
2537c478bd9Sstevel@tonic-gate }
2547c478bd9Sstevel@tonic-gate
2559a411307Srie errno = 0;
2569a411307Srie if ((fp = fopen(magfile, "r")) == NULL) {
2579a411307Srie int err = errno;
2589a411307Srie (void) fprintf(stderr, gettext("%s: %s: cannot open magic "
2599a411307Srie "file: %s\n"), File, magfile, err ? strerror(err) : "");
2607c478bd9Sstevel@tonic-gate return (-1);
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate while (fgets(buf, BSZ, fp) != NULL) {
2637c478bd9Sstevel@tonic-gate char *p = buf;
2647c478bd9Sstevel@tonic-gate char *p2;
2657c478bd9Sstevel@tonic-gate char *p3;
2667c478bd9Sstevel@tonic-gate char opc;
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate /*
2697c478bd9Sstevel@tonic-gate * ensure we have one extra entry allocated
2707c478bd9Sstevel@tonic-gate * to mark end of the table, after the while loop
2717c478bd9Sstevel@tonic-gate */
2727c478bd9Sstevel@tonic-gate if (ep >= (mend - 1)) {
2737c478bd9Sstevel@tonic-gate oldsize = mend - mtab;
2747c478bd9Sstevel@tonic-gate tbsize = (NENT + oldsize) * sizeof (Entry);
2757c478bd9Sstevel@tonic-gate if ((mtab = realloc(mtab, tbsize)) == NULL) {
2769a411307Srie int err = errno;
2779a411307Srie (void) fprintf(stderr, gettext("%s: malloc "
2789a411307Srie "failed: %s\n"), File, strerror(err));
2797c478bd9Sstevel@tonic-gate return (-1);
2807c478bd9Sstevel@tonic-gate } else {
2817c478bd9Sstevel@tonic-gate (void) memset(mtab + oldsize, 0,
2827c478bd9Sstevel@tonic-gate sizeof (Entry) * NENT);
2837c478bd9Sstevel@tonic-gate mend = &mtab[tbsize / sizeof (Entry)];
2847c478bd9Sstevel@tonic-gate ep = &mtab[oldsize-1];
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate lcnt++;
2897c478bd9Sstevel@tonic-gate if (*p == '\n' || *p == '#')
2907c478bd9Sstevel@tonic-gate continue;
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate /* LEVEL */
2947c478bd9Sstevel@tonic-gate if (*p == '>') {
2957c478bd9Sstevel@tonic-gate ep->e_level = 1;
2967c478bd9Sstevel@tonic-gate p++;
2977c478bd9Sstevel@tonic-gate }
2987c478bd9Sstevel@tonic-gate /* OFFSET */
2997c478bd9Sstevel@tonic-gate p2 = strchr(p, '\t');
3007c478bd9Sstevel@tonic-gate if (p2 == NULL) {
3017c478bd9Sstevel@tonic-gate if (cflg)
3029a411307Srie (void) fprintf(stderr, gettext("%s: %s: format "
3039a411307Srie "error, no tab after %s on line %d\n"),
3049a411307Srie File, magfile, p, lcnt);
3057c478bd9Sstevel@tonic-gate continue;
3067c478bd9Sstevel@tonic-gate }
307*5521b763SToomas Soome *p2++ = '\0';
3087c478bd9Sstevel@tonic-gate ep->e_off = strtol((const char *)p, (char **)NULL, 0);
3097c478bd9Sstevel@tonic-gate while (*p2 == '\t')
3107c478bd9Sstevel@tonic-gate p2++;
3117c478bd9Sstevel@tonic-gate /* TYPE */
3127c478bd9Sstevel@tonic-gate p = p2;
3137c478bd9Sstevel@tonic-gate p2 = strchr(p, '\t');
3147c478bd9Sstevel@tonic-gate if (p2 == NULL) {
3157c478bd9Sstevel@tonic-gate if (cflg)
3169a411307Srie (void) fprintf(stderr, gettext("%s: %s: format "
3179a411307Srie "error, no tab after %s on line %d\n"),
3189a411307Srie File, magfile, p, lcnt);
3197c478bd9Sstevel@tonic-gate continue;
3207c478bd9Sstevel@tonic-gate }
321*5521b763SToomas Soome *p2++ = '\0';
3227c478bd9Sstevel@tonic-gate p3 = strchr(p, '&');
3237c478bd9Sstevel@tonic-gate if (p3 != NULL) {
3247c478bd9Sstevel@tonic-gate *p3++ = '\0';
3257c478bd9Sstevel@tonic-gate ep->e_mask = strtoull((const char *)p3, (char **)NULL,
3267c478bd9Sstevel@tonic-gate 0); /* returns 0 or ULLONG_MAX on error */
3277c478bd9Sstevel@tonic-gate } else {
3287c478bd9Sstevel@tonic-gate ep->e_mask = 0ULL;
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate switch (*p) {
3317c478bd9Sstevel@tonic-gate case 'd':
332*5521b763SToomas Soome if (*(p+1) == '\0') {
3337c478bd9Sstevel@tonic-gate /* d */
3347c478bd9Sstevel@tonic-gate ep->e_type = LONG;
335*5521b763SToomas Soome } else if (*(p+2) == '\0') { /* d? */
3367c478bd9Sstevel@tonic-gate switch (*(p+1)) {
3377c478bd9Sstevel@tonic-gate case 'C':
3387c478bd9Sstevel@tonic-gate case '1':
3397c478bd9Sstevel@tonic-gate /* dC, d1 */
3407c478bd9Sstevel@tonic-gate ep->e_type = BYTE;
3417c478bd9Sstevel@tonic-gate break;
3427c478bd9Sstevel@tonic-gate case 'S':
3437c478bd9Sstevel@tonic-gate case '2':
3447c478bd9Sstevel@tonic-gate /* dS, d2 */
3457c478bd9Sstevel@tonic-gate ep->e_type = SHORT;
3467c478bd9Sstevel@tonic-gate break;
3477c478bd9Sstevel@tonic-gate case 'I':
3487c478bd9Sstevel@tonic-gate case 'L':
3497c478bd9Sstevel@tonic-gate case '4':
3507c478bd9Sstevel@tonic-gate /* dI, dL, d4 */
3517c478bd9Sstevel@tonic-gate ep->e_type = LONG;
3527c478bd9Sstevel@tonic-gate break;
3537c478bd9Sstevel@tonic-gate case '8':
3547c478bd9Sstevel@tonic-gate /* d8 */
3557c478bd9Sstevel@tonic-gate ep->e_type = LLONG;
3567c478bd9Sstevel@tonic-gate break;
3577c478bd9Sstevel@tonic-gate default:
3587c478bd9Sstevel@tonic-gate ep->e_type = LONG;
3597c478bd9Sstevel@tonic-gate break;
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate }
3627c478bd9Sstevel@tonic-gate break;
3637c478bd9Sstevel@tonic-gate case 'l':
3647c478bd9Sstevel@tonic-gate if (*(p+1) == 'l') { /* llong */
3657c478bd9Sstevel@tonic-gate ep->e_type = LLONG;
3667c478bd9Sstevel@tonic-gate } else { /* long */
3677c478bd9Sstevel@tonic-gate ep->e_type = LONG;
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate break;
3707c478bd9Sstevel@tonic-gate case 's':
3717c478bd9Sstevel@tonic-gate if (*(p+1) == 'h') {
3727c478bd9Sstevel@tonic-gate /* short */
3737c478bd9Sstevel@tonic-gate ep->e_type = SHORT;
3747c478bd9Sstevel@tonic-gate } else {
3757c478bd9Sstevel@tonic-gate /* s or string */
3767c478bd9Sstevel@tonic-gate ep->e_type = STR;
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate break;
3797c478bd9Sstevel@tonic-gate case 'u':
380*5521b763SToomas Soome if (*(p+1) == '\0') {
3817c478bd9Sstevel@tonic-gate /* u */
3827c478bd9Sstevel@tonic-gate ep->e_type = ULONG;
383*5521b763SToomas Soome } else if (*(p+2) == '\0') { /* u? */
3847c478bd9Sstevel@tonic-gate switch (*(p+1)) {
3857c478bd9Sstevel@tonic-gate case 'C':
3867c478bd9Sstevel@tonic-gate case '1':
3877c478bd9Sstevel@tonic-gate /* uC, u1 */
3887c478bd9Sstevel@tonic-gate ep->e_type = UBYTE;
3897c478bd9Sstevel@tonic-gate break;
3907c478bd9Sstevel@tonic-gate case 'S':
3917c478bd9Sstevel@tonic-gate case '2':
3927c478bd9Sstevel@tonic-gate /* uS, u2 */
3937c478bd9Sstevel@tonic-gate ep->e_type = USHORT;
3947c478bd9Sstevel@tonic-gate break;
3957c478bd9Sstevel@tonic-gate case 'I':
3967c478bd9Sstevel@tonic-gate case 'L':
3977c478bd9Sstevel@tonic-gate case '4':
3987c478bd9Sstevel@tonic-gate /* uI, uL, u4 */
3997c478bd9Sstevel@tonic-gate ep->e_type = ULONG;
4007c478bd9Sstevel@tonic-gate break;
4017c478bd9Sstevel@tonic-gate case '8':
4027c478bd9Sstevel@tonic-gate /* u8 */
4037c478bd9Sstevel@tonic-gate ep->e_type = ULLONG;
4047c478bd9Sstevel@tonic-gate break;
4057c478bd9Sstevel@tonic-gate default:
4067c478bd9Sstevel@tonic-gate ep->e_type = ULONG;
4077c478bd9Sstevel@tonic-gate break;
4087c478bd9Sstevel@tonic-gate }
4097c478bd9Sstevel@tonic-gate } else { /* u?* */
4107c478bd9Sstevel@tonic-gate switch (*(p+1)) {
4117c478bd9Sstevel@tonic-gate case 'b': /* ubyte */
4127c478bd9Sstevel@tonic-gate ep->e_type = UBYTE;
4137c478bd9Sstevel@tonic-gate break;
4147c478bd9Sstevel@tonic-gate case 's': /* ushort */
4157c478bd9Sstevel@tonic-gate ep->e_type = USHORT;
4167c478bd9Sstevel@tonic-gate break;
4177c478bd9Sstevel@tonic-gate case 'l':
4187c478bd9Sstevel@tonic-gate if (*(p+2) == 'l') {
4197c478bd9Sstevel@tonic-gate /* ullong */
4207c478bd9Sstevel@tonic-gate ep->e_type = ULLONG;
4217c478bd9Sstevel@tonic-gate } else {
4227c478bd9Sstevel@tonic-gate /* ulong */
4237c478bd9Sstevel@tonic-gate ep->e_type = ULONG;
4247c478bd9Sstevel@tonic-gate }
4257c478bd9Sstevel@tonic-gate break;
4267c478bd9Sstevel@tonic-gate default:
4277c478bd9Sstevel@tonic-gate /* default, same as "u" */
4287c478bd9Sstevel@tonic-gate ep->e_type = ULONG;
4297c478bd9Sstevel@tonic-gate break;
4307c478bd9Sstevel@tonic-gate }
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate break;
4337c478bd9Sstevel@tonic-gate default:
4347c478bd9Sstevel@tonic-gate /* retain (undocumented) default type */
4357c478bd9Sstevel@tonic-gate ep->e_type = BYTE;
4367c478bd9Sstevel@tonic-gate break;
4377c478bd9Sstevel@tonic-gate }
4387c478bd9Sstevel@tonic-gate if (ep->e_type == 0) {
4397c478bd9Sstevel@tonic-gate ep->e_type = BYTE; /* default */
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate while (*p2 == '\t')
4427c478bd9Sstevel@tonic-gate p2++;
4437c478bd9Sstevel@tonic-gate /* OP-VALUE */
4447c478bd9Sstevel@tonic-gate p = p2;
4457c478bd9Sstevel@tonic-gate p2 = strchr(p, '\t');
4467c478bd9Sstevel@tonic-gate if (p2 == NULL) {
4477c478bd9Sstevel@tonic-gate if (cflg)
4489a411307Srie (void) fprintf(stderr, gettext("%s: %s: format "
4499a411307Srie "error, no tab after %s on line %d\n"),
4509a411307Srie File, magfile, p, lcnt);
4517c478bd9Sstevel@tonic-gate continue;
4527c478bd9Sstevel@tonic-gate }
453*5521b763SToomas Soome *p2++ = '\0';
4547c478bd9Sstevel@tonic-gate if (ep->e_type != STR) {
4557c478bd9Sstevel@tonic-gate opc = *p++;
4567c478bd9Sstevel@tonic-gate switch (opc) {
4577c478bd9Sstevel@tonic-gate case '=':
4587c478bd9Sstevel@tonic-gate ep->e_opcode = EQ;
4597c478bd9Sstevel@tonic-gate break;
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate case '>':
4627c478bd9Sstevel@tonic-gate ep->e_opcode = GT;
4637c478bd9Sstevel@tonic-gate break;
4647c478bd9Sstevel@tonic-gate
4657c478bd9Sstevel@tonic-gate case '<':
4667c478bd9Sstevel@tonic-gate ep->e_opcode = LT;
4677c478bd9Sstevel@tonic-gate break;
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate case 'x':
4707c478bd9Sstevel@tonic-gate ep->e_opcode = ANY;
4717c478bd9Sstevel@tonic-gate break;
4727c478bd9Sstevel@tonic-gate
4737c478bd9Sstevel@tonic-gate case '&':
4747c478bd9Sstevel@tonic-gate ep->e_opcode = AND;
4757c478bd9Sstevel@tonic-gate break;
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@tonic-gate case '^':
4787c478bd9Sstevel@tonic-gate ep->e_opcode = NSET;
4797c478bd9Sstevel@tonic-gate break;
4807c478bd9Sstevel@tonic-gate default: /* EQ (i.e. 0) is default */
4817c478bd9Sstevel@tonic-gate p--; /* since global ep->e_opcode=0 */
4827c478bd9Sstevel@tonic-gate }
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate if (ep->e_opcode != ANY) {
4857c478bd9Sstevel@tonic-gate if (ep->e_type != STR) {
4867c478bd9Sstevel@tonic-gate ep->e_value.num = strtoull((const char *)p,
4877c478bd9Sstevel@tonic-gate (char **)NULL, 0);
4889a411307Srie } else if ((ep->e_value.str =
4899a411307Srie getstr(p, magfile)) == NULL) {
4907c478bd9Sstevel@tonic-gate return (-1);
4917c478bd9Sstevel@tonic-gate }
4927c478bd9Sstevel@tonic-gate }
4937c478bd9Sstevel@tonic-gate p2 += strspn(p2, "\t");
4947c478bd9Sstevel@tonic-gate /* STRING */
4957c478bd9Sstevel@tonic-gate if ((ep->e_str = strdup(p2)) == NULL) {
4969a411307Srie int err = errno;
4979a411307Srie (void) fprintf(stderr, gettext("%s: malloc "
4989a411307Srie "failed: %s\n"), File, strerror(err));
4997c478bd9Sstevel@tonic-gate return (-1);
5007c478bd9Sstevel@tonic-gate } else {
5017c478bd9Sstevel@tonic-gate if ((p = strchr(ep->e_str, '\n')) != NULL)
5027c478bd9Sstevel@tonic-gate *p = '\0';
5037c478bd9Sstevel@tonic-gate if (strchr(ep->e_str, '%') != NULL)
5047c478bd9Sstevel@tonic-gate ep->e_opcode |= SUB;
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate ep++;
5077c478bd9Sstevel@tonic-gate } /* end while (fgets) */
5087c478bd9Sstevel@tonic-gate
5097c478bd9Sstevel@tonic-gate ep->e_off = -1L; /* mark end of table */
5107c478bd9Sstevel@tonic-gate if (first) {
5117c478bd9Sstevel@tonic-gate mtab1 = mtab;
5127c478bd9Sstevel@tonic-gate mend1 = mend;
5137c478bd9Sstevel@tonic-gate ep1 = ep;
5147c478bd9Sstevel@tonic-gate } else {
5157c478bd9Sstevel@tonic-gate mtab2 = mtab;
5167c478bd9Sstevel@tonic-gate mend2 = mend;
5177c478bd9Sstevel@tonic-gate ep2 = ep;
5187c478bd9Sstevel@tonic-gate }
5199a411307Srie if (fclose(fp) != 0) {
5209a411307Srie int err = errno;
5219a411307Srie (void) fprintf(stderr, gettext("%s: fclose failed: %s\n"),
5229a411307Srie File, strerror(err));
5237c478bd9Sstevel@tonic-gate return (-1);
5247c478bd9Sstevel@tonic-gate }
5257c478bd9Sstevel@tonic-gate return (0);
5267c478bd9Sstevel@tonic-gate }
5277c478bd9Sstevel@tonic-gate
5287c478bd9Sstevel@tonic-gate /*
5297c478bd9Sstevel@tonic-gate * Check for Magic Table entries in the file.
5307c478bd9Sstevel@tonic-gate *
5317c478bd9Sstevel@tonic-gate * Since there may be two sets of magic tables, first = 1
5327c478bd9Sstevel@tonic-gate * for the first magic table (mtab1) and 0 for the second magic
5337c478bd9Sstevel@tonic-gate * table (mtab2).
5347c478bd9Sstevel@tonic-gate */
5357c478bd9Sstevel@tonic-gate int
f_ckmtab(char * buf,int bufsize,int first)5367c478bd9Sstevel@tonic-gate f_ckmtab(char *buf, int bufsize, int first)
5377c478bd9Sstevel@tonic-gate {
5387c478bd9Sstevel@tonic-gate int result;
5397c478bd9Sstevel@tonic-gate Entry *mtab;
5407c478bd9Sstevel@tonic-gate Entry *ep;
5417c478bd9Sstevel@tonic-gate char *p;
5427c478bd9Sstevel@tonic-gate int lev1 = 0;
5437c478bd9Sstevel@tonic-gate
5447c478bd9Sstevel@tonic-gate uint16_t u16_val;
5457c478bd9Sstevel@tonic-gate uint32_t u32_val;
5467c478bd9Sstevel@tonic-gate uint64_t u64_val;
5477c478bd9Sstevel@tonic-gate
5487c478bd9Sstevel@tonic-gate if (first) {
5497c478bd9Sstevel@tonic-gate mtab = mtab1;
5507c478bd9Sstevel@tonic-gate } else {
5517c478bd9Sstevel@tonic-gate mtab = mtab2;
5527c478bd9Sstevel@tonic-gate }
5537c478bd9Sstevel@tonic-gate
5547c478bd9Sstevel@tonic-gate if (mtab == (Entry *)NULL) {
5557c478bd9Sstevel@tonic-gate return (0); /* no magic file tests in this table */
5567c478bd9Sstevel@tonic-gate }
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate for (ep = mtab; ep->e_off != -1L; ep++) { /* -1 offset marks end of */
5597c478bd9Sstevel@tonic-gate if (lev1) { /* valid magic file entries */
5607c478bd9Sstevel@tonic-gate if (ep->e_level != 1)
5617c478bd9Sstevel@tonic-gate break;
5627c478bd9Sstevel@tonic-gate } else if (ep->e_level == 1) {
5637c478bd9Sstevel@tonic-gate continue;
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate if (ep->e_off > (off_t)bufsize)
5667c478bd9Sstevel@tonic-gate continue;
5677c478bd9Sstevel@tonic-gate p = &buf[ep->e_off];
5687c478bd9Sstevel@tonic-gate switch (ep->e_type) {
5697c478bd9Sstevel@tonic-gate case STR:
5707c478bd9Sstevel@tonic-gate {
5717c478bd9Sstevel@tonic-gate if (strncmp(p, ep->e_value.str,
5727c478bd9Sstevel@tonic-gate strlen(ep->e_value.str)))
5737c478bd9Sstevel@tonic-gate continue;
5747c478bd9Sstevel@tonic-gate if (lev1) {
5757c478bd9Sstevel@tonic-gate (void) putchar(' ');
5767c478bd9Sstevel@tonic-gate }
5777c478bd9Sstevel@tonic-gate if (ep->e_opcode & SUB)
5787c478bd9Sstevel@tonic-gate (void) printf(ep->e_str,
5797c478bd9Sstevel@tonic-gate ep->e_value.str);
5807c478bd9Sstevel@tonic-gate else
5817c478bd9Sstevel@tonic-gate (void) printf(ep->e_str);
5827c478bd9Sstevel@tonic-gate lev1 = 1;
5837c478bd9Sstevel@tonic-gate continue;
5847c478bd9Sstevel@tonic-gate /*
5857c478bd9Sstevel@tonic-gate * We've matched the string and printed the message;
5867c478bd9Sstevel@tonic-gate * no STR processing occurs beyond this point.
5877c478bd9Sstevel@tonic-gate */
5887c478bd9Sstevel@tonic-gate }
5897c478bd9Sstevel@tonic-gate
5907c478bd9Sstevel@tonic-gate case BYTE:
5917c478bd9Sstevel@tonic-gate case UBYTE:
5927c478bd9Sstevel@tonic-gate u64_val = (uint64_t)(uint8_t)(*p);
5937c478bd9Sstevel@tonic-gate break;
5947c478bd9Sstevel@tonic-gate
5957c478bd9Sstevel@tonic-gate case SHORT:
5967c478bd9Sstevel@tonic-gate case USHORT:
5977c478bd9Sstevel@tonic-gate (void) memcpy(&u16_val, p, sizeof (uint16_t));
5987c478bd9Sstevel@tonic-gate u64_val = (uint64_t)u16_val;
5997c478bd9Sstevel@tonic-gate break;
6007c478bd9Sstevel@tonic-gate
6017c478bd9Sstevel@tonic-gate case LONG:
6027c478bd9Sstevel@tonic-gate case ULONG:
6037c478bd9Sstevel@tonic-gate (void) memcpy(&u32_val, p, sizeof (uint32_t));
6047c478bd9Sstevel@tonic-gate u64_val = (uint64_t)u32_val;
6057c478bd9Sstevel@tonic-gate break;
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate case LLONG:
6087c478bd9Sstevel@tonic-gate case ULLONG:
6097c478bd9Sstevel@tonic-gate (void) memcpy(&(u64_val), p, sizeof (uint64_t));
6107c478bd9Sstevel@tonic-gate break;
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gate }
6137c478bd9Sstevel@tonic-gate
6147c478bd9Sstevel@tonic-gate if (ep->e_mask) {
6157c478bd9Sstevel@tonic-gate u64_val &= ep->e_mask;
6167c478bd9Sstevel@tonic-gate }
6177c478bd9Sstevel@tonic-gate
6187c478bd9Sstevel@tonic-gate /*
6197c478bd9Sstevel@tonic-gate * Compare the values according to the size and sign
6207c478bd9Sstevel@tonic-gate * of the type. For =, &, and ^ operators, the sign
6217c478bd9Sstevel@tonic-gate * does not have any effect, so these are always compared
6227c478bd9Sstevel@tonic-gate * unsigned. Only for < and > operators is the
6237c478bd9Sstevel@tonic-gate * sign significant.
6247c478bd9Sstevel@tonic-gate * If the file value was masked, the compare should
6257c478bd9Sstevel@tonic-gate * be unsigned.
6267c478bd9Sstevel@tonic-gate */
6277c478bd9Sstevel@tonic-gate switch (ep->e_opcode & ~SUB) {
6287c478bd9Sstevel@tonic-gate case EQ:
6297c478bd9Sstevel@tonic-gate switch (ep->e_type) {
6307c478bd9Sstevel@tonic-gate case BYTE:
6317c478bd9Sstevel@tonic-gate case UBYTE:
6327c478bd9Sstevel@tonic-gate if ((uint8_t)u64_val !=
6337c478bd9Sstevel@tonic-gate (uint8_t)(ep->e_value.num))
6347c478bd9Sstevel@tonic-gate continue;
6357c478bd9Sstevel@tonic-gate break;
6367c478bd9Sstevel@tonic-gate case SHORT:
6377c478bd9Sstevel@tonic-gate case USHORT:
6387c478bd9Sstevel@tonic-gate if ((uint16_t)u64_val !=
6397c478bd9Sstevel@tonic-gate (uint16_t)(ep->e_value.num))
6407c478bd9Sstevel@tonic-gate continue;
6417c478bd9Sstevel@tonic-gate break;
6427c478bd9Sstevel@tonic-gate case LONG:
6437c478bd9Sstevel@tonic-gate case ULONG:
6447c478bd9Sstevel@tonic-gate if ((uint32_t)u64_val !=
6457c478bd9Sstevel@tonic-gate (uint32_t)(ep->e_value.num))
6467c478bd9Sstevel@tonic-gate continue;
6477c478bd9Sstevel@tonic-gate break;
6487c478bd9Sstevel@tonic-gate case LLONG:
6497c478bd9Sstevel@tonic-gate case ULLONG:
6507c478bd9Sstevel@tonic-gate if (u64_val != ep->e_value.num)
6517c478bd9Sstevel@tonic-gate continue;
6527c478bd9Sstevel@tonic-gate break;
6537c478bd9Sstevel@tonic-gate default:
6547c478bd9Sstevel@tonic-gate continue;
6557c478bd9Sstevel@tonic-gate }
6567c478bd9Sstevel@tonic-gate break;
6577c478bd9Sstevel@tonic-gate case GT:
6587c478bd9Sstevel@tonic-gate switch (ep->e_type) {
6597c478bd9Sstevel@tonic-gate case BYTE:
6607c478bd9Sstevel@tonic-gate if (ep->e_mask == 0) {
6617c478bd9Sstevel@tonic-gate if ((int8_t)u64_val <=
6627c478bd9Sstevel@tonic-gate (int8_t)(ep->e_value.num))
6637c478bd9Sstevel@tonic-gate continue;
6647c478bd9Sstevel@tonic-gate break;
6657c478bd9Sstevel@tonic-gate }
6667c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
6677c478bd9Sstevel@tonic-gate case UBYTE:
6687c478bd9Sstevel@tonic-gate if ((uint8_t)u64_val <=
6697c478bd9Sstevel@tonic-gate (uint8_t)(ep->e_value.num))
6707c478bd9Sstevel@tonic-gate continue;
6717c478bd9Sstevel@tonic-gate break;
6727c478bd9Sstevel@tonic-gate case SHORT:
6737c478bd9Sstevel@tonic-gate if (ep->e_mask == 0) {
6747c478bd9Sstevel@tonic-gate if ((int16_t)u64_val <=
6757c478bd9Sstevel@tonic-gate (int16_t)(ep->e_value.num))
6767c478bd9Sstevel@tonic-gate continue;
6777c478bd9Sstevel@tonic-gate break;
6787c478bd9Sstevel@tonic-gate }
6797c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
6807c478bd9Sstevel@tonic-gate case USHORT:
6817c478bd9Sstevel@tonic-gate if ((uint16_t)u64_val <=
6827c478bd9Sstevel@tonic-gate (uint16_t)(ep->e_value.num))
6837c478bd9Sstevel@tonic-gate continue;
6847c478bd9Sstevel@tonic-gate break;
6857c478bd9Sstevel@tonic-gate case LONG:
6867c478bd9Sstevel@tonic-gate if (ep->e_mask == 0) {
6877c478bd9Sstevel@tonic-gate if ((int32_t)u64_val <=
6887c478bd9Sstevel@tonic-gate (int32_t)(ep->e_value.num))
6897c478bd9Sstevel@tonic-gate continue;
6907c478bd9Sstevel@tonic-gate break;
6917c478bd9Sstevel@tonic-gate }
6927c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
6937c478bd9Sstevel@tonic-gate case ULONG:
6947c478bd9Sstevel@tonic-gate if ((uint32_t)u64_val <=
6957c478bd9Sstevel@tonic-gate (uint32_t)(ep->e_value.num))
6967c478bd9Sstevel@tonic-gate continue;
6977c478bd9Sstevel@tonic-gate break;
6987c478bd9Sstevel@tonic-gate case LLONG:
6997c478bd9Sstevel@tonic-gate if (ep->e_mask == 0) {
7007c478bd9Sstevel@tonic-gate if ((int64_t)u64_val <=
7017c478bd9Sstevel@tonic-gate (int64_t)(ep->e_value.num))
7027c478bd9Sstevel@tonic-gate continue;
7037c478bd9Sstevel@tonic-gate break;
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
7067c478bd9Sstevel@tonic-gate case ULLONG:
7077c478bd9Sstevel@tonic-gate if (u64_val <= ep->e_value.num)
7087c478bd9Sstevel@tonic-gate continue;
7097c478bd9Sstevel@tonic-gate break;
7107c478bd9Sstevel@tonic-gate default:
7117c478bd9Sstevel@tonic-gate continue;
7127c478bd9Sstevel@tonic-gate }
7137c478bd9Sstevel@tonic-gate break;
7147c478bd9Sstevel@tonic-gate case LT:
7157c478bd9Sstevel@tonic-gate switch (ep->e_type) {
7167c478bd9Sstevel@tonic-gate case BYTE:
7177c478bd9Sstevel@tonic-gate if (ep->e_mask == 0) {
7187c478bd9Sstevel@tonic-gate if ((int8_t)u64_val >=
7197c478bd9Sstevel@tonic-gate (int8_t)(ep->e_value.num))
7207c478bd9Sstevel@tonic-gate continue;
7217c478bd9Sstevel@tonic-gate break;
7227c478bd9Sstevel@tonic-gate }
7237c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
7247c478bd9Sstevel@tonic-gate case UBYTE:
7257c478bd9Sstevel@tonic-gate if ((uint8_t)u64_val >=
7267c478bd9Sstevel@tonic-gate (uint8_t)(ep->e_value.num))
7277c478bd9Sstevel@tonic-gate continue;
7287c478bd9Sstevel@tonic-gate break;
7297c478bd9Sstevel@tonic-gate case SHORT:
7307c478bd9Sstevel@tonic-gate if (ep->e_mask == 0) {
7317c478bd9Sstevel@tonic-gate if ((int16_t)u64_val >=
7327c478bd9Sstevel@tonic-gate (int16_t)(ep->e_value.num))
7337c478bd9Sstevel@tonic-gate continue;
7347c478bd9Sstevel@tonic-gate break;
7357c478bd9Sstevel@tonic-gate }
7367c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
7377c478bd9Sstevel@tonic-gate case USHORT:
7387c478bd9Sstevel@tonic-gate if ((uint16_t)u64_val >=
7397c478bd9Sstevel@tonic-gate (uint16_t)(ep->e_value.num))
7407c478bd9Sstevel@tonic-gate continue;
7417c478bd9Sstevel@tonic-gate break;
7427c478bd9Sstevel@tonic-gate case LONG:
7437c478bd9Sstevel@tonic-gate if (ep->e_mask == 0) {
7447c478bd9Sstevel@tonic-gate if ((int32_t)u64_val >=
7457c478bd9Sstevel@tonic-gate (int32_t)(ep->e_value.num))
7467c478bd9Sstevel@tonic-gate continue;
7477c478bd9Sstevel@tonic-gate break;
7487c478bd9Sstevel@tonic-gate }
7497c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
7507c478bd9Sstevel@tonic-gate case ULONG:
7517c478bd9Sstevel@tonic-gate if ((uint32_t)u64_val >=
7527c478bd9Sstevel@tonic-gate (uint32_t)(ep->e_value.num))
7537c478bd9Sstevel@tonic-gate continue;
7547c478bd9Sstevel@tonic-gate break;
7557c478bd9Sstevel@tonic-gate case LLONG:
7567c478bd9Sstevel@tonic-gate if (ep->e_mask == 0) {
7577c478bd9Sstevel@tonic-gate if ((int64_t)u64_val >=
7587c478bd9Sstevel@tonic-gate (int64_t)(ep->e_value.num))
7597c478bd9Sstevel@tonic-gate continue;
7607c478bd9Sstevel@tonic-gate break;
7617c478bd9Sstevel@tonic-gate }
7627c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
7637c478bd9Sstevel@tonic-gate case ULLONG:
7647c478bd9Sstevel@tonic-gate if (u64_val >= ep->e_value.num)
7657c478bd9Sstevel@tonic-gate continue;
7667c478bd9Sstevel@tonic-gate break;
7677c478bd9Sstevel@tonic-gate default:
7687c478bd9Sstevel@tonic-gate continue;
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate break;
7717c478bd9Sstevel@tonic-gate case AND:
7727c478bd9Sstevel@tonic-gate switch (ep->e_type) {
7737c478bd9Sstevel@tonic-gate case BYTE:
7747c478bd9Sstevel@tonic-gate case UBYTE:
7757c478bd9Sstevel@tonic-gate if (((uint8_t)u64_val &
7767c478bd9Sstevel@tonic-gate (uint8_t)(ep->e_value.num)) ==
7777c478bd9Sstevel@tonic-gate (uint8_t)(ep->e_value.num))
7787c478bd9Sstevel@tonic-gate break;
7797c478bd9Sstevel@tonic-gate continue;
7807c478bd9Sstevel@tonic-gate case SHORT:
7817c478bd9Sstevel@tonic-gate case USHORT:
7827c478bd9Sstevel@tonic-gate if (((uint16_t)u64_val &
7837c478bd9Sstevel@tonic-gate (uint16_t)(ep->e_value.num)) ==
7847c478bd9Sstevel@tonic-gate (uint16_t)(ep->e_value.num))
7857c478bd9Sstevel@tonic-gate break;
7867c478bd9Sstevel@tonic-gate continue;
7877c478bd9Sstevel@tonic-gate case LONG:
7887c478bd9Sstevel@tonic-gate case ULONG:
7897c478bd9Sstevel@tonic-gate if (((uint32_t)u64_val &
7907c478bd9Sstevel@tonic-gate (uint32_t)(ep->e_value.num)) ==
7917c478bd9Sstevel@tonic-gate (uint32_t)(ep->e_value.num))
7927c478bd9Sstevel@tonic-gate break;
7937c478bd9Sstevel@tonic-gate continue;
7947c478bd9Sstevel@tonic-gate case LLONG:
7957c478bd9Sstevel@tonic-gate case ULLONG:
7967c478bd9Sstevel@tonic-gate if ((u64_val & ep->e_value.num) ==
7977c478bd9Sstevel@tonic-gate ep->e_value.num)
7987c478bd9Sstevel@tonic-gate break;
7997c478bd9Sstevel@tonic-gate continue;
8007c478bd9Sstevel@tonic-gate default:
8017c478bd9Sstevel@tonic-gate continue;
8027c478bd9Sstevel@tonic-gate }
8037c478bd9Sstevel@tonic-gate break;
8047c478bd9Sstevel@tonic-gate case NSET:
8057c478bd9Sstevel@tonic-gate switch (ep->e_type) {
8067c478bd9Sstevel@tonic-gate case BYTE:
8077c478bd9Sstevel@tonic-gate case UBYTE:
8087c478bd9Sstevel@tonic-gate if (((uint8_t)u64_val &
8097c478bd9Sstevel@tonic-gate (uint8_t)(ep->e_value.num)) !=
8107c478bd9Sstevel@tonic-gate (uint8_t)(ep->e_value.num))
8117c478bd9Sstevel@tonic-gate break;
8127c478bd9Sstevel@tonic-gate continue;
8137c478bd9Sstevel@tonic-gate case SHORT:
8147c478bd9Sstevel@tonic-gate case USHORT:
8157c478bd9Sstevel@tonic-gate if (((uint16_t)u64_val &
8167c478bd9Sstevel@tonic-gate (uint16_t)(ep->e_value.num)) !=
8177c478bd9Sstevel@tonic-gate (uint16_t)(ep->e_value.num))
8187c478bd9Sstevel@tonic-gate break;
8197c478bd9Sstevel@tonic-gate continue;
8207c478bd9Sstevel@tonic-gate case LONG:
8217c478bd9Sstevel@tonic-gate case ULONG:
8227c478bd9Sstevel@tonic-gate if (((uint32_t)u64_val &
8237c478bd9Sstevel@tonic-gate (uint32_t)(ep->e_value.num)) !=
8247c478bd9Sstevel@tonic-gate (uint32_t)(ep->e_value.num))
8257c478bd9Sstevel@tonic-gate break;
8267c478bd9Sstevel@tonic-gate continue;
8277c478bd9Sstevel@tonic-gate case LLONG:
8287c478bd9Sstevel@tonic-gate case ULLONG:
8297c478bd9Sstevel@tonic-gate if ((u64_val & ep->e_value.num) !=
8307c478bd9Sstevel@tonic-gate ep->e_value.num)
8317c478bd9Sstevel@tonic-gate break;
8327c478bd9Sstevel@tonic-gate continue;
8337c478bd9Sstevel@tonic-gate default:
8347c478bd9Sstevel@tonic-gate continue;
8357c478bd9Sstevel@tonic-gate }
8367c478bd9Sstevel@tonic-gate break;
8377c478bd9Sstevel@tonic-gate case ANY: /* matches anything */
8387c478bd9Sstevel@tonic-gate break;
8397c478bd9Sstevel@tonic-gate default: /* shouldn't occur; ignore it */
8407c478bd9Sstevel@tonic-gate continue;
8417c478bd9Sstevel@tonic-gate }
8427c478bd9Sstevel@tonic-gate if (lev1)
8437c478bd9Sstevel@tonic-gate (void) putchar(' ');
8447c478bd9Sstevel@tonic-gate if (ep->e_opcode & SUB) {
8457c478bd9Sstevel@tonic-gate switch (ep->e_type) {
8467c478bd9Sstevel@tonic-gate case LLONG:
8477c478bd9Sstevel@tonic-gate #ifdef XPG4
8487c478bd9Sstevel@tonic-gate if (ep->e_mask == 0) {
8497c478bd9Sstevel@tonic-gate (void) printf(ep->e_str,
8507c478bd9Sstevel@tonic-gate (int64_t)u64_val);
8517c478bd9Sstevel@tonic-gate break;
8527c478bd9Sstevel@tonic-gate }
8537c478bd9Sstevel@tonic-gate #endif /* XPG4 */
8547c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
8557c478bd9Sstevel@tonic-gate case ULLONG:
8567c478bd9Sstevel@tonic-gate (void) printf(ep->e_str, u64_val);
8577c478bd9Sstevel@tonic-gate break;
8587c478bd9Sstevel@tonic-gate case LONG:
8597c478bd9Sstevel@tonic-gate #ifdef XPG4
8607c478bd9Sstevel@tonic-gate if (ep->e_mask == 0) {
8617c478bd9Sstevel@tonic-gate (void) printf(ep->e_str,
8627c478bd9Sstevel@tonic-gate (int32_t)u64_val);
8637c478bd9Sstevel@tonic-gate break;
8647c478bd9Sstevel@tonic-gate }
8657c478bd9Sstevel@tonic-gate #endif /* XPG4 */
8667c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
8677c478bd9Sstevel@tonic-gate case ULONG:
8687c478bd9Sstevel@tonic-gate (void) printf(ep->e_str,
8697c478bd9Sstevel@tonic-gate (uint32_t)u64_val);
8707c478bd9Sstevel@tonic-gate break;
8717c478bd9Sstevel@tonic-gate case SHORT:
8727c478bd9Sstevel@tonic-gate #ifdef XPG4
8737c478bd9Sstevel@tonic-gate if (ep->e_mask == 0) {
8747c478bd9Sstevel@tonic-gate (void) printf(ep->e_str,
8757c478bd9Sstevel@tonic-gate (int16_t)u64_val);
8767c478bd9Sstevel@tonic-gate break;
8777c478bd9Sstevel@tonic-gate }
8787c478bd9Sstevel@tonic-gate #endif /* XPG4 */
8797c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
8807c478bd9Sstevel@tonic-gate case USHORT:
8817c478bd9Sstevel@tonic-gate (void) printf(ep->e_str,
8827c478bd9Sstevel@tonic-gate (uint16_t)u64_val);
8837c478bd9Sstevel@tonic-gate break;
8847c478bd9Sstevel@tonic-gate case BYTE:
8857c478bd9Sstevel@tonic-gate #ifdef XPG4
8867c478bd9Sstevel@tonic-gate if (ep->e_mask == 0) {
8877c478bd9Sstevel@tonic-gate (void) printf(ep->e_str,
8887c478bd9Sstevel@tonic-gate (int8_t)u64_val);
8897c478bd9Sstevel@tonic-gate break;
8907c478bd9Sstevel@tonic-gate }
8917c478bd9Sstevel@tonic-gate #endif /* XPG4 */
8927c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
8937c478bd9Sstevel@tonic-gate case UBYTE:
8947c478bd9Sstevel@tonic-gate (void) printf(ep->e_str,
8957c478bd9Sstevel@tonic-gate (uint8_t)u64_val);
8967c478bd9Sstevel@tonic-gate break;
8977c478bd9Sstevel@tonic-gate case STR:
8987c478bd9Sstevel@tonic-gate /*
8997c478bd9Sstevel@tonic-gate * Note: Currently can't get type
9007c478bd9Sstevel@tonic-gate * STR here because we already
9017c478bd9Sstevel@tonic-gate * did a 'continue' out of the
9027c478bd9Sstevel@tonic-gate * loop earlier for case STR
9037c478bd9Sstevel@tonic-gate */
9047c478bd9Sstevel@tonic-gate break;
9057c478bd9Sstevel@tonic-gate }
9067c478bd9Sstevel@tonic-gate } else
9077c478bd9Sstevel@tonic-gate (void) printf(ep->e_str);
9087c478bd9Sstevel@tonic-gate lev1 = 1;
9097c478bd9Sstevel@tonic-gate }
9107c478bd9Sstevel@tonic-gate result = lev1 ? (int)(1 + ep - mtab) : 0;
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gate return (result);
9137c478bd9Sstevel@tonic-gate }
9147c478bd9Sstevel@tonic-gate
9157c478bd9Sstevel@tonic-gate static void
showstr(char * s,int width)9167c478bd9Sstevel@tonic-gate showstr(char *s, int width)
9177c478bd9Sstevel@tonic-gate {
9187c478bd9Sstevel@tonic-gate char c;
9197c478bd9Sstevel@tonic-gate
9207c478bd9Sstevel@tonic-gate while ((c = *s++) != '\0')
9217c478bd9Sstevel@tonic-gate if (c >= 040 && c < 0176) {
9227c478bd9Sstevel@tonic-gate (void) putchar(c);
9237c478bd9Sstevel@tonic-gate width--;
9247c478bd9Sstevel@tonic-gate } else {
9257c478bd9Sstevel@tonic-gate (void) putchar('\\');
9267c478bd9Sstevel@tonic-gate switch (c) {
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gate case '\n':
9297c478bd9Sstevel@tonic-gate (void) putchar('n');
9307c478bd9Sstevel@tonic-gate width -= 2;
9317c478bd9Sstevel@tonic-gate break;
9327c478bd9Sstevel@tonic-gate
9337c478bd9Sstevel@tonic-gate case '\r':
9347c478bd9Sstevel@tonic-gate (void) putchar('r');
9357c478bd9Sstevel@tonic-gate width -= 2;
9367c478bd9Sstevel@tonic-gate break;
9377c478bd9Sstevel@tonic-gate
9387c478bd9Sstevel@tonic-gate case '\a':
9397c478bd9Sstevel@tonic-gate (void) putchar('a');
9407c478bd9Sstevel@tonic-gate width -= 2;
9417c478bd9Sstevel@tonic-gate break;
9427c478bd9Sstevel@tonic-gate
9437c478bd9Sstevel@tonic-gate case '\b':
9447c478bd9Sstevel@tonic-gate (void) putchar('b');
9457c478bd9Sstevel@tonic-gate width -= 2;
9467c478bd9Sstevel@tonic-gate break;
9477c478bd9Sstevel@tonic-gate
9487c478bd9Sstevel@tonic-gate case '\t':
9497c478bd9Sstevel@tonic-gate (void) putchar('t');
9507c478bd9Sstevel@tonic-gate width -= 2;
9517c478bd9Sstevel@tonic-gate break;
9527c478bd9Sstevel@tonic-gate
9537c478bd9Sstevel@tonic-gate case '\f':
9547c478bd9Sstevel@tonic-gate (void) putchar('f');
9557c478bd9Sstevel@tonic-gate width -= 2;
9567c478bd9Sstevel@tonic-gate break;
9577c478bd9Sstevel@tonic-gate
9587c478bd9Sstevel@tonic-gate case '\v':
9597c478bd9Sstevel@tonic-gate (void) putchar('v');
9607c478bd9Sstevel@tonic-gate width -= 2;
9617c478bd9Sstevel@tonic-gate break;
9627c478bd9Sstevel@tonic-gate
9637c478bd9Sstevel@tonic-gate default:
9647c478bd9Sstevel@tonic-gate (void) printf("%.3o", c & 0377);
9657c478bd9Sstevel@tonic-gate width -= 4;
9667c478bd9Sstevel@tonic-gate break;
9677c478bd9Sstevel@tonic-gate }
9687c478bd9Sstevel@tonic-gate }
9697c478bd9Sstevel@tonic-gate while (width >= 0) {
9707c478bd9Sstevel@tonic-gate (void) putchar(' ');
9717c478bd9Sstevel@tonic-gate width--;
9727c478bd9Sstevel@tonic-gate };
9737c478bd9Sstevel@tonic-gate }
9747c478bd9Sstevel@tonic-gate
9757c478bd9Sstevel@tonic-gate static char *
type_to_name(Entry * ep)9767c478bd9Sstevel@tonic-gate type_to_name(Entry *ep)
9777c478bd9Sstevel@tonic-gate {
9787c478bd9Sstevel@tonic-gate static char buf[20];
9797c478bd9Sstevel@tonic-gate char *s;
9807c478bd9Sstevel@tonic-gate
9817c478bd9Sstevel@tonic-gate switch (ep->e_type) {
9827c478bd9Sstevel@tonic-gate case BYTE:
9837c478bd9Sstevel@tonic-gate s = "byte";
9847c478bd9Sstevel@tonic-gate break;
9857c478bd9Sstevel@tonic-gate case SHORT:
9867c478bd9Sstevel@tonic-gate s = "short";
9877c478bd9Sstevel@tonic-gate break;
9887c478bd9Sstevel@tonic-gate case LONG:
9897c478bd9Sstevel@tonic-gate s = "long";
9907c478bd9Sstevel@tonic-gate break;
9917c478bd9Sstevel@tonic-gate case LLONG:
9927c478bd9Sstevel@tonic-gate s = "llong";
9937c478bd9Sstevel@tonic-gate break;
9947c478bd9Sstevel@tonic-gate case UBYTE:
9957c478bd9Sstevel@tonic-gate s = "ubyte";
9967c478bd9Sstevel@tonic-gate break;
9977c478bd9Sstevel@tonic-gate case USHORT:
9987c478bd9Sstevel@tonic-gate s = "ushort";
9997c478bd9Sstevel@tonic-gate break;
10007c478bd9Sstevel@tonic-gate case ULONG:
10017c478bd9Sstevel@tonic-gate s = "ulong";
10027c478bd9Sstevel@tonic-gate break;
10037c478bd9Sstevel@tonic-gate case ULLONG:
10047c478bd9Sstevel@tonic-gate s = "ullong";
10057c478bd9Sstevel@tonic-gate break;
10067c478bd9Sstevel@tonic-gate case STR:
10077c478bd9Sstevel@tonic-gate return ("string");
10087c478bd9Sstevel@tonic-gate default:
10097c478bd9Sstevel@tonic-gate /* more of an emergency measure .. */
10107c478bd9Sstevel@tonic-gate (void) sprintf(buf, "%d", ep->e_type);
10117c478bd9Sstevel@tonic-gate return (buf);
10127c478bd9Sstevel@tonic-gate }
10137c478bd9Sstevel@tonic-gate if (ep->e_mask) {
10147c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s&0x%llx", s, ep->e_mask);
10157c478bd9Sstevel@tonic-gate return (buf);
10167c478bd9Sstevel@tonic-gate } else
10177c478bd9Sstevel@tonic-gate return (s);
10187c478bd9Sstevel@tonic-gate }
10197c478bd9Sstevel@tonic-gate
10207c478bd9Sstevel@tonic-gate static char
op_to_name(char op)10217c478bd9Sstevel@tonic-gate op_to_name(char op)
10227c478bd9Sstevel@tonic-gate {
10237c478bd9Sstevel@tonic-gate char c;
10247c478bd9Sstevel@tonic-gate
10257c478bd9Sstevel@tonic-gate switch (op & ~SUB) {
10267c478bd9Sstevel@tonic-gate
10277c478bd9Sstevel@tonic-gate case EQ:
10287c478bd9Sstevel@tonic-gate case STRC:
10297c478bd9Sstevel@tonic-gate c = '=';
10307c478bd9Sstevel@tonic-gate break;
10317c478bd9Sstevel@tonic-gate
10327c478bd9Sstevel@tonic-gate case GT:
10337c478bd9Sstevel@tonic-gate c = '>';
10347c478bd9Sstevel@tonic-gate break;
10357c478bd9Sstevel@tonic-gate
10367c478bd9Sstevel@tonic-gate case LT:
10377c478bd9Sstevel@tonic-gate c = '<';
10387c478bd9Sstevel@tonic-gate break;
10397c478bd9Sstevel@tonic-gate
10407c478bd9Sstevel@tonic-gate case ANY:
10417c478bd9Sstevel@tonic-gate c = 'x';
10427c478bd9Sstevel@tonic-gate break;
10437c478bd9Sstevel@tonic-gate
10447c478bd9Sstevel@tonic-gate case AND:
10457c478bd9Sstevel@tonic-gate c = '&';
10467c478bd9Sstevel@tonic-gate break;
10477c478bd9Sstevel@tonic-gate
10487c478bd9Sstevel@tonic-gate case NSET:
10497c478bd9Sstevel@tonic-gate c = '^';
10507c478bd9Sstevel@tonic-gate break;
10517c478bd9Sstevel@tonic-gate
10527c478bd9Sstevel@tonic-gate default:
10537c478bd9Sstevel@tonic-gate c = '?';
10547c478bd9Sstevel@tonic-gate break;
10557c478bd9Sstevel@tonic-gate }
10567c478bd9Sstevel@tonic-gate
10577c478bd9Sstevel@tonic-gate return (c);
10587c478bd9Sstevel@tonic-gate }
10597c478bd9Sstevel@tonic-gate
10607c478bd9Sstevel@tonic-gate /*
10617c478bd9Sstevel@tonic-gate * f_prtmtab - Prints out a header, then entries from both magic
10627c478bd9Sstevel@tonic-gate * tables, mtab1 and mtab2, if any exist.
10637c478bd9Sstevel@tonic-gate */
10647c478bd9Sstevel@tonic-gate void
f_prtmtab(void)10657c478bd9Sstevel@tonic-gate f_prtmtab(void)
10667c478bd9Sstevel@tonic-gate {
10677c478bd9Sstevel@tonic-gate Entry *mtab;
10687c478bd9Sstevel@tonic-gate Entry *ep;
10697c478bd9Sstevel@tonic-gate int count;
10707c478bd9Sstevel@tonic-gate
10717c478bd9Sstevel@tonic-gate (void) printf("%-7s %-7s %-10s %-7s %-11s %s\n",
10727c478bd9Sstevel@tonic-gate "level", "off", "type", "opcode", "value", "string");
10737c478bd9Sstevel@tonic-gate for (mtab = mtab1, count = 1; count <= 2; count++, mtab = mtab2) {
10747c478bd9Sstevel@tonic-gate if (mtab == (Entry *)NULL) {
10757c478bd9Sstevel@tonic-gate continue;
10767c478bd9Sstevel@tonic-gate }
10777c478bd9Sstevel@tonic-gate for (ep = mtab; ep->e_off != -1L; ep++) {
10787c478bd9Sstevel@tonic-gate (void) printf("%-7d %-7ld %-10s %-7c ",
10797c478bd9Sstevel@tonic-gate ep->e_level,
10807c478bd9Sstevel@tonic-gate ep->e_off, type_to_name(ep),
10817c478bd9Sstevel@tonic-gate op_to_name(ep->e_opcode));
10827c478bd9Sstevel@tonic-gate if (ep->e_type == STR) {
10837c478bd9Sstevel@tonic-gate showstr(ep->e_value.str, 10);
10847c478bd9Sstevel@tonic-gate } else { /* numeric */
10857c478bd9Sstevel@tonic-gate (void) printf("%-#11llo", ep->e_value.num);
10867c478bd9Sstevel@tonic-gate }
10877c478bd9Sstevel@tonic-gate (void) printf(" %s", ep->e_str);
10887c478bd9Sstevel@tonic-gate if (ep->e_opcode & SUB)
10897c478bd9Sstevel@tonic-gate (void) printf("\tsubst");
10907c478bd9Sstevel@tonic-gate (void) printf("\n");
10917c478bd9Sstevel@tonic-gate }
10927c478bd9Sstevel@tonic-gate }
10937c478bd9Sstevel@tonic-gate }
10947c478bd9Sstevel@tonic-gate
10957c478bd9Sstevel@tonic-gate intmax_t
f_getmaxoffset(int first)10967c478bd9Sstevel@tonic-gate f_getmaxoffset(int first)
10977c478bd9Sstevel@tonic-gate {
10987c478bd9Sstevel@tonic-gate Entry *mtab;
10997c478bd9Sstevel@tonic-gate Entry *ep;
11007c478bd9Sstevel@tonic-gate intmax_t cur;
11017c478bd9Sstevel@tonic-gate intmax_t max = 0;
11027c478bd9Sstevel@tonic-gate
11037c478bd9Sstevel@tonic-gate if (first) {
11047c478bd9Sstevel@tonic-gate mtab = mtab1;
11057c478bd9Sstevel@tonic-gate } else {
11067c478bd9Sstevel@tonic-gate mtab = mtab2;
11077c478bd9Sstevel@tonic-gate }
11087c478bd9Sstevel@tonic-gate if (mtab == (Entry *)NULL) {
11097c478bd9Sstevel@tonic-gate return (0);
11107c478bd9Sstevel@tonic-gate }
11117c478bd9Sstevel@tonic-gate for (ep = mtab; ep->e_off != -1L; ep++) {
11127c478bd9Sstevel@tonic-gate cur = ep->e_off;
11137c478bd9Sstevel@tonic-gate switch (ep->e_type) {
11147c478bd9Sstevel@tonic-gate case STR:
11157c478bd9Sstevel@tonic-gate cur += strlen(ep->e_value.str);
11167c478bd9Sstevel@tonic-gate break;
11177c478bd9Sstevel@tonic-gate case BYTE:
11187c478bd9Sstevel@tonic-gate case UBYTE:
11197c478bd9Sstevel@tonic-gate cur += sizeof (uchar_t);
11207c478bd9Sstevel@tonic-gate break;
11217c478bd9Sstevel@tonic-gate case SHORT:
11227c478bd9Sstevel@tonic-gate case USHORT:
11237c478bd9Sstevel@tonic-gate cur += sizeof (uint16_t);
11247c478bd9Sstevel@tonic-gate break;
11257c478bd9Sstevel@tonic-gate case LONG:
11267c478bd9Sstevel@tonic-gate case ULONG:
11277c478bd9Sstevel@tonic-gate cur += sizeof (uint32_t);
11287c478bd9Sstevel@tonic-gate break;
11297c478bd9Sstevel@tonic-gate case LLONG:
11307c478bd9Sstevel@tonic-gate case ULLONG:
11317c478bd9Sstevel@tonic-gate cur += sizeof (uint64_t);
11327c478bd9Sstevel@tonic-gate break;
11337c478bd9Sstevel@tonic-gate }
11347c478bd9Sstevel@tonic-gate if (cur <= INT_MAX && cur > max) {
11357c478bd9Sstevel@tonic-gate max = cur;
11367c478bd9Sstevel@tonic-gate }
11377c478bd9Sstevel@tonic-gate }
11387c478bd9Sstevel@tonic-gate
11397c478bd9Sstevel@tonic-gate return (max);
11407c478bd9Sstevel@tonic-gate }
1141