RCS file: /p/file/cvsroot/file/src/file.c,v Working file: file.c head: 1.121 branch: locks: strict access list: symbolic names: FILE4_24: 1.119 pre-rrt-big-changes-post-4-23: 1.119 FILE4_23: 1.117 FILE4_22: 1.117 FILE4_21: 1.111 FILE4_20: 1.107 FILE4_19: 1.104 FILE4_18: 1.102 FILE4_17: 1.100 FILE4_16: 1.100 FILE4_15: 1.97 FILE4_14: 1.96 FILE4_13: 1.95 FILE4_12: 1.95 FILE4_11: 1.95 FILE4_10: 1.93 FILE4_09: 1.92 FILE4_08: 1.92 FILE4_07: 1.88 FILE4_06: 1.85 FILE4_05: 1.83 FILE4_04: 1.81 FILE4_03: 1.77 FILE4_02: 1.77 FILE4_01: 1.75 FILE4_00: 1.73 FILE3_41: 1.69 FILE3_40: 1.68 FILE3_39: 1.66 FILE3_38: 1.62 FILE3_37: 1.59 FILE3_36: 1.58 FILE3_35: 1.56 FILE3_34: 1.56 FILE3_33: 1.55 FILE3_32: 1.54 FILE3_31: 1.51 FILE3_30: 1.49 FILE3_28: 1.47 FILE3_27: 1.46 keyword substitution: kv total revisions: 121; selected revisions: 121 description:  ---------------------------- revision 1.121 date: 2008/07/03 15:48:18; author: christos; state: Exp; lines: +5 -1 more fixes for ancient systems ---------------------------- revision 1.120 date: 2008/05/18 23:21:17; author: christos; state: Exp; lines: +2 -2 Use sizeof instead of array length from Charles Longeau ---------------------------- revision 1.119 date: 2008/02/07 00:58:52; author: christos; state: Exp; lines: +4 -84 more fixes from rrt@ ---------------------------- revision 1.118 date: 2008/02/04 20:51:17; author: christos; state: Exp; lines: +3 -2 Debian Fixes via rrt@ ---------------------------- revision 1.117 date: 2007/12/27 16:35:58; author: christos; state: Exp; lines: +9 -13 Various cleanups from OpenBSD and gcc warnings. ---------------------------- revision 1.116 date: 2007/10/29 00:54:08; author: christos; state: Exp; lines: +1 -2 convert fortran to a soft test (from rrt). ---------------------------- revision 1.115 date: 2007/10/25 15:33:17; author: christos; state: Exp; lines: +6 -12 nuke the --with and -no filename options. Leave the brief option like before. ---------------------------- revision 1.114 date: 2007/10/23 21:26:56; author: christos; state: Exp; lines: +24 -9 add -b and -bb option... I need to re-think this because it breaks compatibility ---------------------------- revision 1.113 date: 2007/10/23 19:58:59; author: christos; state: Exp; lines: +20 -67 From Reuben Thomas: - split mime into mime-type and mime-encoding - fix usage string to be auto-generated from the options. ---------------------------- revision 1.112 date: 2007/10/17 19:33:31; author: christos; state: Exp; lines: +20 -5 - separate mime encoding from mime type - fix printing -\012 ---------------------------- revision 1.111 date: 2007/05/08 14:44:18; author: christos; state: Exp; lines: +3 -6 back out timing patch ---------------------------- revision 1.110 date: 2007/05/08 14:41:44; author: christos; state: Exp; lines: +9 -2 mention -C in the options ---------------------------- revision 1.109 date: 2007/03/15 14:50:34; author: christos; state: Exp; lines: +3 -3 fix exclude option (Dmitry V. Levin) ---------------------------- revision 1.108 date: 2007/03/12 15:43:21; author: christos; state: Exp; lines: +3 -3 kill the whole __unused thing. ---------------------------- revision 1.107 date: 2007/01/25 21:05:46; author: christos; state: Exp; lines: +33 -3 add exclude flag. centralize buffer tests. ---------------------------- revision 1.106 date: 2007/01/16 14:54:57; author: ljt; state: Exp; lines: +3 -3 Make this compile with gcc warnings on and make it pass lint. Fix a puts()/putc() usage error. ---------------------------- revision 1.105 date: 2007/01/12 17:38:28; author: christos; state: Exp; lines: +1 -1 Use File id. ---------------------------- revision 1.104 date: 2006/11/25 17:28:54; author: christos; state: Exp; lines: +11 -6 - keep the offset in a separate variable in the magic structure, instead of trashing the offset in the magic number. - fix printing of the nul offset. ---------------------------- revision 1.103 date: 2006/11/17 16:11:10; author: christos; state: Exp; lines: +12 -6 add -0 ---------------------------- revision 1.102 date: 2006/06/02 00:07:58; author: ian; state: Exp; lines: +5 -2 Add missing 'r' flag in USAGE, and one comment ---------------------------- revision 1.101 date: 2006/05/03 15:50:23; author: christos; state: Exp; lines: +6 -4 use constants and be more tolerant of seek errors. From suse ---------------------------- revision 1.100 date: 2005/10/17 18:41:44; author: christos; state: Exp; lines: +12 -10 void casts, problems with 64 bit elf files. ---------------------------- revision 1.99 date: 2005/10/17 17:39:39; author: christos; state: Exp; lines: +9 -3 Fix the '\n' chopping. ---------------------------- revision 1.98 date: 2005/10/17 15:31:10; author: christos; state: Exp; lines: +1 -2 Support for O_BINARY ---------------------------- revision 1.97 date: 2005/08/12 14:19:33; author: christos; state: Exp; lines: +10 -3 Add -h support for POSIX. ---------------------------- revision 1.96 date: 2005/03/06 05:58:22; author: christos; state: Exp; lines: +2 -2 Add indirect magic offset support and search support. ---------------------------- revision 1.95 date: 2004/09/27 15:28:37; author: christos; state: Exp; lines: +2 -1 fix memory leaks. ---------------------------- revision 1.94 date: 2004/09/11 19:15:57; author: christos; state: Exp; lines: +1 -6 Remove advertising clauses, with Ian's permission. ---------------------------- revision 1.93 date: 2004/04/07 14:23:55; author: christos; state: Exp; lines: +2 -2 Add more conditional defines ---------------------------- revision 1.92 date: 2004/03/22 21:34:39; author: christos; state: Exp; lines: +2 -2 typo in wchar_t ---------------------------- revision 1.91 date: 2004/03/22 19:12:15; author: christos; state: Exp; lines: +42 -5 wide char strlen support. from debian ---------------------------- revision 1.90 date: 2004/03/03 17:24:28; author: christos; state: Exp; lines: +3 -1 don't support getopt_long if we don't have ---------------------------- revision 1.89 date: 2004/03/03 17:21:05; author: christos; state: Exp; lines: +4 -4 disable help messages if we don't have getopt_long ---------------------------- revision 1.88 date: 2003/12/23 17:32:41; author: christos; state: Exp; lines: +3 -4 fix -k flag ---------------------------- revision 1.87 date: 2003/11/11 20:01:45; author: christos; state: Exp; lines: +2 -2 Include "file.h" first because it includes "config.h" and this needs to come first. ---------------------------- revision 1.86 date: 2003/10/27 18:09:41; author: christos; state: Exp; lines: +2 -2 Remove unused variables. ---------------------------- revision 1.85 date: 2003/10/09 16:29:53; author: christos; state: Exp; lines: +2 -1 Add long description. ---------------------------- revision 1.84 date: 2003/10/09 15:15:23; author: christos; state: Exp; lines: +6 -2 Add a raw flag, and translate unprintable chars. ---------------------------- revision 1.83 date: 2003/10/08 17:09:26; author: christos; state: Exp; lines: +8 -3 Print error when compile fails, and turn warnings on while compiling so we can see what is wrong. ---------------------------- revision 1.82 date: 2003/10/08 16:37:27; author: christos; state: Exp; lines: +2 -12 - Treat filenames more sanely. - Handle freeing of magic in one place. - Fix memory leak. ---------------------------- revision 1.81 date: 2003/09/12 19:39:44; author: christos; state: Exp; lines: +2 -2 minor fixes ---------------------------- revision 1.80 date: 2003/07/10 21:10:16; author: christos; state: Exp; lines: +3 -2 add -p to the long usage. ---------------------------- revision 1.79 date: 2003/07/10 17:41:24; author: christos; state: Exp; lines: +12 -3 Utime/utimes support ---------------------------- revision 1.78 date: 2003/07/10 17:01:38; author: christos; state: Exp; lines: +3 -2 Don't exit with -1. ---------------------------- revision 1.77 date: 2003/03/27 22:46:51; author: christos; state: Exp; lines: +3 -5 even better usage fix. ---------------------------- revision 1.76 date: 2003/03/27 22:33:18; author: christos; state: Exp; lines: +11 -8 fix version printing. make separator take a string instead of char. ---------------------------- revision 1.75 date: 2003/03/26 16:31:19; author: christos; state: Exp; lines: +5 -4 better handling of stdin ---------------------------- revision 1.74 date: 2003/03/26 15:35:30; author: christos; state: Exp; lines: +2 -2 - pass lint. - fix pointer casts. - only first error is kept. ---------------------------- revision 1.73 date: 2003/03/24 01:34:21; author: christos; state: Exp; lines: +1 -6 add apptype.c for OS/2 ---------------------------- revision 1.72 date: 2003/03/24 01:16:28; author: christos; state: Exp; lines: +6 -6 constant name protection. ---------------------------- revision 1.71 date: 2003/03/23 21:16:26; author: christos; state: Exp; lines: +33 -24 update copyrights. ---------------------------- revision 1.70 date: 2003/03/23 04:06:05; author: christos; state: Exp; lines: +93 -190 reorg ---------------------------- revision 1.69 date: 2003/02/27 20:47:46; author: christos; state: Exp; lines: +2 -2 patches from NetBSD. ---------------------------- revision 1.68 date: 2003/02/08 18:33:53; author: christos; state: Exp; lines: +16 -5 - detect inttypes.h too (Dave Love ) - eliminate unsigned char warnings (Petter Reinholdtsen ) - better elf PT_NOTE handling (Nalin Dahyabhai ) - add options to format the output differently - much more magic. ---------------------------- revision 1.67 date: 2002/07/09 14:12:40; author: christos; state: Exp; lines: +7 -7 Detect getopt_long correctly. Fix gcc'ism. ---------------------------- revision 1.66 date: 2002/07/03 19:00:41; author: christos; state: Exp; lines: +1 -2 - solaris fixes - ansify and c99ise - improve compile_only mode - magic fixes ---------------------------- revision 1.65 date: 2002/07/03 18:26:37; author: christos; state: Exp; lines: +35 -48 - de __P() - use stdint.h ---------------------------- revision 1.64 date: 2002/06/11 17:31:46; author: christos; state: Exp; lines: +1 -4 Solaris compilation cleanups. ---------------------------- revision 1.63 date: 2002/06/11 17:15:52; author: christos; state: Exp; lines: +2 -2 Large file support for linux. ---------------------------- revision 1.62 date: 2002/05/16 18:45:56; author: christos; state: Exp; lines: +108 -8 - pt_note elf additions from NetBSD - EMX os specific changes (Alexander Mai) - stdint.h detection, acconfig.h fixes (Maciej W. Rozycki, Franz Korntner) - regex file additions (Kim Cromie) - getopt_long support and misc cleanups (Michael Piefel) - many magic fixes and additions ---------------------------- revision 1.61 date: 2001/12/18 20:56:38; author: christos; state: Exp; lines: +2 -2 avarvit@dolnet.gr: Make unrecognized files print application/octet-stream instead of data. ---------------------------- revision 1.60 date: 2001/10/20 17:44:53; author: christos; state: Exp; lines: +2 -2 - fix compilation problem when QUICK is not defined. - zlib support Nicolas Lichtmaier - largefile support Nicolas Lichtmaier - support seeking on pipes Nicolas Lichtmaier ---------------------------- revision 1.59 date: 2001/07/23 00:02:32; author: christos; state: Exp; lines: +2 -2 sync with NetBSD ---------------------------- revision 1.58 date: 2001/07/22 21:04:15; author: christos; state: Exp; lines: +21 -8 - magic fixes - add new operators, pascal strings, UTC date printing, $HOME/.magic [from "Tom N Harris" ] ---------------------------- revision 1.57 date: 2001/04/27 23:59:52; author: christos; state: Exp; lines: +1 -3 Always enable quick mode, even if we don't have mmap (christos) Autoconf help for mmap (Alexander Mai) ---------------------------- revision 1.56 date: 2001/03/11 20:29:16; author: christos; state: Exp; lines: +24 -12 add compiled format ---------------------------- revision 1.55 date: 2000/08/05 19:00:12; author: christos; state: Exp; lines: +2 -1 delint. ---------------------------- revision 1.54 date: 2000/08/05 18:30:26; author: christos; state: Exp; lines: +2 -2 don't include file.h first. ---------------------------- revision 1.53 date: 2000/08/05 17:36:48; author: christos; state: Exp; lines: +69 -66 Correct indianness detection in elf (Charles Hannum) FreeBSD elf core support (Guy Harris) Use gzip in systems that don't have uncompress (Anthon van der Neut) Internationalization/EBCDIC support (Eric Fisher) Many many magic changes ---------------------------- revision 1.52 date: 2000/05/14 22:58:53; author: christos; state: Exp; lines: +1 -4 add errno.h in file.h and remove it from other places. ---------------------------- revision 1.51 date: 2000/05/14 17:58:36; author: christos; state: Exp; lines: +31 -27 - new magic for claris files - new magic for mathematica and maple files - new magic for msvc files - new -k flag to keep going matching all possible entries - add the word executable on #! magic files, and fix the usage of the word script - lots of other magic fixes - fix typo test -> text ---------------------------- revision 1.50 date: 2000/04/23 04:31:44; author: christos; state: Exp; lines: +1 -4 remove duplicate locale (Alexander Mai) ---------------------------- revision 1.49 date: 2000/04/11 02:32:35; author: christos; state: Exp; lines: +21 -6 mime changes ---------------------------- revision 1.48 date: 1999/11/28 20:02:29; author: christos; state: Exp; lines: +8 -1 new string/[Bcb] magic from anton, and adjustments to the magic files to use it. ---------------------------- revision 1.47 date: 1999/10/31 22:23:03; author: christos; state: Exp; lines: +6 -1 Recent changes ---------------------------- revision 1.46 date: 1999/02/14 17:16:05; author: christos; state: Exp; lines: +13 -3 Automake and file -s patches. ---------------------------- revision 1.45 date: 1999/01/14 16:21:21; author: christos; state: Exp; lines: +4 -4 Fix usage string. ---------------------------- revision 1.44 date: 1999/01/14 15:53:59; author: christos; state: Exp; lines: +8 -3 Mostly magic fixes. and -n option. ---------------------------- revision 1.43 date: 1999/01/13 15:44:03; author: christos; state: Exp; lines: +3 -3 Various fixed. ---------------------------- revision 1.42 date: 1998/09/12 13:17:52; author: christos; state: Exp; lines: +12 -7 *** empty log message *** ---------------------------- revision 1.41 date: 1998/06/27 13:57:23; author: christos; state: Exp; lines: +4 -2 *** empty log message *** ---------------------------- revision 1.40 date: 1998/06/27 13:23:39; author: christos; state: Exp; lines: +5 -5 rcsid magic ---------------------------- revision 1.39 date: 1998/02/15 23:18:53; author: christos; state: Exp; lines: +9 -5 Add autoconf ---------------------------- revision 1.38 date: 1997/01/15 19:28:35; author: christos; state: Exp; lines: +5 -1 \fix typos ---------------------------- revision 1.37 date: 1997/01/15 17:23:24; author: christos; state: Exp; lines: +23 -4 - add support for elf core files: find the program name under SVR4 [Ken Pizzini] - print strings only up to the first carriage return [various] - freebsd international ascii support [J Wunsch] - magic fixes and additions [Guy Harris] - 64 bit fixes [Larry Schwimmer] - support for both utime and utimes, but don't restore file access times by default [various] - \xXX only takes 2 hex digits, not 3. - re-implement support for core files [Guy Harris] ---------------------------- revision 1.36 date: 1996/10/05 18:13:57; author: christos; state: Exp; lines: +5 -55 Segregate elf stuff. ---------------------------- revision 1.35 date: 1996/06/22 22:04:22; author: christos; state: Exp; lines: +109 -33 *** empty log message *** ---------------------------- revision 1.34 date: 1995/10/27 23:12:01; author: christos; state: Exp; lines: +3 -3 Added colon separated list of magic files ---------------------------- revision 1.33 date: 1995/05/20 22:09:21; author: christos; state: Exp; lines: +49 -39 Passed incorrect argument to eatsize(). Use %ld and %lx where appropriate. Remove unused variables ELF support for both big and little endian Fixes for small files again. ---------------------------- revision 1.32 date: 1995/04/28 17:29:13; author: christos; state: Exp; lines: +47 -8 - Incorrect nroff detection fix from der Mouse - Lost and incorrect magic entries. - Added ELF stripped binary detection [in C; ugh] - Look for $MAGIC to find the magic file. - Eat trailing size specifications from numbers i.e. ignore 10L - More fixes for very short files ---------------------------- revision 1.31 date: 1995/03/25 22:08:07; author: christos; state: Exp; lines: +7 -2 3.16 ---------------------------- revision 1.30 date: 1995/01/21 21:03:35; author: christos; state: Exp; lines: +27 -8 Added CSECTION for the file man page Added version flag -v Fixed bug with -f input flag (from iorio@violet.berkeley.edu) Lots of magic fixes and reorganization... ---------------------------- revision 1.29 date: 1993/10/27 20:59:05; author: christos; state: Exp; lines: +16 -13 Changed -z flag to understand gzip format too. Moved builtin compression detection to a table, and move the compress magic entry out of the source. Made printing of numbers unsigned, and added the mask to it. Changed the buffer size to 8k, because gzip will refuse to unzip just a few bytes. ---------------------------- revision 1.28 date: 1993/09/23 21:47:01; author: christos; state: Exp; lines: +3 -2 *** empty log message *** ---------------------------- revision 1.27 date: 1993/09/16 20:45:46; author: christos; state: Exp; lines: +2 -2 off by one in nbytes ---------------------------- revision 1.26 date: 1993/02/19 14:22:45; author: ian; state: Exp; lines: +5 -3 Part of Guy Harris' Jan-93 rewrite, including: Put an extra '\0' at the end of the buffer before handing it to "tryit()"; "ascmagic()" assumes the buffer is a '\0'-terminated string, as it runs a copy of it through "strtok()". ---------------------------- revision 1.25 date: 1992/09/11 13:15:16; author: ian; state: Exp; lines: +4 -3 Permission denied type messages are no longer fatal. ---------------------------- revision 1.24 date: 1992/09/11 11:44:31; author: ian; state: Exp; lines: +1 -9 Remove ckfputs() function; it's now in print.c. ---------------------------- revision 1.23 date: 1992/09/08 22:32:35; author: ian; state: Exp; lines: +10 -1 Christos's fix to his fix: make cfkputs() a function, not a macro. ---------------------------- revision 1.22 date: 1992/09/08 15:36:41; author: ian; state: Exp; lines: +1 -1 Change RCS ID from Header to ID. ---------------------------- revision 1.21 date: 1992/09/08 15:01:52; author: ian; state: Exp; lines: +122 -107 Zoulos' version: sagans of tiny changes, mostly for dynamic arrays, ANSI C, dropping old cruft. ---------------------------- revision 1.20 date: 1992/05/22 17:50:52; author: ian; state: Exp; lines: +29 -12 Rename try to tryit; give warning exactly 2 args; process() now has 1 arg; delete definition of struct utimbuf. ---------------------------- revision 1.19 date: 1991/02/25 10:02:28; author: ian; state: Exp; lines: +9 -2 Try to make filenames line up by putting 2nd tab if strlen(name)<7, like other file commands do. ---------------------------- revision 1.18 date: 1991/01/23 13:56:37; author: ian; state: Exp; lines: +11 -10 Delint. ---------------------------- revision 1.17 date: 1991/01/23 13:23:23; author: ian; state: Exp; lines: +45 -28 Break out "try" routine, takes a buffer and nbytes, to call softmagic and ascmagic, defaulting to "data", so it can be called by the compress handler in hardmagic.c. Add new -z option, to (later) handle uncompressing of files. Minor formatting changes at front of file. ---------------------------- revision 1.16 date: 1990/10/03 17:49:09; author: ian; state: Exp; lines: +10 -5 Add a -L option that lets you follow symlinks, after BSD ls(1)'s -L option. ---------------------------- revision 1.15 date: 1988/03/23 11:42:16; author: ian; state: Exp; lines: +4 -2 exit code non-zero for case of "no files and no -f". ---------------------------- revision 1.14 date: 1987/11/12 13:11:06; author: ian; state: Exp; lines: +2 -2 Print a file name for standard input as well as filename case. ---------------------------- revision 1.13 date: 1987/11/12 12:57:50; author: ian; state: Exp; lines: +4 -1 Handle case where read of HOWMANY from file returns zero! ---------------------------- revision 1.12 date: 1987/11/06 21:03:16; author: ian; state: Exp; lines: +2 -2 Add -c to Usage message. ---------------------------- revision 1.11 date: 1987/10/05 22:04:55; author: ian; state: Exp; lines: +7 -4 If -f namefile was specified, we don't need a list of files on the commandline too, though it's still allowable to have both. ---------------------------- revision 1.10 date: 1987/10/05 21:47:05; author: ian; state: Exp; lines: +2 -2 Clarify usage message (tnx John Gilmore). ---------------------------- revision 1.9 date: 1987/09/16 14:44:56; author: ian; state: Exp; lines: +2 -1 Fix rcsid. ---------------------------- revision 1.8 date: 1987/09/11 22:06:52; author: ian; state: Exp; lines: +8 -4 -c runs now do not expect file arguments. ---------------------------- revision 1.7 date: 1987/09/11 15:02:38; author: ian; state: Exp; lines: +24 -1 Add updated legal notice. ---------------------------- revision 1.6 date: 1987/08/30 10:46:58; author: ian; state: Exp; lines: +24 -9 Gilmore's code to read stdin (has a goto, grrr). ---------------------------- revision 1.5 date: 1987/08/30 10:11:17; author: ian; state: Exp; lines: +4 -0 Add #ifdef MAGIC so it can come from the compile command (Gilmore). ---------------------------- revision 1.4 date: 1987/08/28 21:36:02; author: ian; state: Exp; lines: +10 -30 Withdraw "-" logic as it results in core dumps (why?). ---------------------------- revision 1.3 date: 1987/08/28 21:09:02; author: ian; state: Exp; lines: +1 -1 Minor stylistic tweaking. ---------------------------- revision 1.2 date: 1987/08/28 21:04:38; author: ian; state: Exp; lines: +30 -10 John Gilmore mod: allow "-" as a filename argument! Clever, but involves a goto. ---------------------------- revision 1.1 date: 1987/08/23 19:51:05; author: ian; state: Exp; Initial revision =============================================================================