=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/file/file.h,v retrieving revision 1.19 retrieving revision 1.20 diff -c -r1.19 -r1.20 *** src/usr.bin/file/file.h 2008/05/08 01:40:56 1.19 --- src/usr.bin/file/file.h 2009/04/24 18:54:34 1.20 *************** *** 1,4 **** ! /* $OpenBSD: file.h,v 1.19 2008/05/08 01:40:56 chl Exp $ */ /* * Copyright (c) Ian F. Darwin 1986-1995. * Software written by Ian F. Darwin and others; --- 1,4 ---- ! /* $OpenBSD: file.h,v 1.20 2009/04/24 18:54:34 chl Exp $ */ /* * Copyright (c) Ian F. Darwin 1986-1995. * Software written by Ian F. Darwin and others; *************** *** 28,34 **** */ /* * file.h - definitions for file(1) program ! * @(#)$Id: file.h,v 1.19 2008/05/08 01:40:56 chl Exp $ */ #ifndef __file_h__ --- 28,34 ---- */ /* * file.h - definitions for file(1) program ! * @(#)$Id: file.h,v 1.20 2009/04/24 18:54:34 chl Exp $ */ #ifndef __file_h__ *************** *** 51,56 **** --- 51,57 ---- #include /* Do this here and now, because struct stat gets re-defined on solaris */ #include + #include #define ENABLE_CONDITIONALS *************** *** 84,99 **** #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef HOWMANY # define HOWMANY (256 * 1024) /* how much of the file to look at */ #endif ! #define MAXMAGIS 8192 /* max entries in /etc/magic */ ! #define MAXDESC 64 /* max leng of text description */ #define MAXstring 32 /* max leng of "string" types */ #define MAGICNO 0xF11E041C ! #define VERSIONNO 4 ! #define FILE_MAGICSIZE (32 * 4) #define FILE_LOAD 0 #define FILE_CHECK 1 --- 85,105 ---- #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif + #ifndef MAX + #define MAX(a,b) (((a) > (b)) ? (a) : (b)) + #endif + #ifndef HOWMANY # define HOWMANY (256 * 1024) /* how much of the file to look at */ #endif ! #define MAXMAGIS 8192 /* max entries in any one magic file ! or directory */ ! #define MAXDESC 64 /* max leng of text description/MIME type */ #define MAXstring 32 /* max leng of "string" types */ #define MAGICNO 0xF11E041C ! #define VERSIONNO 5 ! #define FILE_MAGICSIZE (32 * 6) #define FILE_LOAD 0 #define FILE_CHECK 1 *************** *** 102,119 **** struct magic { /* Word 1 */ uint16_t cont_level; /* level of ">" */ - uint8_t nospflag; /* suppress space character */ uint8_t flag; ! #define INDIR 1 /* if '(...)' appears */ ! #define OFFADD 2 /* if '>&' or '>...(&' appears */ ! #define INDIROFFADD 4 /* if '>&(' appears */ ! #define UNSIGNED 8 /* comparison is unsigned */ /* 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 FILE_INVALID 0 #define FILE_BYTE 1 #define FILE_SHORT 2 --- 108,130 ---- struct magic { /* Word 1 */ uint16_t cont_level; /* level of ">" */ uint8_t flag; ! #define INDIR 0x01 /* if '(...)' appears */ ! #define OFFADD 0x02 /* if '>&' or '>...(&' appears */ ! #define INDIROFFADD 0x04 /* if '>&(' appears */ ! #define UNSIGNED 0x08 /* comparison is unsigned */ ! #define NOSPACE 0x10 /* suppress space character before output */ ! #define BINTEST 0x20 /* test is for a binary type (set only ! for top-level tests) */ ! #define TEXTTEST 0 /* for passing to file_softmagic */ + uint8_t dummy1; + /* Word 2 */ uint8_t reln; /* relation (0=eq, '>'=gt, etc) */ uint8_t vallen; /* length of string value, if any */ ! uint8_t type; /* comparison type (FILE_*) */ ! uint8_t in_type; /* type of indirection */ #define FILE_INVALID 0 #define FILE_BYTE 1 #define FILE_SHORT 2 *************** *** 147,153 **** #define FILE_QLDATE 30 #define FILE_LEQLDATE 31 #define FILE_BEQLDATE 32 ! #define FILE_NAMES_SIZE 33/* size of array to contain all names */ #define IS_STRING(t) \ ((t) == FILE_STRING || \ --- 158,170 ---- #define FILE_QLDATE 30 #define FILE_LEQLDATE 31 #define FILE_BEQLDATE 32 ! #define FILE_FLOAT 33 ! #define FILE_BEFLOAT 34 ! #define FILE_LEFLOAT 35 ! #define FILE_DOUBLE 36 ! #define FILE_BEDOUBLE 37 ! #define FILE_LEDOUBLE 38 ! #define FILE_NAMES_SIZE 39/* size of array to contain all names */ #define IS_STRING(t) \ ((t) == FILE_STRING || \ *************** *** 162,177 **** #define FILE_FMT_NUM 1 /* "cduxXi" */ #define FILE_FMT_STR 2 /* "s" */ #define FILE_FMT_QUAD 3 /* "ll" */ /* Word 3 */ uint8_t in_op; /* operator for indirection */ uint8_t mask_op; /* operator for mask */ #ifdef ENABLE_CONDITIONALS uint8_t cond; /* conditional type */ ! uint8_t dummy1; #else - uint8_t dummy1; uint8_t dummy2; #endif #define FILE_OPS "&|^+-*/%" --- 179,196 ---- #define FILE_FMT_NUM 1 /* "cduxXi" */ #define FILE_FMT_STR 2 /* "s" */ #define FILE_FMT_QUAD 3 /* "ll" */ + #define FILE_FMT_FLOAT 4 /* "eEfFgG" */ + #define FILE_FMT_DOUBLE 5 /* "eEfFgG" */ /* Word 3 */ uint8_t in_op; /* operator for indirection */ uint8_t mask_op; /* operator for mask */ #ifdef ENABLE_CONDITIONALS uint8_t cond; /* conditional type */ ! uint8_t dummy2; #else uint8_t dummy2; + uint8_t dummy3; #endif #define FILE_OPS "&|^+-*/%" *************** *** 212,218 **** } _s; /* for use with string types */ } _u; #define num_mask _u._mask ! #define str_count _u._s._count #define str_flags _u._s._flags /* Words 9-16 */ --- 231,237 ---- } _s; /* for use with string types */ } _u; #define num_mask _u._mask ! #define str_range _u._s._count #define str_flags _u._s._flags /* Words 9-16 */ *************** *** 225,233 **** --- 244,256 ---- uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */ uint8_t hq[8]; /* 8 bytes of a fixed-endian "quad" */ char s[MAXstring]; /* the search string or regex pattern */ + float f; + double d; } value; /* either number or string */ /* Words 17..31 */ char desc[MAXDESC]; /* description */ + /* Words 32..47 */ + char mimetype[MAXDESC]; /* MIME type */ }; #define BIT(A) (1 << (A)) *************** *** 242,247 **** --- 265,271 ---- #define CHAR_IGNORE_UPPERCASE 'C' #define CHAR_REGEX_OFFSET_START 's' #define STRING_IGNORE_CASE (STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE) + #define STRING_DEFAULT_RANGE 100 /* list of magic entries */ *************** *** 268,281 **** } *li; } c; struct out { ! /* Accumulation buffer */ ! char *buf; ! char *ptr; ! size_t left; ! size_t size; ! /* Printable buffer */ ! char *pbuf; ! size_t psize; } o; uint32_t offset; int error; --- 292,299 ---- } *li; } c; struct out { ! char *buf; /* Accumulation buffer */ ! char *pbuf; /* Printable buffer */ } o; uint32_t offset; int error; *************** *** 292,300 **** --- 310,323 ---- size_t rm_len; /* match length */ } search; + /* FIXME: Make the string dynamically allocated so that e.g. + strings matched in files can be longer than MAXstring */ union VALUETYPE ms_value; /* either number or string */ }; + /* Type for Unicode characters */ + typedef unsigned long unichar; + struct stat; protected const char *file_fmttime(uint32_t, int); protected int file_buffer(struct magic_set *, int, const char *, const void *, *************** *** 309,315 **** const unsigned char *, size_t); protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t); protected int file_is_tar(struct magic_set *, const unsigned char *, size_t); ! protected int file_softmagic(struct magic_set *, const unsigned char *, size_t); protected struct mlist *file_apprentice(struct magic_set *, const char *, int); protected uint64_t file_signextend(struct magic_set *, struct magic *, uint64_t); --- 332,338 ---- const unsigned char *, size_t); protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t); protected int file_is_tar(struct magic_set *, const unsigned char *, size_t); ! protected int file_softmagic(struct magic_set *, const unsigned char *, size_t, int); protected struct mlist *file_apprentice(struct magic_set *, const char *, int); protected uint64_t file_signextend(struct magic_set *, struct magic *, uint64_t); *************** *** 326,331 **** --- 349,355 ---- protected const char *file_getbuffer(struct magic_set *); protected ssize_t sread(int, void *, size_t, int); protected int file_check_mem(struct magic_set *, unsigned int); + protected int file_looks_utf8(const unsigned char *, size_t, unichar *, size_t *); #ifndef COMPILE_ONLY extern const char *file_names[]; *************** *** 343,351 **** #define strtoul(a, b, c) strtol(a, b, c) #endif ! #ifndef HAVE_SNPRINTF ! int snprintf(char *, size_t, const char *, ...); #endif #if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK) #define QUICK --- 367,378 ---- #define strtoul(a, b, c) strtol(a, b, c) #endif ! #ifndef HAVE_VASPRINTF ! int vasprintf(char **ptr, const char *format_string, va_list vargs); #endif + #ifndef HAVE_ASPRINTF + int asprintf(char **ptr, const char *format_string, ...); + #endif #if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK) #define QUICK *************** *** 355,360 **** --- 382,390 ---- #define O_BINARY 0 #endif + #ifdef __GNUC__ + static const char *rcsid(const char *) __attribute__((__used__)); + #endif #define FILE_RCSID(id) \ static const char *rcsid(const char *p) { \ return rcsid(p = id); \