aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid E. O'Brien <obrien@FreeBSD.org>2007-05-24 16:12:23 +0000
committerDavid E. O'Brien <obrien@FreeBSD.org>2007-05-24 16:12:23 +0000
commitd1d50c78ab5592e27e6f1dc9657dc4c8eb8fdc9e (patch)
tree37b746f3239e5c10707b493dc640fe926e355910
parentdbca37326fc67da021d06cc2d5cee76ef2ee1339 (diff)
downloadsrc-d1d50c78ab5592e27e6f1dc9657dc4c8eb8fdc9e.tar.gz
src-d1d50c78ab5592e27e6f1dc9657dc4c8eb8fdc9e.zip
Virgin import of Christos Zoulas's FILE 4.19.
Notes
Notes: svn path=/vendor/file/dist/; revision=169942
-rw-r--r--contrib/file/ChangeLog86
-rw-r--r--contrib/file/LEGAL.NOTICE4
-rw-r--r--contrib/file/MAINT40
-rw-r--r--contrib/file/Magdir/archive23
-rw-r--r--contrib/file/Magdir/audio80
-rw-r--r--contrib/file/Magdir/cad15
-rw-r--r--contrib/file/Magdir/cafebabe21
-rw-r--r--contrib/file/Magdir/commands2
-rw-r--r--contrib/file/Magdir/editors3
-rw-r--r--contrib/file/Magdir/elf27
-rw-r--r--contrib/file/Magdir/filesystems127
-rw-r--r--contrib/file/Magdir/images8
-rw-r--r--contrib/file/Magdir/java9
-rw-r--r--contrib/file/Magdir/linux7
-rw-r--r--contrib/file/Magdir/mach29
-rw-r--r--contrib/file/Magdir/misctools3
-rw-r--r--contrib/file/Magdir/msdos18
-rw-r--r--contrib/file/Magdir/os40032
-rw-r--r--contrib/file/Magdir/python1
-rw-r--r--contrib/file/Magdir/riff7
-rw-r--r--contrib/file/Magdir/sun8
-rw-r--r--contrib/file/Magdir/sysex127
-rw-r--r--contrib/file/Magdir/unicode15
-rw-r--r--contrib/file/Magdir/vmware7
-rw-r--r--contrib/file/Magdir/wordprocessors21
-rw-r--r--contrib/file/Magdir/xwindows2
-rw-r--r--contrib/file/Makefile.am3
-rw-r--r--contrib/file/Makefile.in3
-rw-r--r--contrib/file/README5
-rw-r--r--contrib/file/apprentice.c470
-rw-r--r--contrib/file/ascmagic.c6
-rw-r--r--contrib/file/compress.c59
-rw-r--r--contrib/file/config.h.in3
-rwxr-xr-xcontrib/file/configure902
-rw-r--r--contrib/file/configure.in14
-rw-r--r--contrib/file/file.c36
-rw-r--r--contrib/file/file.h70
-rw-r--r--contrib/file/funcs.c28
-rwxr-xr-xcontrib/file/install-sh496
-rw-r--r--contrib/file/is_tar.c12
-rw-r--r--contrib/file/magic.c103
-rw-r--r--contrib/file/magic.mime78
-rwxr-xr-xcontrib/file/magic2mime3
-rw-r--r--contrib/file/mkinstalldirs179
-rw-r--r--contrib/file/patchlevel.h10
-rw-r--r--contrib/file/print.c34
-rw-r--r--contrib/file/readelf.c155
-rw-r--r--contrib/file/softmagic.c610
-rw-r--r--contrib/file/tar.h5
49 files changed, 2096 insertions, 1910 deletions
diff --git a/contrib/file/ChangeLog b/contrib/file/ChangeLog
index d35b90472b66..8c58f749a2c7 100644
--- a/contrib/file/ChangeLog
+++ b/contrib/file/ChangeLog
@@ -1,3 +1,89 @@
+2006-12-11 16:49 Christos Zoulas <christos@zoulas.com>
+
+ * fix byteswapping issue
+
+ * report the number of bytes we tried to
+ allocate when allocation fails
+
+ * add a few missed cases in the strength routine
+
+2006-12-08 16:32 Christos Zoulas <christos@zoulas.com>
+
+ * store and print the line number of the magic
+ entry for debugging.
+
+ * if the magic entry did not print anything,
+ don't treat it as a match
+
+ * change the magic strength algorithm to take
+ into account the relationship op.
+
+ * fix a bug in search where we could accidentally
+ return a match.
+
+ * propagate the error return from match to
+ file_softmagic.
+
+2006-11-25 13:35 Christos Zoulas <christos@zoulas.com>
+
+ * Don't store the current offset in the magic
+ struct, because it needs to be restored and
+ it was not done properly all the time. Bug
+ found by: Arkadiusz Miskiewicz
+
+ * Fix problem in the '\0' separator; and don't
+ print it as an additional separator; print
+ it as the only separator.
+
+2006-11-17 10:51 Christos Zoulas <christos@zoulas.com>
+
+ * Added a -0 option to print a '\0' separator
+ Etienne Buira <etienne.buira@free.fr>
+
+2006-10-31 15:14 Christos Zoulas <christos@zoulas.com>
+
+ * Check offset before copying (Mike Frysinger)
+
+ * merge duplicated code
+
+ * add quad date support
+
+ * make sure that we nul terminate desc (Ryoji Kanai)
+
+ * don't process elf notes multiple times
+
+ * allow -z to report empty compressed files
+
+ * use calloc to initialize the ascii buffers (Jos van den Oever)
+
+2006-06-08 11:11 Christos Zoulas <christos@zoulas.com>
+
+ * QNX fixes (Mike Gorchak)
+
+ * Add quad support.
+
+ * FIFO checks (Dr. Werner Fink)
+
+ * Linux ELF fixes (Dr. Werner Fink)
+
+ * Magic format checks (Dr. Werner Fink)
+
+ * Magic format function improvent (Karl Chen)
+
+2006-05-03 11:11 Christos Zoulas <christos@zoulas.com>
+
+ * Pick up some elf changes and some constant fixes from SUSE
+
+ * Identify gnu tar vs. posix tar
+
+ * When keep going, don't print spurious newlines (Radek Vokál)
+
+2006-04-01 12:02 Christos Zoulas <christos@zoulas.com>
+
+ * Use calloc instead of malloc (Mike Frysinger)
+
+ * Fix configure script to detect wctypes.h (Mike Frysinger)
+
2006-03-02 16:06 Christos Zoulas <christos@zoulas.com>
* Print empty if the file is (Mike Frysinger)
diff --git a/contrib/file/LEGAL.NOTICE b/contrib/file/LEGAL.NOTICE
index 0c2c719260f7..d1ea55641bd1 100644
--- a/contrib/file/LEGAL.NOTICE
+++ b/contrib/file/LEGAL.NOTICE
@@ -1,7 +1,7 @@
-$Id: LEGAL.NOTICE,v 1.14 2004/09/11 19:15:56 christos Exp $
+$Id: LEGAL.NOTICE,v 1.15 2006/05/03 18:48:33 christos Exp $
Copyright (c) Ian F. Darwin 1986, 1987, 1989, 1990, 1991, 1992, 1994, 1995.
Software written by Ian F. Darwin and others;
-maintained 1994-2004 Christos Zoulas.
+maintained 1994- Christos Zoulas.
This software is not subject to any export provision of the United States
Department of Commerce, and may be exported to any country or planet.
diff --git a/contrib/file/MAINT b/contrib/file/MAINT
index c711117fb994..2a51470ddb74 100644
--- a/contrib/file/MAINT
+++ b/contrib/file/MAINT
@@ -1,4 +1,4 @@
-$Id: MAINT,v 1.5 2003/03/23 04:36:37 christos Exp $
+$Id: MAINT,v 1.7 2006/06/01 18:19:41 ian Exp $
Maintenance notes:
@@ -18,16 +18,38 @@ short.
- Do not distribute changed versions.
People trying to be helpful occasionally put up their hacked versions
-of the file command for FTP, then the "archie" server finds and publishes
-the hacked version, and people all over the world get copies of it.
-Within a day or two I am getting email from around the world
-asking me why "my" file command won't compile!!! Needless to say this
-detracts from the limited time I have available to work on the actual
-software. Therefore I ask you again to please NOT distribute
-your changed version.
-
+of the file command for anonymous FTP, and people all over the
+world get copies of the hacked versions. Within a day or two I am
+getting email from around the world asking me why "my" file command
+won't compile!!! Needless to say this detracts from the limited
+time I have available to work on the actual software. Therefore I
+ask you again to please NOT distribute your changed version. If
+you need to make changes, please add a patch file next to the
+distribution tar, and a README file that clearly explains what you
+are trying to fix.
Thank you for your assistance and cooperation.
+Code Overview
+
+This is a rough idea of the control flow from the main program:
+
+file.c main()
+file.c process (called for each file)
+ printf file name
+magic.c magic_file()
+fsmagic.c file_fsmagic()
+ (handles statbuf modes for DEV)
+ (handles statbuf modes for executable &c.
+ reads data from file.
+funcs.c: file_buffer()
+compress.c file_zmagic()
+is_tar.c file_is_tar()
+softmagic.c file_softmagic()
+ match() - looks for match against main magic database
+ascmagic.c file_ascmagic()
+readelf.c file_tryelf()
+ "unknown"
+
Christos Zoulas
christos@astron.com
diff --git a/contrib/file/Magdir/archive b/contrib/file/Magdir/archive
index f60731b8c438..e110fd481194 100644
--- a/contrib/file/Magdir/archive
+++ b/contrib/file/Magdir/archive
@@ -509,6 +509,12 @@
# RAR archiver (Greg Roelofs, newt@uchicago.edu)
0 string Rar! RAR archive data,
>44 byte x v%0x,
+>10 byte >0 flags:
+>>10 byte &0x01 Archive volume,
+>>10 byte &0x02 Commented,
+>>10 byte &0x04 Locked,
+>>10 byte &0x08 Solid,
+>>10 byte &0x20 Authenticated,
>35 byte 0 os: MS-DOS
>35 byte 1 os: OS/2
>35 byte 2 os: Win32
@@ -530,6 +536,8 @@
>4 byte 0x0b Zip archive data, at least v1.1 to extract
>4 byte 0x14
>>30 ubelong !0x6d696d65 Zip archive data, at least v2.0 to extract
+>0x161 string WINZIP Zip archive data, WinZIP self-extracting
+
# OpenOffice.org / KOffice / StarOffice documents
# From: Abel Cheung <abel@oaka.org>
@@ -700,3 +708,18 @@
# EET archive
# From: Tilman Sauerbeck <tilman@code-monkey.de>
0 belong 0x1ee7ff00 EET archive
+
+# rzip archives
+0 string RZIP rzip compressed data
+>4 byte x - version %d
+>5 byte x \b.%d
+>6 belong x (%d bytes)
+
+# From: "Robert Dale" <robdale@gmail.com>
+0 belong 123 dar archive,
+>4 belong x label "%.8x
+>>8 belong x %.8x
+>>>12 beshort x %.4x"
+>14 byte 0x54 end slice
+>14 beshort 0x4e4e multi-part
+>14 beshort 0x4e53 multi-part, with -S
diff --git a/contrib/file/Magdir/audio b/contrib/file/Magdir/audio
index 252a9dea0f0f..fd9d7715d71b 100644
--- a/contrib/file/Magdir/audio
+++ b/contrib/file/Magdir/audio
@@ -25,7 +25,7 @@
>12 belong 19 16-bit linear compressed,
>12 belong 20 16-bit linear with emphasis and compression,
>12 belong 21 Music kit DSP commands,
->12 belong 23 8-bit ISDN mu-law compressed (CCITT G.721 ADPCM voice data encoding),
+>12 belong 23 8-bit ISDN mu-law compressed (CCITT G.721 ADPCM voice enc.),
>12 belong 24 compressed (8-bit CCITT G.722 ADPCM)
>12 belong 25 compressed (3-bit CCITT G.723.3 ADPCM),
>12 belong 26 compressed (5-bit CCITT G.723.5 ADPCM),
@@ -55,7 +55,7 @@
>12 belong 19 16-bit linear compressed,
>12 belong 20 16-bit linear with emphasis and compression,
>12 belong 21 Music kit DSP commands,
->12 lelong 23 8-bit ISDN mu-law compressed (CCITT G.721 ADPCM voice data encoding),
+>12 lelong 23 8-bit ISDN mu-law compressed (CCITT G.721 ADPCM voice enc.),
>12 belong 24 compressed (8-bit CCITT G.722 ADPCM)
>12 belong 25 compressed (3-bit CCITT G.723.3 ADPCM),
>12 belong 26 compressed (5-bit CCITT G.723.5 ADPCM),
@@ -221,9 +221,41 @@
# SGI SoundTrack <mpruett@sgi.com>
0 string _SGI_SoundTrack SGI SoundTrack project file
# ID3 version 2 tags <waschk@informatik.uni-rostock.de>
-0 string ID3 MP3 file with ID3 version 2.
+0 string ID3 Audio file with ID3 version 2
>3 ubyte <0xff \b%d.
>4 ubyte <0xff \b%d tag
+>2584 string fLaC \b, FLAC encoding
+>>2588 byte&0x7f >0 \b, unknown version
+>>2588 byte&0x7f 0 \b
+# some common bits/sample values
+>>>2600 beshort&0x1f0 0x030 \b, 4 bit
+>>>2600 beshort&0x1f0 0x050 \b, 6 bit
+>>>2600 beshort&0x1f0 0x070 \b, 8 bit
+>>>2600 beshort&0x1f0 0x0b0 \b, 12 bit
+>>>2600 beshort&0x1f0 0x0f0 \b, 16 bit
+>>>2600 beshort&0x1f0 0x170 \b, 24 bit
+>>>2600 byte&0xe 0x0 \b, mono
+>>>2600 byte&0xe 0x2 \b, stereo
+>>>2600 byte&0xe 0x4 \b, 3 channels
+>>>2600 byte&0xe 0x6 \b, 4 channels
+>>>2600 byte&0xe 0x8 \b, 5 channels
+>>>2600 byte&0xe 0xa \b, 6 channels
+>>>2600 byte&0xe 0xc \b, 7 channels
+>>>2600 byte&0xe 0xe \b, 8 channels
+# some common sample rates
+>>>2597 belong&0xfffff0 0x0ac440 \b, 44.1 kHz
+>>>2597 belong&0xfffff0 0x0bb800 \b, 48 kHz
+>>>2597 belong&0xfffff0 0x07d000 \b, 32 kHz
+>>>2597 belong&0xfffff0 0x056220 \b, 22.05 kHz
+>>>2597 belong&0xfffff0 0x05dc00 \b, 24 kHz
+>>>2597 belong&0xfffff0 0x03e800 \b, 16 kHz
+>>>2597 belong&0xfffff0 0x02b110 \b, 11.025 kHz
+>>>2597 belong&0xfffff0 0x02ee00 \b, 12 kHz
+>>>2597 belong&0xfffff0 0x01f400 \b, 8 kHz
+>>>2597 belong&0xfffff0 0x177000 \b, 96 kHz
+>>>2597 belong&0xfffff0 0x0fa000 \b, 64 kHz
+>>>2601 byte&0xf >0 \b, >4G samples
+>2584 string !fLaC \b, MP3 encoding
# NSF (NES sound file) magic
0 string NESM\x1a NES Sound File
@@ -443,10 +475,6 @@
# From: Emanuel Haupt <ehaupt@critical.ch>
0 string ZXAYEMUL Spectrum 128 tune
-# From: Alex Beregszaszi <alex@fsn.hu>
-0 string MP+ Musepack
->3 byte&0x0f x SV%d
-
0 string \0BONK BONK,
#>5 byte x version %d
>14 byte x %d channel(s),
@@ -479,3 +507,41 @@
0 string \[playlist\] PLS playlist
# licq.conf
1 string \[licq\] LICQ configuration file
+
+# Atari ST audio files by Dirk Jagdmann <doj@cubic.org>
+0 string ICE! SNDH Atari ST music
+0 string SC68\ Music-file\ /\ (c)\ (BeN)jami sc68 Atari ST music
+
+# musepak support From: "Jiri Pejchal" <jiri.pejchal@gmail.com>
+0 string MP+ Musepack audio
+>3 byte 255 \b, SV pre8
+>3 byte&0xF 0x6 \b, SV 6
+>3 byte&0xF 0x8 \b, SV 8
+>3 byte&0xF 0x7 \b, SV 7
+>>3 byte&0xF0 0x0 \b.0
+>>3 byte&0xF0 0x10 \b.1
+>>3 byte&0xF0 240 \b.15
+>>10 byte&0xF0 0x0 \b, no profile
+>>10 byte&0xF0 0x10 \b, profile 'Unstable/Experimental'
+>>10 byte&0xF0 0x50 \b, quality 0
+>>10 byte&0xF0 0x60 \b, quality 1
+>>10 byte&0xF0 0x70 \b, quality 2 (Telephone)
+>>10 byte&0xF0 0x80 \b, quality 3 (Thumb)
+>>10 byte&0xF0 0x90 \b, quality 4 (Radio)
+>>10 byte&0xF0 0xA0 \b, quality 5 (Standard)
+>>10 byte&0xF0 0xB0 \b, quality 6 (Xtreme)
+>>10 byte&0xF0 0xC0 \b, quality 7 (Insane)
+>>10 byte&0xF0 0xD0 \b, quality 8 (BrainDead)
+>>10 byte&0xF0 0xE0 \b, quality 9
+>>10 byte&0xF0 0xF0 \b, quality 10
+>>27 byte 0x0 \b, Buschmann 1.7.0-9, Klemm 0.90-1.05
+>>27 byte 102 \b, Beta 1.02
+>>27 byte 104 \b, Beta 1.04
+>>27 byte 105 \b, Alpha 1.05
+>>27 byte 106 \b, Beta 1.06
+>>27 byte 110 \b, Release 1.1
+>>27 byte 111 \b, Alpha 1.11
+>>27 byte 112 \b, Beta 1.12
+>>27 byte 113 \b, Alpha 1.13
+>>27 byte 114 \b, Beta 1.14
+>>27 byte 115 \b, Alpha 1.15
diff --git a/contrib/file/Magdir/cad b/contrib/file/Magdir/cad
index 03263401c70a..757dab6be089 100644
--- a/contrib/file/Magdir/cad
+++ b/contrib/file/Magdir/cad
@@ -35,6 +35,7 @@
>>30 string \120\104 DGNFile
>>30 string \172\104 DGNFile
>>30 string \172\105 DGNFile
+>>30 string \172\106 DGNFile
>>30 string \234\106 DGNFile
>>30 string \273\105 DGNFile
>>30 string \306\106 DGNFile
@@ -52,3 +53,17 @@
0 string AC1012 AutoCad (release 12)
0 string AC1013 AutoCad (release 13)
0 string AC1014 AutoCad (release 14)
+
+# CAD: file(1) magic for computer aided design files
+# Phillip Griffith <phillip dot griffith at gmail dot com>
+# AutoCAD magic taken from the Open Design Alliance's OpenDWG specifications.
+#
+0 belong 0x08051700 Bentley/Intergraph MicroStation DGN cell library
+0 belong 0x0809fe02 Bentley/Intergraph MicroStation DGN vector CAD
+0 belong 0xc809fe02 Bentley/Intergraph MicroStation DGN vector CAD
+0 beshort 0x0809 Bentley/Intergraph MicroStation
+>0x02 byte 0xfe
+>>0x04 beshort 0x1800 CIT raster CAD
+0 string AC1012 AutoDesk AutoCAD R13
+0 string AC1014 AutoDesk AutoCAD R14
+0 string AC1015 AutoDesk AutoCAD R2000
diff --git a/contrib/file/Magdir/cafebabe b/contrib/file/Magdir/cafebabe
new file mode 100644
index 000000000000..233411c80439
--- /dev/null
+++ b/contrib/file/Magdir/cafebabe
@@ -0,0 +1,21 @@
+#------------------------------------------------------------------------------
+# Cafe Babes unite!
+#
+# Since Java bytecode and Mach-O fat-files have the same magic number, the test
+# must be performed in the same "magic" sequence to get both right. The long
+# at offset 4 in a mach-O fat file tells the number of architectures; the short at
+# offset 4 in a Java bytecode file is the JVM minor version and the
+# short at offset 6 is the JVM major version. Since there are only
+# only 18 labeled Mach-O architectures at current, and the first released
+# Java class format was version 43.0, we can safely choose any number
+# between 18 and 39 to test the number of architectures against
+# (and use as a hack). Let's not use 18, because the Mach-O people
+# might add another one or two as time goes by...
+#
+0 belong 0xcafebabe
+>4 belong >30 compiled Java class data,
+>>6 beshort x version %d.
+>>4 beshort x \b%d
+>4 belong 1 Mach-O fat file with 1 architecture
+>4 belong >1
+>>4 belong <20 Mach-O fat file with %ld architectures
diff --git a/contrib/file/Magdir/commands b/contrib/file/Magdir/commands
index 24649844b155..2bdffbebf2bf 100644
--- a/contrib/file/Magdir/commands
+++ b/contrib/file/Magdir/commands
@@ -52,3 +52,5 @@
0 string/b #!\ /usr/bin/php PHP script text executable
0 string Zend\x00 PHP script Zend Optimizer data
+
+0 string \$! DCL command file
diff --git a/contrib/file/Magdir/editors b/contrib/file/Magdir/editors
index 7edbe8bc6b64..02826fa071e1 100644
--- a/contrib/file/Magdir/editors
+++ b/contrib/file/Magdir/editors
@@ -11,3 +11,6 @@
# Vi IMproved Encrypted file
# by David Necas <yeti@physics.muni.cz>
0 string VimCrypt~ Vim encrypted file data
+# Vi IMproved Swap file
+# by Sven Wegener <swegener@gentoo.org>
+0 string b0VIM\ Vim swap file, version %s
diff --git a/contrib/file/Magdir/elf b/contrib/file/Magdir/elf
index 9b559b1ee57b..6c9976f97024 100644
--- a/contrib/file/Magdir/elf
+++ b/contrib/file/Magdir/elf
@@ -84,21 +84,22 @@
>>18 leshort 40 ARM,
>>18 leshort 41 Alpha,
>>18 leshort 0xa390 IBM S/390 (obsolete),
->>18 leshort 42 Hitachi SH,
+>>18 leshort 42 Renesas SH,
>>18 leshort 43 SPARC V9 - invalid byte order,
>>18 leshort 44 Siemens Tricore Embedded Processor,
>>18 leshort 45 Argonaut RISC Core, Argonaut Technologies Inc.,
->>18 leshort 46 Hitachi H8/300,
->>18 leshort 47 Hitachi H8/300H,
->>18 leshort 48 Hitachi H8S,
->>18 leshort 49 Hitachi H8/500,
+>>18 leshort 46 Renesas H8/300,
+>>18 leshort 47 Renesas H8/300H,
+>>18 leshort 48 Renesas H8S,
+>>18 leshort 49 Renesas H8/500,
>>18 leshort 50 IA-64,
>>18 leshort 51 Stanford MIPS-X,
>>18 leshort 52 Motorola Coldfire,
>>18 leshort 53 Motorola M68HC12,
->>18 leshort 62 AMD x86-64,
+>>18 leshort 62 x86-64,
>>18 leshort 75 Digital VAX,
>>18 leshort 88 Renesas M32R,
+>>18 leshort 94 Tensilica Xtensa,
>>18 leshort 97 NatSemi 32k,
>>18 leshort 0x9026 Alpha (unofficial),
>>20 lelong 0 invalid version
@@ -176,14 +177,14 @@
>>18 beshort 39 Motorola RCE,
>>18 beshort 40 ARM,
>>18 beshort 41 Alpha,
->>18 beshort 42 Hitachi SH,
+>>18 beshort 42 Renesas SH,
>>18 beshort 43 SPARC V9,
>>18 beshort 44 Siemens Tricore Embedded Processor,
>>18 beshort 45 Argonaut RISC Core, Argonaut Technologies Inc.,
->>18 beshort 46 Hitachi H8/300,
->>18 beshort 47 Hitachi H8/300H,
->>18 beshort 48 Hitachi H8S,
->>18 beshort 49 Hitachi H8/500,
+>>18 beshort 46 Renesas H8/300,
+>>18 beshort 47 Renesas H8/300H,
+>>18 beshort 48 Renesas H8S,
+>>18 beshort 49 Renesas H8/500,
>>18 beshort 50 IA-64,
>>18 beshort 51 Stanford MIPS-X,
>>18 beshort 52 Motorola Coldfire,
@@ -191,6 +192,7 @@
>>18 beshort 73 Cray NV1,
>>18 beshort 75 Digital VAX,
>>18 beshort 88 Renesas M32R,
+>>18 beshort 94 Tensilica Xtensa,
>>18 beshort 97 NatSemi 32k,
>>18 beshort 0x9026 Alpha (unofficial),
>>18 beshort 0xa390 IBM S/390 (obsolete),
@@ -215,5 +217,8 @@
>>7 byte 10 (Tru64)
>>7 byte 11 (Novell Modesto)
>>7 byte 12 (OpenBSD)
+# VMS Itanium added by gerardo.cacciari@gmail.com
+>8 string \2
+>>7 byte 13 (OpenVMS)
>>7 byte 97 (ARM)
>>7 byte 255 (embedded)
diff --git a/contrib/file/Magdir/filesystems b/contrib/file/Magdir/filesystems
index 1fbe281e3a94..dd4910a99dd5 100644
--- a/contrib/file/Magdir/filesystems
+++ b/contrib/file/Magdir/filesystems
@@ -658,7 +658,7 @@
0x18b string OS/2 OS/2 Boot Manager
-9564 lelong 0x00011954 Unix Fast File system (little-endian),
+9564 lelong 0x00011954 Unix Fast File system [v1] (little-endian),
>8404 string x last mounted on %s,
#>9504 ledate x last checked at %s,
>8224 ledate x last written at %s,
@@ -674,8 +674,48 @@
>8320 lelong 0 TIME optimization
>8320 lelong 1 SPACE optimization
-9564 belong 0x00011954 Unix Fast File system (big-endian),
->7168 long 0x4c41424c Apple UFS Volume
+42332 lelong 0x19540119 Unix Fast File system [v2] (little-endian)
+>&-1164 string x last mounted on %s,
+>&-696 string >\0 volume name %s,
+>&-304 leqldate x last written at %s,
+>&-1167 byte x clean flag %d,
+>&-1168 byte x readonly flag %d,
+>&-296 lequad x number of blocks %lld,
+>&-288 lequad x number of data blocks %lld,
+>&-1332 lelong x number of cylinder groups %d,
+>&-1328 lelong x block size %d,
+>&-1324 lelong x fragment size %d,
+>&-180 lelong x average file size %d,
+>&-176 lelong x average number of files in dir %d,
+>&-272 lequad x pending blocks to free %lld,
+>&-264 lelong x pending inodes to free %ld,
+>&-664 lequad x system-wide uuid %0llx,
+>&-1316 lelong x minimum percentage of free blocks %d,
+>&-1248 lelong 0 TIME optimization
+>&-1248 lelong 1 SPACE optimization
+
+66908 lelong 0x19540119 Unix Fast File system [v2] (little-endian)
+>&-1164 string x last mounted on %s,
+>&-696 string >\0 volume name %s,
+>&-304 leqldate x last written at %s,
+>&-1167 byte x clean flag %d,
+>&-1168 byte x readonly flag %d,
+>&-296 lequad x number of blocks %lld,
+>&-288 lequad x number of data blocks %lld,
+>&-1332 lelong x number of cylinder groups %d,
+>&-1328 lelong x block size %d,
+>&-1324 lelong x fragment size %d,
+>&-180 lelong x average file size %d,
+>&-176 lelong x average number of files in dir %d,
+>&-272 lequad x pending blocks to free %lld,
+>&-264 lelong x pending inodes to free %ld,
+>&-664 lequad x system-wide uuid %0llx,
+>&-1316 lelong x minimum percentage of free blocks %d,
+>&-1248 lelong 0 TIME optimization
+>&-1248 lelong 1 SPACE optimization
+
+9564 belong 0x00011954 Unix Fast File system [v1] (big-endian),
+>7168 belong 0x4c41424c Apple UFS Volume
>>7186 string x named %s,
>>7176 belong x volume label version %d,
>>7180 bedate x created on %s,
@@ -694,6 +734,46 @@
>8320 belong 0 TIME optimization
>8320 belong 1 SPACE optimization
+42332 belong 0x19540119 Unix Fast File system [v2] (big-endian)
+>&-1164 string x last mounted on %s,
+>&-696 string >\0 volume name %s,
+>&-304 beqldate x last written at %s,
+>&-1167 byte x clean flag %d,
+>&-1168 byte x readonly flag %d,
+>&-296 bequad x number of blocks %lld,
+>&-288 bequad x number of data blocks %lld,
+>&-1332 belong x number of cylinder groups %d,
+>&-1328 belong x block size %d,
+>&-1324 belong x fragment size %d,
+>&-180 belong x average file size %d,
+>&-176 belong x average number of files in dir %d,
+>&-272 bequad x pending blocks to free %lld,
+>&-264 belong x pending inodes to free %ld,
+>&-664 bequad x system-wide uuid %0llx,
+>&-1316 belong x minimum percentage of free blocks %d,
+>&-1248 belong 0 TIME optimization
+>&-1248 belong 1 SPACE optimization
+
+66908 belong 0x19540119 Unix Fast File system [v2] (big-endian)
+>&-1164 string x last mounted on %s,
+>&-696 string >\0 volume name %s,
+>&-304 beqldate x last written at %s,
+>&-1167 byte x clean flag %d,
+>&-1168 byte x readonly flag %d,
+>&-296 bequad x number of blocks %lld,
+>&-288 bequad x number of data blocks %lld,
+>&-1332 belong x number of cylinder groups %d,
+>&-1328 belong x block size %d,
+>&-1324 belong x fragment size %d,
+>&-180 belong x average file size %d,
+>&-176 belong x average number of files in dir %d,
+>&-272 bequad x pending blocks to free %lld,
+>&-264 belong x pending inodes to free %ld,
+>&-664 bequad x system-wide uuid %0llx,
+>&-1316 belong x minimum percentage of free blocks %d,
+>&-1248 belong 0 TIME optimization
+>&-1248 belong 1 SPACE optimization
+
# ext2/ext3 filesystems - Andreas Dilger <adilger@turbolabs.com>
0x438 leshort 0xEF53 Linux
>0x44c lelong x rev %d
@@ -783,7 +863,16 @@
#
# CDROM Filesystems
-32769 string CD001 ISO 9660 CD-ROM filesystem data
+# Modified for UDF by gerardo.cacciari@gmail.com
+32769 string CD001
+>38913 string !NSR0 ISO 9660 CD-ROM filesystem data
+>38913 string NSR01 UDF filesystem data (version 1.0)
+>38913 string NSR02 UDF filesystem data (version 1.5)
+>38913 string NSR03 UDF filesystem data (version 2.0)
+>38913 string >NSR03 UDF filesystem data (unknown version,
+>>38917 byte x id 'NSR0%c')
+>38913 string <NSR01 UDF filesystem data (unknown version,
+>>38917 byte x id 'NSR0%c')
# "application id" which appears to be used as a volume label
>32808 string >\0 '%s'
>34816 string \000CD001\001EL\ TORITO\ SPECIFICATION (bootable)
@@ -834,21 +923,25 @@
0 string VoIP\ Startup\ and Aculab VoIP firmware
>35 string x format %s
-# PPCBoot image file
+# u-boot/PPCBoot image file
# From: Mark Brown <broonie@sirena.org.uk>
-0 belong 0x27051956 PPCBoot image
+0 belong 0x27051956 u-boot/PPCBoot image
>4 string PPCBoot
>>12 string x version %s
# JFFS2 file system
-0 leshort 0x1984 Linux old jffs2 filesystem data little endian
-0 lelong 0xe0011985 Linux jffs2 filesystem data little endian
+0 leshort 0x1984 Linux old jffs2 filesystem data little endian
+0 leshort 0x1985 Linux jffs2 filesystem data little endian
# Squashfs
0 string sqsh Squashfs filesystem, big endian,
>28 beshort x version %d.
>30 beshort x \b%d,
->8 belong x %d bytes,
+>28 beshort <3
+>>8 belong x %d bytes,
+>28 beshort >2
+>>63 bequad x %lld bytes,
+#>>67 belong x %d bytes,
>4 belong x %d inodes,
>28 beshort <2
>>32 beshort x blocksize: %d bytes,
@@ -858,7 +951,11 @@
0 string hsqs Squashfs filesystem, little endian,
>28 leshort x version %d.
>30 leshort x \b%d,
->8 lelong x %d bytes,
+>28 leshort <3
+>>8 lelong x %d bytes,
+>28 leshort >2
+>>63 lequad x %lld bytes,
+#>>63 lelong x %d bytes,
>4 lelong x %d inodes,
>28 leshort <2
>>32 leshort x blocksize: %d bytes,
@@ -866,6 +963,8 @@
>>51 lelong x blocksize: %d bytes,
>39 ledate x created: %s
+0 string td\000 floppy image data (TeleDisk)
+
# AFS Dump Magic
# From: Ty Sarna <tsarna@sarna.org>
0 string \x01\xb3\xa1\x13\x22 AFS Dump
@@ -879,3 +978,11 @@
>>>>>>>>&4 bedate x on: %s
>>>>>>>>&0 bedate =0 full dump
>>>>>>>>&0 bedate !0 incremental since: %s
+
+# VMS backup savesets - gerardo.cacciari@gmail.com
+# had to comment out GEM Image and G3 raw data entries due to conflict
+#0 byte x
+#>(0.s+16) string \x01\x01
+#>>&(&0.b+8) byte 0x42 OpenVMS backup saveset data
+#>>>40 lelong x (block size %d
+#>>>49 string >\0 original name '%s')
diff --git a/contrib/file/Magdir/images b/contrib/file/Magdir/images
index 70fd84c2941d..155e99efbac8 100644
--- a/contrib/file/Magdir/images
+++ b/contrib/file/Magdir/images
@@ -267,9 +267,6 @@
#
0 beshort 0x1010 PEX Binary Archive
-# Visio drawings
-03000 string Visio\ (TM)\ Drawing %s
-
# Tgif files
0 string \%TGIF\ x Tgif file version %s
@@ -526,3 +523,8 @@
# specifications at http://hdf.ncsa.uiuc.edu/
0 belong 0x0e031301 Hierarchical Data Format (version 4) data
0 string \211HDF\r\n\032 Hierarchical Data Format (version 5) data
+
+# From: Tobias Burnus <burnus@net-b.de>
+# Xara (for a while: Corel Xara) is a graphic package, see
+# http://www.xara.com/ for Windows and as GPL application for
+0 string XARA\243\243 Xara graphics file
diff --git a/contrib/file/Magdir/java b/contrib/file/Magdir/java
index f9b70915f60d..7aa22a6adb43 100644
--- a/contrib/file/Magdir/java
+++ b/contrib/file/Magdir/java
@@ -1,10 +1,7 @@
#------------------------------------------------------------
-# Java ByteCode
-# From Larry Schwimmer (schwim@cs.stanford.edu)
-# Handled in Mach now
-#0 belong 0xcafebabe compiled Java class data,
-#>6 beshort x version %d.
-#>4 beshort x \b%d
+# Java ByteCode and Mach-O binaries (e.g., Mac OS X) use the
+# same magic number, 0xcafebabe, so they are both handled
+# in the entry called "cafebabe".
#------------------------------------------------------------
# Java serialization
# From Martin Pool (m.pool@pharos.com.au)
diff --git a/contrib/file/Magdir/linux b/contrib/file/Magdir/linux
index 36cc24fc2fe9..fc0c42d40cf7 100644
--- a/contrib/file/Magdir/linux
+++ b/contrib/file/Magdir/linux
@@ -229,3 +229,10 @@
0x618 string LVM2\ 001 LVM2 (Linux Logical Volume Manager)
>(0x614.l+0x600) string >\0 , UUID: %s
+
+# SE Linux policy database
+0 lelong 0xf97cff8c SE Linux policy
+>16 lelong x v%d
+>20 lelong 1 MLS
+>24 lelong x %d symbols
+>28 lelong x %d ocons
diff --git a/contrib/file/Magdir/mach b/contrib/file/Magdir/mach
index 6289a2da8a8b..cced3a587323 100644
--- a/contrib/file/Magdir/mach
+++ b/contrib/file/Magdir/mach
@@ -1,26 +1,9 @@
-#------------------------------------------------------------------------------
-# mach file description
-#
-# Since Java bytecode and Mach-O fat-files have the same magic number the test
-# must be preformed in the same "magic" sequence to get both right. The long
-# at offset 4 in a fat file tells the number of architectures. The short at
-# offset 4 in a Java bytecode file is the compiler minor version and the
-# short at offset 6 is the compiler major version. Since there are only
-# only 18 labeled Mach-O architectures at current, and the first released
-# Java class format was version 43.0, we can safely choose any number
-# between 18 and 39 to test the number of architectures against
-# (and use as a hack).
-#
-0 belong 0xcafebabe
->4 belong >19 compiled Java class data,
->>6 beshort x version %d.
->>4 beshort x \b%d
->4 belong 1 Mach-O fat file with 1 architecture
->4 belong >1
-# The following is necessary to support java class files.
->>4 belong <20 Mach-O fat file with %ld architectures
-#>>4 belong <0xffff Mach-O fat file with %ld architectures
-#
+#------------------------------------------------------------
+# Mach has two magic numbers, 0xcafebabe and 0xfeedface.
+# Unfortunately the first, cafebabe, is shared with
+# Java ByteCode, so they are both handled in the file "cafebabe".
+# The "feedface" ones are handled herein.
+#------------------------------------------------------------
0 lelong&0xfeffffff 0xfeedface Mach-O
>0 byte 0xcf 64-bit
>12 lelong 1 object
diff --git a/contrib/file/Magdir/misctools b/contrib/file/Magdir/misctools
index d3fa270cdf65..488779c56c67 100644
--- a/contrib/file/Magdir/misctools
+++ b/contrib/file/Magdir/misctools
@@ -8,3 +8,6 @@
# From: Alex Beregszaszi <alex@fsn.hu>
4 string gtktalog GNOME Catalogue (gtktalog)
>13 string >\0 version %s
+
+# From: Tomasz Trojanowski <tomek@uninet.com.pl>
+0 search/80 .la\ -\ a\ libtool\ library\ file libtool library file
diff --git a/contrib/file/Magdir/msdos b/contrib/file/Magdir/msdos
index c02ca99353a9..4f226dd9bc94 100644
--- a/contrib/file/Magdir/msdos
+++ b/contrib/file/Magdir/msdos
@@ -86,6 +86,7 @@
>>>>(0x3c.l+4) leshort 0x290 PA-RISC
>>>>(0x3c.l+22) leshort&0x0100 >0 32-bit
>>>>(0x3c.l+22) leshort&0x1000 >0 system file
+>>>>(0x3c.l+232) lelong >0 Mono/.Net assembly
>>>>(0x3c.l+0xf8) string UPX0 \b, UPX compressed
>>>>(0x3c.l+0xf8) search/0x140 PEC2 \b, PECompact2 compressed
@@ -358,6 +359,8 @@
>30 byte 12 (4kB sectors)
# Popular applications
+# False positive with PPT
+#0 string \xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3E\x00\x03\x00\xFE\xFF Microsoft Installer
2080 string Microsoft\ Word\ 6.0\ Document %s
2080 string Documento\ Microsoft\ Word\ 6 Spanish Microsoft Word 6 document data
# Pawel Wiecek <coven@i17linuxb.ists.pwr.wroc.pl> (for polish Word)
@@ -368,7 +371,6 @@
0 string PO^Q` Microsoft Word 6.0 Document
#
0 string \376\067\0\043 Microsoft Office Document
-0 string \320\317\021\340\241\261\032\341 Microsoft Office Document
0 string \333\245-\0\0\0 Microsoft Office Document
#
2080 string Microsoft\ Excel\ 5.0\ Worksheet %s
@@ -590,10 +592,16 @@
>>(64.l) lestring16 >0 Description: %15.15s
# From: Alex Beregszaszi <alex@fsn.hu>
-0 string COWD VMWare3 disk image
->12 belong x %d bytes
+0 string COWD VMWare3
+>4 byte 3 disk image
+>>32 lelong x (%d/
+>>36 lelong x \b%d/
+>>40 lelong x \b%d)
+>4 byte 2 undoable disk image
+>>32 string >\0 (%s)
0 string VMDK VMware4 disk image
+0 string KDMV VMware4 disk image
0 belong 0x514649fb QEMU Copy-On-Write disk image
>4 belong x version %d,
@@ -607,3 +615,7 @@
>48 string x subtype %s
0 lelong 0x02468ace Bochs Sparse disk image
+
+# from http://filext.com by Derek M Jones <derek@knosof.co.uk>
+0 string \xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3E\x00\x03\x00\xFE\xFF Microsoft Installer
+0 string \320\317\021\340\241\261\032\341 Microsoft Office Document
diff --git a/contrib/file/Magdir/os400 b/contrib/file/Magdir/os400
new file mode 100644
index 000000000000..bee366065123
--- /dev/null
+++ b/contrib/file/Magdir/os400
@@ -0,0 +1,32 @@
+#------------------------------------------------------------------------------
+# os400: file(1) magic for IBM OS/400 files
+
+# IBM OS/400 (i5/OS) Save file (SAVF) - gerardo.cacciari@gmail.com
+# In spite of its quite variable format (due to internal memory page
+# length differences between CISC and RISC versions of the OS) the
+# SAVF structure hasn't suitable offsets to identify the catalog
+# header in the first descriptor where there are some useful infos,
+# so we must search in a somewhat large area for a particular string
+# that represents the EBCDIC encoding of 'QSRDSSPC' (save/restore
+# descriptor space) preceded by a two byte constant.
+40 string @@@@@@@@
+>1089 search/7394 \x19\xDB\xD8\xE2\xD9\xC4\xE2\xE2\xD7\xC3 IBM OS/400 save file data
+>>&212 byte 0x01 \b, created with SAVOBJ
+>>&212 byte 0x02 \b, created with SAVLIB
+>>&212 byte 0x07 \b, created with SAVCFG
+>>&212 byte 0x0B \b, created with SAVDLO
+>>&213 byte 0x43 \b, at least V5R3 to open
+>>&213 byte 0x42 \b, at least V5R2 to open
+>>&213 byte 0x41 \b, at least V5R1 to open
+>>&213 byte 0x40 \b, at least V4R5 to open
+>>&213 byte 0x3F \b, at least V4R4 to open
+>>&213 byte 0x3E \b, at least V4R3 to open
+>>&213 byte 0x3C \b, at least V4R2 to open
+>>&213 byte 0x3D \b, at least V4R1M4 to open
+>>&213 byte 0x3B \b, at least V4R1 to open
+>>&213 byte 0x3A \b, at least V3R7 to open
+>>&213 byte 0x35 \b, at least V3R6 to open
+>>&213 byte 0x36 \b, at least V3R2 to open
+>>&213 byte 0x34 \b, at least V3R1 to open
+>>&213 byte 0x31 \b, at least V3R0M5 to open
+>>&213 byte 0x30 \b, at least V2R3 to open
diff --git a/contrib/file/Magdir/python b/contrib/file/Magdir/python
index 5aea137f289d..9fac2b9ae707 100644
--- a/contrib/file/Magdir/python
+++ b/contrib/file/Magdir/python
@@ -13,6 +13,7 @@
0 belong 0x2ded0d0a python 2.2 byte-compiled
0 belong 0x3bf20d0a python 2.3 byte-compiled
0 belong 0x6df20d0a python 2.4 byte-compiled
+0 belong 0xb3f20d0a python 2.5 byte-compiled
0 string/b #!\ /usr/bin/python python script text executable
diff --git a/contrib/file/Magdir/riff b/contrib/file/Magdir/riff
index 1f1deeca3b42..5aa9d109388d 100644
--- a/contrib/file/Magdir/riff
+++ b/contrib/file/Magdir/riff
@@ -29,6 +29,8 @@
>8 string RMID \b, MIDI
# RIFF Multimedia Movie File format
>8 string RMMP \b, multimedia movie
+# RIFF wrapper for MP3
+>8 string RMP3 \b, MPEG Layer 3 audio
# Microsoft WAVE format (*.wav)
>8 string WAVE \b, WAVE audio
>>20 leshort 1 \b, Microsoft PCM
@@ -120,6 +122,7 @@
>>>>>>>(104.l+132) string/c iv50 Indeo 5.0
>>>>>>>(104.l+132) string/c mp42 Microsoft MPEG-4 v2
>>>>>>>(104.l+132) string/c mp43 Microsoft MPEG-4 v3
+>>>>>>>(104.l+132) string/c fmp4 FFMpeg MPEG-4
>>>>>>>(104.l+132) string/c mjpg Motion JPEG
>>>>>>>(104.l+132) string/c div3 DivX 3
>>>>>>>>112 string/c div3 Low-Motion
@@ -127,6 +130,7 @@
>>>>>>>(104.l+132) string/c divx DivX 4
>>>>>>>(104.l+132) string/c dx50 DivX 5
>>>>>>>(104.l+132) string/c xvid XviD
+>>>>>>>(104.l+132) string/c wmv3 Windows Media Video 9
>>>>>>>(104.l+132) string/c h264 X.264
>>>>>>>(104.l+132) lelong 0
##>>>>>>>(104.l+132) string x (%.4s)
@@ -138,6 +142,9 @@
>>>>>>>(92.l+172) string strf
>>>>>>>>(92.l+180) leshort 0x0001 uncompressed PCM
>>>>>>>>(92.l+180) leshort 0x0002 ADPCM
+>>>>>>>>(92.l+180) leshort 0x0006 aLaw
+>>>>>>>>(92.l+180) leshort 0x0007 uLaw
+>>>>>>>>(92.l+180) leshort 0x0050 MPEG-1 Layer 1 or 2
>>>>>>>>(92.l+180) leshort 0x0055 MPEG-1 Layer 3
>>>>>>>>(92.l+180) leshort 0x2000 Dolby AC3
>>>>>>>>(92.l+180) leshort 0x0161 DivX
diff --git a/contrib/file/Magdir/sun b/contrib/file/Magdir/sun
index 4c43b27a792b..871071e9996b 100644
--- a/contrib/file/Magdir/sun
+++ b/contrib/file/Magdir/sun
@@ -12,10 +12,12 @@
>>20 belong >4096 dynamically linked executable
>0 byte ^0x80 executable
>16 belong >0 not stripped
+
0 belong&077777777 0600410 sparc pure
>0 byte &0x80 dynamically linked executable
>0 byte ^0x80 executable
>16 belong >0 not stripped
+
0 belong&077777777 0600407 sparc
>0 byte &0x80 dynamically linked executable
>0 byte ^0x80 executable
@@ -26,11 +28,14 @@
>>20 belong <4096 shared library
>>20 belong =4096 dynamically linked executable
>>20 belong >4096 dynamically linked executable
+>0 byte ^0x80 executable
>16 belong >0 not stripped
+
0 belong&077777777 0400410 mc68020 pure
>0 byte &0x80 dynamically linked executable
>0 byte ^0x80 executable
>16 belong >0 not stripped
+
0 belong&077777777 0400407 mc68020
>0 byte &0x80 dynamically linked executable
>0 byte ^0x80 executable
@@ -41,11 +46,14 @@
>>20 belong <4096 shared library
>>20 belong =4096 dynamically linked executable
>>20 belong >4096 dynamically linked executable
+>0 byte ^0x80 executable
>16 belong >0 not stripped
+
0 belong&077777777 0200410 mc68010 pure
>0 byte &0x80 dynamically linked executable
>0 byte ^0x80 executable
>16 belong >0 not stripped
+
0 belong&077777777 0200407 mc68010
>0 byte &0x80 dynamically linked executable
>0 byte ^0x80 executable
diff --git a/contrib/file/Magdir/sysex b/contrib/file/Magdir/sysex
index e2a4bd827d2e..03d6cdd6b78a 100644
--- a/contrib/file/Magdir/sysex
+++ b/contrib/file/Magdir/sysex
@@ -11,7 +11,28 @@
>1 byte 0x04 Moog
>1 byte 0x05 Passport
>1 byte 0x06 Lexicon
->1 byte 0x07 Kurzweil
+>1 byte 0x07 Kurzweil/Future Retro
+>>3 byte 0x77 777
+>>4 byte 0x00 Bank
+>>4 byte 0x01 Song
+>>5 byte 0x0f 16
+>>5 byte 0x0e 15
+>>5 byte 0x0d 14
+>>5 byte 0x0c 13
+>>5 byte 0x0b 12
+>>5 byte 0x0a 11
+>>5 byte 0x09 10
+>>5 byte 0x08 9
+>>5 byte 0x07 8
+>>5 byte 0x06 7
+>>5 byte 0x05 6
+>>5 byte 0x04 5
+>>5 byte 0x03 4
+>>5 byte 0x02 3
+>>5 byte 0x01 2
+>>5 byte 0x00 1
+>>5 byte 0x10 (ALL)
+>>2 byte x \b, Channel %d
>1 byte 0x08 Fender
>1 byte 0x09 Gulbransen
>1 byte 0x0a AKG
@@ -21,6 +42,12 @@
>1 byte 0x0e Garfield
>1 byte 0x0f Ensoniq
>1 byte 0x10 Oberheim
+>>2 byte 0x06 Matrix 6 series
+>>3 byte 0x0A Dump (All)
+>>3 byte 0x01 Dump (Bank)
+>>4 belong 0x0002040E Matrix 1000
+>>>11 byte <2 User bank %d
+>>>11 byte >1 Preset bank %d
>1 byte 0x11 Apple
>1 byte 0x12 GreyMatter
>1 byte 0x14 PalmTree
@@ -52,11 +79,107 @@
>>3 byte 0x09 EK-44
>1 byte 0x30 Dynacord
+>1 byte 0x31 Jomox
>1 byte 0x33 Clavia
>1 byte 0x39 Soundcraft
-
+# Some Waldorf info from http://Stromeko.Synth.net/Downloads#WaldorfDocs
>1 byte 0x3e Waldorf
+>>2 byte 0x00 microWave
+>>2 byte 0x0E microwave2 / XT
+>>2 byte 0x0F Q / Q+
+>>3 byte =0 (default id)
+>>3 byte >0 (
+>>>3 byte <0x7F \bdevice %d)
+>>>3 byte =0x7F \bbroadcast id)
>>3 byte 0x7f Microwave I
+>>>4 byte 0x00 SNDR (Sound Request)
+>>>4 byte 0x10 SNDD (Sound Dump)
+>>>4 byte 0x20 SNDP (Sound Parameter Change)
+>>>4 byte 0x30 SNDQ (Sound Parameter Inquiry)
+>>>4 byte 0x70 BOOT (Sound Reserved)
+>>>4 byte 0x01 MULR (Multi Request)
+>>>4 byte 0x11 MULD (Multi Dump)
+>>>4 byte 0x21 MULP (Multi Parameter Change)
+>>>4 byte 0x31 MULQ (Multi Parameter Inquiry)
+>>>4 byte 0x71 OS (Multi Reserved)
+>>>4 byte 0x02 DRMR (Drum Map Request)
+>>>4 byte 0x12 DRMD (Drum Map Dump)
+>>>4 byte 0x22 DRMP (Drum Map Parameter Change)
+>>>4 byte 0x32 DRMQ (Drum Map Parameter Inquiry)
+>>>4 byte 0x72 BIN (Drum Map Reserved)
+>>>4 byte 0x03 PATR (Sequencer Pattern Request)
+>>>4 byte 0x13 PATD (Sequencer Pattern Dump)
+>>>4 byte 0x23 PATP (Sequencer Pattern Parameter Change)
+>>>4 byte 0x33 PATQ (Sequencer Pattern Parameter Inquiry)
+>>>4 byte 0x73 AFM (Sequencer Pattern Reserved)
+>>>4 byte 0x04 GLBR (Global Parameter Request)
+>>>4 byte 0x14 GLBD (Global Parameter Dump)
+>>>4 byte 0x24 GLBP (Global Parameter Parameter Change)
+>>>4 byte 0x34 GLBQ (Global Parameter Parameter Inquiry)
+>>>4 byte 0x07 MODR (Mode Parameter Request)
+>>>4 byte 0x17 MODD (Mode Parameter Dump)
+>>>4 byte 0x27 MODP (Mode Parameter Parameter Change)
+>>>4 byte 0x37 MODQ (Mode Parameter Parameter Inquiry)
+>>2 byte 0x10 microQ
+>>>4 byte 0x00 SNDR (Sound Request)
+>>>4 byte 0x10 SNDD (Sound Dump)
+>>>4 byte 0x20 SNDP (Sound Parameter Change)
+>>>4 byte 0x30 SNDQ (Sound Parameter Inquiry)
+>>>4 byte 0x70 (Sound Reserved)
+>>>4 byte 0x01 MULR (Multi Request)
+>>>4 byte 0x11 MULD (Multi Dump)
+>>>4 byte 0x21 MULP (Multi Parameter Change)
+>>>4 byte 0x31 MULQ (Multi Parameter Inquiry)
+>>>4 byte 0x71 OS (Multi Reserved)
+>>>4 byte 0x02 DRMR (Drum Map Request)
+>>>4 byte 0x12 DRMD (Drum Map Dump)
+>>>4 byte 0x22 DRMP (Drum Map Parameter Change)
+>>>4 byte 0x32 DRMQ (Drum Map Parameter Inquiry)
+>>>4 byte 0x72 BIN (Drum Map Reserved)
+>>>4 byte 0x04 GLBR (Global Parameter Request)
+>>>4 byte 0x14 GLBD (Global Parameter Dump)
+>>>4 byte 0x24 GLBP (Global Parameter Parameter Change)
+>>>4 byte 0x34 GLBQ (Global Parameter Parameter Inquiry)
+>>2 byte 0x11 rackAttack
+>>>4 byte 0x00 SNDR (Sound Parameter Request)
+>>>4 byte 0x10 SNDD (Sound Parameter Dump)
+>>>4 byte 0x20 SNDP (Sound Parameter Parameter Change)
+>>>4 byte 0x30 SNDQ (Sound Parameter Parameter Inquiry)
+>>>4 byte 0x01 PRGR (Program Parameter Request)
+>>>4 byte 0x11 PRGD (Program Parameter Dump)
+>>>4 byte 0x21 PRGP (Program Parameter Parameter Change)
+>>>4 byte 0x31 PRGQ (Program Parameter Parameter Inquiry)
+>>>4 byte 0x71 OS (Program Parameter Reserved)
+>>>4 byte 0x03 PATR (Pattern Parameter Request)
+>>>4 byte 0x13 PATD (Pattern Parameter Dump)
+>>>4 byte 0x23 PATP (Pattern Parameter Parameter Change)
+>>>4 byte 0x33 PATQ (Pattern Parameter Parameter Inquiry)
+>>>4 byte 0x04 GLBR (Global Parameter Request)
+>>>4 byte 0x14 GLBD (Global Parameter Dump)
+>>>4 byte 0x24 GLBP (Global Parameter Parameter Change)
+>>>4 byte 0x34 GLBQ (Global Parameter Parameter Inquiry)
+>>>4 byte 0x05 EFXR (FX Parameter Request)
+>>>4 byte 0x15 EFXD (FX Parameter Dump)
+>>>4 byte 0x25 EFXP (FX Parameter Parameter Change)
+>>>4 byte 0x35 EFXQ (FX Parameter Parameter Inquiry)
+>>>4 byte 0x07 MODR (Mode Command Request)
+>>>4 byte 0x17 MODD (Mode Command Dump)
+>>>4 byte 0x27 MODP (Mode Command Parameter Change)
+>>>4 byte 0x37 MODQ (Mode Command Parameter Inquiry)
+>>2 byte 0x03 Wave
+>>>4 byte 0x00 SBPR (Soundprogram)
+>>>4 byte 0x01 SAPR (Performance)
+>>>4 byte 0x02 SWAVE (Wave)
+>>>4 byte 0x03 SWTBL (Wave control table)
+>>>4 byte 0x04 SVT (Velocity Curve)
+>>>4 byte 0x05 STT (Tuning Table)
+>>>4 byte 0x06 SGLB (Global Parameters)
+>>>4 byte 0x07 SARRMAP (Performance Program Change Map)
+>>>4 byte 0x08 SBPRMAP (Sound Program Change Map)
+>>>4 byte 0x09 SBPRPAR (Sound Parameter)
+>>>4 byte 0x0A SARRPAR (Performance Parameter)
+>>>4 byte 0x0B SINSPAR (Instrument/External Parameter)
+>>>4 byte 0x0F SBULK (Bulk Switch on/off)
# Japanese Group
>1 byte 0x40 Kawai
diff --git a/contrib/file/Magdir/unicode b/contrib/file/Magdir/unicode
new file mode 100644
index 000000000000..45a32d4536b7
--- /dev/null
+++ b/contrib/file/Magdir/unicode
@@ -0,0 +1,15 @@
+
+#---------------------------------------------------------------------------
+# Unicode: BOM prefixed text files - Adrian Havill <havill@turbolinux.co.jp>
+#
+0 string +/v8 Unicode text, UTF-7
+0 string +/v9 Unicode text, UTF-7
+0 string +/v+ Unicode text, UTF-7
+0 string +/v/ Unicode text, UTF-7
+0 string \357\273\277 Unicode text, UTF-8
+0 string \335\163\146\163 Unicode text, UTF-8-EBCDIC
+0 string \376\377\000\000 Unicode text, UTF-32, big-endian
+0 string \377\376\000\000 Unicode text, UTF-32, little-endian
+0 string \376\377 Unicode text, UTF-16, big-endian
+0 string \377\376 Unicode text, UTF-16, little-endian
+0 string \016\376\377 Unicode text, SCSU (Standard Compression Scheme for Unicode)
diff --git a/contrib/file/Magdir/vmware b/contrib/file/Magdir/vmware
index 6af543c435de..28e19e57a899 100644
--- a/contrib/file/Magdir/vmware
+++ b/contrib/file/Magdir/vmware
@@ -3,10 +3,3 @@
# VMware specific files (deducted from version 1.1 and log file entries)
# Anthon van der Neut (anthon@mnt.org)
0 belong 0x4d52564e VMware nvram
-0 belong 0x434f5744 VMware
->4 byte 3 virtual disk
->>32 lelong x (%d/
->>36 lelong x \b%d/
->>40 lelong x \b%d)
->4 byte 2 undoable disk
->>32 string >\0 (%s)
diff --git a/contrib/file/Magdir/wordprocessors b/contrib/file/Magdir/wordprocessors
index 369fd40cfd6e..9c06d8d6cba9 100644
--- a/contrib/file/Magdir/wordprocessors
+++ b/contrib/file/Magdir/wordprocessors
@@ -104,7 +104,9 @@
#end of WordPerfect type files Version 1.6 - PLEASE DO NOT REMOVE THIS LINE
# Hangul (Korean) Word Processor File
-0 string HWP\ Document\ File Hangul (Korean) Word Processor File
+0 string HWP\ Document\ File Hangul (Korean) Word Processor File 3.0
+# From: Won-Kyu Park <wkpark@kldp.org>
+512 string R\0o\0o\0t\0 Hangul (Korean) Word Processor File 2000
# CosmicBook, from Benoît Rouits
0 string CSBK Ted Neslson's CosmicBook hypertext file
@@ -115,3 +117,20 @@
0 string \\1cw\ ChiWriter file
>5 string >\0 version %s
0 string \\1cw ChiWriter file
+
+# Quark Express from http://www.garykessler.net/library/file_sigs.html
+2 string IIXPR3 Intel Quark Express Document (English)
+2 string IIXPRa Intel Quark Express Document (Korean)
+2 string MMXPR3 Motorola Quark Express Document (English)
+2 string MMXPRa Motorola Quark Express Document (Korean)
+
+# adobe indesign (document, whatever...) from querkan
+0 belong 0x0606edf5 Adobe InDesign
+>16 string DOCUMENT Document
+
+# From: Michael Piefel <piefel@debian.org>
+# sqtroff intermediate language (replacement for ditroff int. lang.)
+0 string X\ 495 SoftQuad troff Context intermediate for AT&T 495 laser printer
+0 string X\ hp SoftQuad troff Context intermediate for HP LaserJet
+0 string X\ impr SoftQuad troff Context intermediate for IMAGEN imPRESS
+0 string X\ ps SoftQuad troff Context intermediate for PostScript
diff --git a/contrib/file/Magdir/xwindows b/contrib/file/Magdir/xwindows
index 1805d45b9282..57f3b083f3b3 100644
--- a/contrib/file/Magdir/xwindows
+++ b/contrib/file/Magdir/xwindows
@@ -13,7 +13,7 @@
# xfsdump archive
0 string xFSdump0 xfsdump archive
->8 long x (version %d)
+>8 belong x (version %d)
# Jaleo XFS files
0 long 395726 Jaleo XFS file
diff --git a/contrib/file/Makefile.am b/contrib/file/Makefile.am
index 7b6c73a08086..c7059c56a573 100644
--- a/contrib/file/Makefile.am
+++ b/contrib/file/Makefile.am
@@ -52,6 +52,7 @@ Magdir/bout \
Magdir/bsdi \
Magdir/btsnoop \
Magdir/cad \
+Magdir/cafebabe \
Magdir/c-lang \
Magdir/c64 \
Magdir/cddb \
@@ -143,6 +144,7 @@ Magdir/ocaml \
Magdir/octave \
Magdir/olf \
Magdir/os2 \
+Magdir/os400 \
Magdir/os9 \
Magdir/osf1 \
Magdir/palm \
@@ -194,6 +196,7 @@ Magdir/troff \
Magdir/tuxedo \
Magdir/typeset \
Magdir/unknown \
+Magdir/unicode \
Magdir/uuencode \
Magdir/varied.out \
Magdir/varied.script \
diff --git a/contrib/file/Makefile.in b/contrib/file/Makefile.in
index bee55c84126d..cd265b8e7df8 100644
--- a/contrib/file/Makefile.in
+++ b/contrib/file/Makefile.in
@@ -192,6 +192,7 @@ Magdir/bout \
Magdir/bsdi \
Magdir/btsnoop \
Magdir/cad \
+Magdir/cafebabe \
Magdir/c-lang \
Magdir/c64 \
Magdir/cddb \
@@ -283,6 +284,7 @@ Magdir/ocaml \
Magdir/octave \
Magdir/olf \
Magdir/os2 \
+Magdir/os400 \
Magdir/os9 \
Magdir/osf1 \
Magdir/palm \
@@ -334,6 +336,7 @@ Magdir/troff \
Magdir/tuxedo \
Magdir/typeset \
Magdir/unknown \
+Magdir/unicode \
Magdir/uuencode \
Magdir/varied.out \
Magdir/varied.script \
diff --git a/contrib/file/README b/contrib/file/README
index 0e97732c0742..b4223f4b9cee 100644
--- a/contrib/file/README
+++ b/contrib/file/README
@@ -1,5 +1,5 @@
** README for file(1) Command **
-@(#) $Id: README,v 1.33 2003/05/23 21:31:56 christos Exp $
+@(#) $Id: README,v 1.34 2006/05/03 18:48:33 christos Exp $
This is Release 4.x of Ian Darwin's (copyright but distributable)
file(1) command. This version is the standard "file" command for Linux,
@@ -96,7 +96,8 @@ and does not exist any longer.
From: Kees Zeelenberg
-An MS-Windows (Win32) port of File-3.36 is available from
+An MS-Windows (Win32) port of File-4.17 is available from
http://gnuwin32.sourceforge.net/
+
File is an implementation of the Unix File(1) command.
It knows the 'magic number' of several thousands of file types.
diff --git a/contrib/file/apprentice.c b/contrib/file/apprentice.c
index a5bc4f205ef9..974fae95e2dd 100644
--- a/contrib/file/apprentice.c
+++ b/contrib/file/apprentice.c
@@ -36,6 +36,7 @@
#include <unistd.h>
#endif
#include <string.h>
+#include <assert.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/stat.h>
@@ -45,7 +46,7 @@
#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: apprentice.c,v 1.87 2006/03/02 22:08:57 christos Exp $")
+FILE_RCSID("@(#)$Id: apprentice.c,v 1.100 2006/12/11 21:48:49 christos Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
@@ -86,12 +87,17 @@ struct magic_entry {
uint32_t max_count;
};
+const int file_formats[] = { FILE_FORMAT_STRING };
+const size_t file_nformats = sizeof(file_formats) / sizeof(file_formats[0]);
+const char *file_names[] = { FILE_FORMAT_NAME };
+const size_t file_nnames = sizeof(file_names) / sizeof(file_names[0]);
+
private int getvalue(struct magic_set *ms, struct magic *, const char **);
private int hextoint(int);
private const char *getstr(struct magic_set *, const char *, char *, int,
int *);
private int parse(struct magic_set *, struct magic_entry **, uint32_t *,
- const char *, int);
+ const char *, size_t, int);
private void eatsize(const char **);
private int apprentice_1(struct magic_set *, const char *, int, struct mlist *);
private size_t apprentice_magic_strength(const struct magic *);
@@ -102,11 +108,13 @@ private void byteswap(struct magic *, uint32_t);
private void bs1(struct magic *);
private uint16_t swap2(uint16_t);
private uint32_t swap4(uint32_t);
+private uint64_t swap8(uint64_t);
private char *mkdbname(const char *, char *, size_t, int);
private int apprentice_map(struct magic_set *, struct magic **, uint32_t *,
const char *);
private int apprentice_compile(struct magic_set *, struct magic **, uint32_t *,
const char *);
+private int check_format_type(const char *, int);
private int check_format(struct magic_set *, struct magic *);
private size_t maxmagic = 0;
@@ -186,8 +194,6 @@ apprentice_1(struct magic_set *ms, const char *fn, int action,
mapped = 0;
}
- if (rv == -1)
- return rv;
mapped = rv;
if (magic == NULL || nmagic == 0) {
@@ -197,7 +203,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action,
if ((ml = malloc(sizeof(*ml))) == NULL) {
file_delmagic(magic, mapped, nmagic);
- file_oomem(ms);
+ file_oomem(ms, sizeof(*ml));
return -1;
}
@@ -243,6 +249,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
char *p, *mfn, *afn = NULL;
int file_err, errs = -1;
struct mlist *mlist;
+ static const char mime[] = ".mime";
if (fn == NULL)
fn = getenv("MAGIC");
@@ -250,13 +257,13 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
fn = MAGIC;
if ((fn = mfn = strdup(fn)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, strlen(fn));
return NULL;
}
if ((mlist = malloc(sizeof(*mlist))) == NULL) {
free(mfn);
- file_oomem(ms);
+ file_oomem(ms, sizeof(*mlist));
return NULL;
}
mlist->next = mlist->prev = mlist;
@@ -268,14 +275,15 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
if (*fn == '\0')
break;
if (ms->flags & MAGIC_MIME) {
- if ((afn = malloc(strlen(fn) + 5 + 1)) == NULL) {
+ size_t len = strlen(fn) + sizeof(mime);
+ if ((afn = malloc(len)) == NULL) {
free(mfn);
free(mlist);
- file_oomem(ms);
+ file_oomem(ms, len);
return NULL;
}
(void)strcpy(afn, fn);
- (void)strcat(afn, ".mime");
+ (void)strcat(afn, mime);
fn = afn;
}
file_err = apprentice_1(ms, fn, action, mlist);
@@ -298,49 +306,107 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
return mlist;
}
+/*
+ * Get weight of this magic entry, for sorting purposes.
+ */
private size_t
apprentice_magic_strength(const struct magic *m)
{
+#define MULT 10
+ size_t val = 2 * MULT; /* baseline strength */
+
switch (m->type) {
case FILE_BYTE:
- return 1;
+ val += 1 * MULT;
+ break;
case FILE_SHORT:
case FILE_LESHORT:
case FILE_BESHORT:
- return 2;
+ val += 2 * MULT;
+ break;
case FILE_LONG:
case FILE_LELONG:
case FILE_BELONG:
case FILE_MELONG:
- return 4;
+ val += 4 * MULT;
+ break;
case FILE_PSTRING:
case FILE_STRING:
- case FILE_REGEX:
+ val += m->vallen * MULT;
+ break;
+
case FILE_BESTRING16:
case FILE_LESTRING16:
+ val += m->vallen * MULT / 2;
+ break;
+
case FILE_SEARCH:
- return m->vallen;
+ case FILE_REGEX:
+ val += m->vallen;
+ break;
case FILE_DATE:
case FILE_LEDATE:
case FILE_BEDATE:
case FILE_MEDATE:
- return 4;
-
case FILE_LDATE:
case FILE_LELDATE:
case FILE_BELDATE:
case FILE_MELDATE:
- return 8;
+ val += 4 * MULT;
+ break;
+
+ case FILE_QUAD:
+ case FILE_BEQUAD:
+ case FILE_LEQUAD:
+ case FILE_QDATE:
+ case FILE_LEQDATE:
+ case FILE_BEQDATE:
+ case FILE_QLDATE:
+ case FILE_LEQLDATE:
+ case FILE_BEQLDATE:
+ val += 8 * MULT;
+ break;
default:
- return 0;
+ val = 0;
+ (void)fprintf(stderr, "Bad type %d\n", m->type);
+ abort();
}
+
+ switch (m->reln) {
+ case 'x': /* matches anything penalize */
+ val = 0;
+ break;
+
+ case '!':
+ case '=': /* Exact match, prefer */
+ val += MULT;
+ break;
+
+ case '>':
+ case '<': /* comparison match reduce strength */
+ val -= 2 * MULT;
+ break;
+
+ case '^':
+ case '&': /* masking bits, we could count them too */
+ val -= MULT;
+ break;
+
+ default:
+ (void)fprintf(stderr, "Bad relation %c\n", m->reln);
+ abort();
+ }
+ return val;
}
+/*
+ * Sort callback for sorting entries by "strength" (basically length)
+ */
private int
apprentice_sort(const void *a, const void *b)
{
@@ -370,7 +436,10 @@ apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
char line[BUFSIZ+1];
int errs = 0;
struct magic_entry *marray;
- uint32_t marraycount, i, mentrycount;
+ uint32_t marraycount, i, mentrycount = 0;
+ size_t lineno = 0;
+
+ ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */
f = fopen(ms->file = fn, "r");
if (f == NULL) {
@@ -380,10 +449,10 @@ apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
return -1;
}
- maxmagic = MAXMAGIS;
+ maxmagic = MAXMAGIS;
if ((marray = calloc(maxmagic, sizeof(*marray))) == NULL) {
(void)fclose(f);
- file_oomem(ms);
+ file_oomem(ms, maxmagic * sizeof(*marray));
return -1;
}
marraycount = 0;
@@ -392,17 +461,21 @@ apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
if (action == FILE_CHECK)
(void)fprintf(stderr, "%s\n", hdr);
- /* parse it */
+ /* read and parse this file */
for (ms->line = 1; fgets(line, BUFSIZ, f) != NULL; ms->line++) {
size_t len;
- if (line[0] == '#') /* comment, do not parse */
- continue;
len = strlen(line);
- if (len < 2) /* null line, garbage, etc */
+ if (len == 0) /* null line, garbage, etc */
continue;
- if (line[len - 1] == '\n')
+ if (line[len - 1] == '\n') {
+ lineno++;
line[len - 1] = '\0'; /* delete newline */
- if (parse(ms, &marray, &marraycount, line, action) != 0)
+ }
+ if (line[0] == '\0') /* empty, do not parse */
+ continue;
+ if (line[0] == '#') /* comment, do not parse */
+ continue;
+ if (parse(ms, &marray, &marraycount, line, lineno, action) != 0)
errs++;
}
@@ -414,11 +487,11 @@ apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
qsort(marray, marraycount, sizeof(*marray), apprentice_sort);
#endif
- for (i = 0, mentrycount = 0; i < marraycount; i++)
+ for (i = 0; i < marraycount; i++)
mentrycount += marray[i].cont_count;
if ((*magicp = malloc(sizeof(**magicp) * mentrycount)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, sizeof(**magicp) * mentrycount);
errs++;
goto out;
}
@@ -447,8 +520,8 @@ out:
/*
* extend the sign bit if the comparison is to be signed
*/
-protected uint32_t
-file_signextend(struct magic_set *ms, struct magic *m, uint32_t v)
+protected uint64_t
+file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
{
if (!(m->flag & UNSIGNED))
switch(m->type) {
@@ -479,6 +552,17 @@ file_signextend(struct magic_set *ms, struct magic *m, uint32_t v)
case FILE_MELONG:
v = (int32_t) v;
break;
+ case FILE_QUAD:
+ case FILE_BEQUAD:
+ case FILE_LEQUAD:
+ case FILE_QDATE:
+ case FILE_QLDATE:
+ case FILE_BEQDATE:
+ case FILE_BEQLDATE:
+ case FILE_LEQDATE:
+ case FILE_LEQLDATE:
+ v = (int64_t) v;
+ break;
case FILE_STRING:
case FILE_PSTRING:
case FILE_BESTRING16:
@@ -500,15 +584,15 @@ file_signextend(struct magic_set *ms, struct magic *m, uint32_t v)
*/
private int
parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
- const char *line, int action)
+ const char *line, size_t lineno, int action)
{
- int i = 0;
+ size_t i;
struct magic_entry *me;
struct magic *m;
const char *l = line;
char *t;
private const char *fops = FILE_OPS;
- uint32_t val;
+ uint64_t val;
uint32_t cont_level;
cont_level = 0;
@@ -531,7 +615,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
struct magic *nm;
size_t cnt = me->max_count + ALLOC_CHUNK;
if ((nm = realloc(me->mp, sizeof(*nm) * cnt)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, sizeof(*nm) * cnt);
return -1;
}
me->mp = m = nm;
@@ -547,7 +631,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
maxmagic += ALLOC_INCR;
if ((mp = realloc(*mentryp, sizeof(*mp) * maxmagic)) ==
NULL) {
- file_oomem(ms);
+ file_oomem(ms, sizeof(*mp) * maxmagic);
return -1;
}
(void)memset(&mp[*nmentryp], 0, sizeof(*mp) *
@@ -557,7 +641,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
me = &(*mentryp)[*nmentryp];
if (me->mp == NULL) {
if ((m = malloc(sizeof(*m) * ALLOC_CHUNK)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, sizeof(*m) * ALLOC_CHUNK);
return -1;
}
me->mp = m;
@@ -568,6 +652,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
m->cont_level = 0;
me->cont_count = 1;
}
+ m->lineno = lineno;
if (m->cont_level != 0 && *l == '&') {
++l; /* step over */
@@ -690,105 +775,21 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
++l;
EATAB;
-#define NBYTE 4
-#define NSHORT 5
-#define NLONG 4
-#define NSTRING 6
-#define NDATE 4
-#define NBESHORT 7
-#define NBELONG 6
-#define NBEDATE 6
-#define NLESHORT 7
-#define NLELONG 6
-#define NMELONG 6
-#define NLEDATE 6
-#define NMEDATE 6
-#define NPSTRING 7
-#define NLDATE 5
-#define NBELDATE 7
-#define NLELDATE 7
-#define NMELDATE 7
-#define NREGEX 5
-#define NBESTRING16 10
-#define NLESTRING16 10
-#define NSEARCH 6
-
if (*l == 'u') {
++l;
m->flag |= UNSIGNED;
}
/* get type, skip it */
- if (strncmp(l, "char", NBYTE)==0) { /* HP/UX compat */
- m->type = FILE_BYTE;
- l += NBYTE;
- } else if (strncmp(l, "byte", NBYTE)==0) {
- m->type = FILE_BYTE;
- l += NBYTE;
- } else if (strncmp(l, "short", NSHORT)==0) {
- m->type = FILE_SHORT;
- l += NSHORT;
- } else if (strncmp(l, "long", NLONG)==0) {
- m->type = FILE_LONG;
- l += NLONG;
- } else if (strncmp(l, "string", NSTRING)==0) {
- m->type = FILE_STRING;
- l += NSTRING;
- } else if (strncmp(l, "date", NDATE)==0) {
- m->type = FILE_DATE;
- l += NDATE;
- } else if (strncmp(l, "beshort", NBESHORT)==0) {
- m->type = FILE_BESHORT;
- l += NBESHORT;
- } else if (strncmp(l, "belong", NBELONG)==0) {
- m->type = FILE_BELONG;
- l += NBELONG;
- } else if (strncmp(l, "bedate", NBEDATE)==0) {
- m->type = FILE_BEDATE;
- l += NBEDATE;
- } else if (strncmp(l, "leshort", NLESHORT)==0) {
- m->type = FILE_LESHORT;
- l += NLESHORT;
- } else if (strncmp(l, "lelong", NLELONG)==0) {
- m->type = FILE_LELONG;
- l += NLELONG;
- } else if (strncmp(l, "melong", NMELONG)==0) {
- m->type = FILE_MELONG;
- l += NMELONG;
- } else if (strncmp(l, "ledate", NLEDATE)==0) {
- m->type = FILE_LEDATE;
- l += NLEDATE;
- } else if (strncmp(l, "medate", NMEDATE)==0) {
- m->type = FILE_MEDATE;
- l += NMEDATE;
- } else if (strncmp(l, "pstring", NPSTRING)==0) {
- m->type = FILE_PSTRING;
- l += NPSTRING;
- } else if (strncmp(l, "ldate", NLDATE)==0) {
- m->type = FILE_LDATE;
- l += NLDATE;
- } else if (strncmp(l, "beldate", NBELDATE)==0) {
- m->type = FILE_BELDATE;
- l += NBELDATE;
- } else if (strncmp(l, "leldate", NLELDATE)==0) {
- m->type = FILE_LELDATE;
- l += NLELDATE;
- } else if (strncmp(l, "meldate", NMELDATE)==0) {
- m->type = FILE_MELDATE;
- l += NMELDATE;
- } else if (strncmp(l, "regex", NREGEX)==0) {
- m->type = FILE_REGEX;
- l += NREGEX;
- } else if (strncmp(l, "bestring16", NBESTRING16)==0) {
- m->type = FILE_BESTRING16;
- l += NBESTRING16;
- } else if (strncmp(l, "lestring16", NLESTRING16)==0) {
- m->type = FILE_LESTRING16;
- l += NLESTRING16;
- } else if (strncmp(l, "search", NSEARCH)==0) {
- m->type = FILE_SEARCH;
- l += NSEARCH;
- } else {
+ for (i = 0; i < file_nnames; i++) {
+ size_t len = strlen(file_names[i]);
+ if (strncmp(l, file_names[i], len) == 0) {
+ m->type = i;
+ l+= len;
+ break;
+ }
+ }
+ if (i == file_nnames) {
if (ms->flags & MAGIC_CHECK)
file_magwarn(ms, "type `%s' invalid", l);
return -1;
@@ -805,7 +806,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
if (op != FILE_OPDIVIDE || !IS_PLAINSTRING(m->type)) {
++l;
m->mask_op |= op;
- val = (uint32_t)strtoul(l, &t, 0);
+ val = (uint64_t)strtoull(l, &t, 0);
l = t;
m->mask = file_signextend(ms, m, val);
eatsize(&l);
@@ -892,11 +893,20 @@ GetDesc:
m->nospflag = 1;
} else
m->nospflag = 0;
- while ((m->desc[i++] = *l++) != '\0' && i < MAXDESC)
- /* NULLBODY */;
+ for (i = 0; (m->desc[i++] = *l++) != '\0' && i < sizeof(m->desc); )
+ continue;
+ if (i == sizeof(m->desc)) {
+ m->desc[sizeof(m->desc) - 1] = '\0';
+ if (ms->flags & MAGIC_CHECK)
+ file_magwarn(ms, "description `%s' truncated", m->desc);
+ }
- if (ms->flags & MAGIC_CHECK) {
- if (!check_format(ms, m))
+ /*
+ * We only do this check while compiling, or if any of the magic
+ * files were not compiled.
+ */
+ if (ms->flags & MAGIC_CHECK) {
+ if (check_format(ms, m) == -1)
return -1;
}
#ifndef COMPILE_ONLY
@@ -909,6 +919,105 @@ GetDesc:
return 0;
}
+private int
+check_format_type(const char *ptr, int type)
+{
+ int quad = 0;
+ if (*ptr == '\0') {
+ /* Missing format string; bad */
+ return -1;
+ }
+
+ switch (type) {
+ case FILE_FMT_QUAD:
+ quad = 1;
+ /*FALLTHROUGH*/
+ case FILE_FMT_NUM:
+ if (*ptr == '-')
+ ptr++;
+ if (*ptr == '.')
+ ptr++;
+ while (isdigit((unsigned char)*ptr)) ptr++;
+ if (*ptr == '.')
+ ptr++;
+ while (isdigit((unsigned char)*ptr)) ptr++;
+ if (quad) {
+ if (*ptr++ != 'l')
+ return -1;
+ if (*ptr++ != 'l')
+ return -1;
+ }
+
+ switch (*ptr++) {
+ case 'l':
+ switch (*ptr++) {
+ case 'i':
+ case 'd':
+ case 'u':
+ case 'x':
+ case 'X':
+ return 0;
+ default:
+ return -1;
+ }
+
+ case 'h':
+ switch (*ptr++) {
+ case 'h':
+ switch (*ptr++) {
+ case 'i':
+ case 'd':
+ case 'u':
+ case 'x':
+ case 'X':
+ return 0;
+ default:
+ return -1;
+ }
+ case 'd':
+ return 0;
+ default:
+ return -1;
+ }
+
+ case 'i':
+ case 'c':
+ case 'd':
+ case 'u':
+ case 'x':
+ case 'X':
+ return 0;
+
+ default:
+ return -1;
+ }
+
+ case FILE_FMT_STR:
+ if (*ptr == '-')
+ ptr++;
+ while (isdigit((unsigned char )*ptr))
+ ptr++;
+ if (*ptr == '.') {
+ ptr++;
+ while (isdigit((unsigned char )*ptr))
+ ptr++;
+ }
+
+ switch (*ptr++) {
+ case 's':
+ return 0;
+ default:
+ return -1;
+ }
+
+ default:
+ /* internal error */
+ abort();
+ }
+ /*NOTREACHED*/
+ return -1;
+}
+
/*
* Check that the optional printf format in description matches
* the type of the magic.
@@ -916,8 +1025,6 @@ GetDesc:
private int
check_format(struct magic_set *ms, struct magic *m)
{
- static const char *formats[] = { FILE_FORMAT_STRING };
- static const char *names[] = { FILE_FORMAT_NAME };
char *ptr;
for (ptr = m->desc; *ptr; ptr++)
@@ -927,37 +1034,42 @@ check_format(struct magic_set *ms, struct magic *m)
/* No format string; ok */
return 1;
}
- if (m->type >= sizeof(formats)/sizeof(formats[0])) {
- file_magwarn(ms, "Internal error inconsistency between m->type"
- " and format strings");
- return 0;
+
+ assert(file_nformats == file_nnames);
+
+ if (m->type >= file_nformats) {
+ file_error(ms, 0, "Internal error inconsistency between "
+ "m->type and format strings");
+ return -1;
}
- if (formats[m->type] == NULL) {
- file_magwarn(ms, "No format string for `%s' with description "
- "`%s'", m->desc, names[m->type]);
- return 0;
+ if (file_formats[m->type] == FILE_FMT_NONE) {
+ file_error(ms, 0, "No format string for `%s' with description "
+ "`%s'", m->desc, file_names[m->type]);
+ return -1;
+ }
+
+ ptr++;
+ if (check_format_type(ptr, file_formats[m->type]) == -1) {
+ /*
+ * TODO: this error message is unhelpful if the format
+ * string is not one character long
+ */
+ file_error(ms, 0, "Printf format `%c' is not valid for type "
+ " `%s' in description `%s'", *ptr,
+ file_names[m->type], m->desc);
+ return -1;
}
+
for (; *ptr; ptr++) {
- if (*ptr == 'l' || *ptr == 'h') {
- /* XXX: we should really fix this one day */
- continue;
+ if (*ptr == '%') {
+ file_error(ms, 0,
+ "Too many format strings (should have at most one) "
+ "for `%s' with description `%s'",
+ file_names[m->type], m->desc);
+ return -1;
}
- if (islower((unsigned char)*ptr) || *ptr == 'X')
- break;
- }
- if (*ptr == '\0') {
- /* Missing format string; bad */
- file_magwarn(ms, "Invalid format `%s' for type `%s'",
- m->desc, names[m->type]);
- return 0;
}
- if (strchr(formats[m->type], *ptr) == NULL) {
- file_magwarn(ms, "Printf format `%c' is not valid for type `%s'"
- " in description `%s'",
- *ptr, names[m->type], m->desc);
- return 0;
- }
- return 1;
+ return 0;
}
/*
@@ -989,8 +1101,8 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p)
default:
if (m->reln != 'x') {
char *ep;
- m->value.l = file_signextend(ms, m,
- (uint32_t)strtoul(*p, &ep, 0));
+ m->value.q = file_signextend(ms, m,
+ (uint64_t)strtoull(*p, &ep, 0));
*p = ep;
eatsize(p);
}
@@ -1242,7 +1354,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
#define RET 2
#else
if ((mm = malloc((size_t)st.st_size)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, (size_t)st.st_size);
goto error;
}
if (read(fd, mm, (size_t)st.st_size) != (size_t)st.st_size) {
@@ -1396,6 +1508,26 @@ swap4(uint32_t sv)
}
/*
+ * swap a quad
+ */
+private uint64_t
+swap8(uint64_t sv)
+{
+ uint32_t rv;
+ uint8_t *s = (uint8_t *)(void *)&sv;
+ uint8_t *d = (uint8_t *)(void *)&rv;
+ d[0] = s[3];
+ d[1] = s[2];
+ d[2] = s[1];
+ d[3] = s[0];
+ d[4] = s[7];
+ d[5] = s[6];
+ d[6] = s[5];
+ d[7] = s[4];
+ return rv;
+}
+
+/*
* byteswap a single magic entry
*/
private void
@@ -1405,6 +1537,6 @@ bs1(struct magic *m)
m->offset = swap4((uint32_t)m->offset);
m->in_offset = swap4((uint32_t)m->in_offset);
if (!IS_STRING(m->type))
- m->value.l = swap4(m->value.l);
- m->mask = swap4(m->mask);
+ m->value.q = swap8(m->value.q);
+ m->mask = swap8(m->mask);
}
diff --git a/contrib/file/ascmagic.c b/contrib/file/ascmagic.c
index 43d467cd3e22..81525c893be2 100644
--- a/contrib/file/ascmagic.c
+++ b/contrib/file/ascmagic.c
@@ -49,7 +49,7 @@
#include "names.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: ascmagic.c,v 1.45 2006/03/12 22:09:33 christos Exp $")
+FILE_RCSID("@(#)$Id: ascmagic.c,v 1.46 2006/10/20 21:04:15 christos Exp $")
#endif /* lint */
typedef unsigned long unichar;
@@ -102,9 +102,9 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
while (nbytes > 1 && buf[nbytes - 1] == '\0')
nbytes--;
- if ((nbuf = malloc((nbytes + 1) * sizeof(nbuf[0]))) == NULL)
+ if ((nbuf = calloc(1, (nbytes + 1) * sizeof(nbuf[0]))) == NULL)
goto done;
- if ((ubuf = malloc((nbytes + 1) * sizeof(ubuf[0]))) == NULL)
+ if ((ubuf = calloc(1, (nbytes + 1) * sizeof(ubuf[0]))) == NULL)
goto done;
/*
diff --git a/contrib/file/compress.c b/contrib/file/compress.c
index a33c7e9331dc..5989eb295014 100644
--- a/contrib/file/compress.c
+++ b/contrib/file/compress.c
@@ -42,6 +42,7 @@
#include <string.h>
#include <errno.h>
#include <sys/types.h>
+#include <sys/ioctl.h>
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
@@ -50,10 +51,9 @@
#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: compress.c,v 1.42 2005/03/06 05:58:22 christos Exp $")
+FILE_RCSID("@(#)$Id: compress.c,v 1.45 2006/10/31 19:37:17 christos Exp $")
#endif
-
private struct {
const char *magic;
size_t maglen;
@@ -76,9 +76,10 @@ private struct {
private int ncompr = sizeof(compr) / sizeof(compr[0]);
+#define NODATA ((size_t)~0)
+
private ssize_t swrite(int, const void *, size_t);
-private ssize_t sread(int, void *, size_t);
private size_t uncompressbuf(struct magic_set *, int, size_t,
const unsigned char *, unsigned char **, size_t);
#ifdef HAVE_LIBZ
@@ -102,7 +103,7 @@ file_zmagic(struct magic_set *ms, int fd, const unsigned char *buf,
continue;
if (memcmp(buf, compr[i].magic, compr[i].maglen) == 0 &&
(nsz = uncompressbuf(ms, fd, i, buf, &newbuf,
- nbytes)) != 0) {
+ nbytes)) != NODATA) {
ms->flags &= ~MAGIC_COMPRESS;
rv = -1;
if (file_buffer(ms, -1, newbuf, nsz) == -1)
@@ -152,14 +153,52 @@ swrite(int fd, const void *buf, size_t n)
/*
* `safe' read for sockets and pipes.
*/
-private ssize_t
+protected ssize_t
sread(int fd, void *buf, size_t n)
{
int rv;
+#ifdef FIONREAD
+ int t = 0;
+#endif
size_t rn = n;
+ if (fd == STDIN_FILENO)
+ goto nocheck;
+
+#ifdef FIONREAD
+ if ((ioctl(fd, FIONREAD, &t) < 0) || (t == 0)) {
+#ifdef FD_ZERO
+ for (;;) {
+ fd_set check;
+ struct timeval tout = {0, 100 * 1000};
+
+ FD_ZERO(&check);
+ FD_SET(fd, &check);
+
+ /*
+ * Avoid soft deadlock: do not read if there
+ * is nothing to read from sockets and pipes.
+ */
+ if (select(fd + 1, &check, NULL, NULL, &tout) <= 0) {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ return 0;
+ }
+ break;
+ }
+#endif
+ (void)ioctl(fd, FIONREAD, &t);
+ }
+
+ if (t > 0 && (size_t)t < n) {
+ n = t;
+ rn = n;
+ }
+#endif
+
+nocheck:
do
- switch (rv = read(fd, buf, n)) {
+ switch ((rv = read(fd, buf, n))) {
case -1:
if (errno == EINTR)
continue;
@@ -305,7 +344,7 @@ uncompressgzipped(struct magic_set *ms, const unsigned char *old,
inflateEnd(&z);
/* let's keep the nul-terminate tradition */
- (*newch)[n++] = '\0';
+ (*newch)[n] = '\0';
return n;
}
@@ -327,7 +366,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
if ((fd != -1 && pipe(fdin) == -1) || pipe(fdout) == -1) {
file_error(ms, errno, "cannot create pipe");
- return 0;
+ return NODATA;
}
switch (fork()) {
case 0: /* child */
@@ -360,7 +399,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
/*NOTREACHED*/
case -1:
file_error(ms, errno, "could not fork");
- return 0;
+ return NODATA;
default: /* parent */
(void) close(fdout[1]);
@@ -420,7 +459,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
n = r;
}
/* NUL terminate, as every buffer is handled here. */
- (*newch)[n++] = '\0';
+ (*newch)[n] = '\0';
err:
if (fdin[1] != -1)
(void) close(fdin[1]);
diff --git a/contrib/file/config.h.in b/contrib/file/config.h.in
index db66b2b766ce..3fe7a8dd9eb9 100644
--- a/contrib/file/config.h.in
+++ b/contrib/file/config.h.in
@@ -118,6 +118,9 @@
/* Define to 1 if you have the <wchar.h> header file. */
#undef HAVE_WCHAR_H
+/* Define to 1 if you have the <wctype.h> header file. */
+#undef HAVE_WCTYPE_H
+
/* Define to 1 if you have the `wcwidth' function. */
#undef HAVE_WCWIDTH
diff --git a/contrib/file/configure b/contrib/file/configure
index 538dd497207c..f39e9462b348 100755
--- a/contrib/file/configure
+++ b/contrib/file/configure
@@ -1808,7 +1808,7 @@ fi
# Define the identity of the package.
PACKAGE=file
- VERSION=4.17
+ VERSION=4.19
cat >>confdefs.h <<_ACEOF
@@ -20514,610 +20514,11 @@ done
-for ac_header in fcntl.h locale.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
- # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
- (eval $ac_compile) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; } &&
- { ac_try='test -s conftest.$ac_objext'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; }; then
- ac_header_compiler=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
- (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } >/dev/null; then
- if test -s conftest.err; then
- ac_cpp_err=$ac_c_preproc_warn_flag
- ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
- else
- ac_cpp_err=
- fi
-else
- ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
- ac_header_preproc=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
- ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So? What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
- yes:no: )
- { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
- ac_header_preproc=yes
- ;;
- no:yes:* )
- { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
- (
- cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists. ##
-## ------------------------------------------ ##
-_ASBOX
- ) |
- sed "s/^/$as_me: WARNING: /" >&2
- ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
- cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
-
-
-
-
-for ac_header in sys/mman.h sys/stat.h sys/types.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
- # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
- (eval $ac_compile) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; } &&
- { ac_try='test -s conftest.$ac_objext'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; }; then
- ac_header_compiler=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
- (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } >/dev/null; then
- if test -s conftest.err; then
- ac_cpp_err=$ac_c_preproc_warn_flag
- ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
- else
- ac_cpp_err=
- fi
-else
- ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
- ac_header_preproc=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
- ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So? What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
- yes:no: )
- { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
- ac_header_preproc=yes
- ;;
- no:yes:* )
- { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
- (
- cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists. ##
-## ------------------------------------------ ##
-_ASBOX
- ) |
- sed "s/^/$as_me: WARNING: /" >&2
- ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
- cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
-
-
-
-for ac_header in stdint.h inttypes.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
- # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
- (eval $ac_compile) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; } &&
- { ac_try='test -s conftest.$ac_objext'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; }; then
- ac_header_compiler=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
- (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } >/dev/null; then
- if test -s conftest.err; then
- ac_cpp_err=$ac_c_preproc_warn_flag
- ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
- else
- ac_cpp_err=
- fi
-else
- ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
- ac_header_preproc=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
- ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So? What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
- yes:no: )
- { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
- ac_header_preproc=yes
- ;;
- no:yes:* )
- { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
- (
- cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists. ##
-## ------------------------------------------ ##
-_ASBOX
- ) |
- sed "s/^/$as_me: WARNING: /" >&2
- ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
- cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-fi
-
-done
-
-
-for ac_header in unistd.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
- # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
- (eval $ac_compile) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; } &&
- { ac_try='test -s conftest.$ac_objext'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; }; then
- ac_header_compiler=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
- (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } >/dev/null; then
- if test -s conftest.err; then
- ac_cpp_err=$ac_c_preproc_warn_flag
- ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
- else
- ac_cpp_err=
- fi
-else
- ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
- ac_header_preproc=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
- ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So? What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
- yes:no: )
- { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
- ac_header_preproc=yes
- ;;
- no:yes:* )
- { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
- (
- cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists. ##
-## ------------------------------------------ ##
-_ASBOX
- ) |
- sed "s/^/$as_me: WARNING: /" >&2
- ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
- cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-fi
-done
-
-for ac_header in getopt.h
+for ac_header in fcntl.h locale.h stdint.h inttypes.h unistd.h getopt.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
@@ -21267,157 +20668,9 @@ fi
done
-for ac_header in locale.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
- # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
- (eval $ac_compile) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; } &&
- { ac_try='test -s conftest.$ac_objext'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; }; then
- ac_header_compiler=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
- (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } >/dev/null; then
- if test -s conftest.err; then
- ac_cpp_err=$ac_c_preproc_warn_flag
- ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
- else
- ac_cpp_err=
- fi
-else
- ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
- ac_header_preproc=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
- ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So? What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
- yes:no: )
- { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
- ac_header_preproc=yes
- ;;
- no:yes:* )
- { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
- (
- cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists. ##
-## ------------------------------------------ ##
-_ASBOX
- ) |
- sed "s/^/$as_me: WARNING: /" >&2
- ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
- cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-fi
-done
-
-
-for ac_header in utime.h
+for ac_header in utime.h wchar.h wctype.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
@@ -21567,157 +20820,10 @@ fi
done
-for ac_header in sys/utime.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
- # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
- (eval $ac_compile) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; } &&
- { ac_try='test -s conftest.$ac_objext'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; }; then
- ac_header_compiler=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
- (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } >/dev/null; then
- if test -s conftest.err; then
- ac_cpp_err=$ac_c_preproc_warn_flag
- ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
- else
- ac_cpp_err=
- fi
-else
- ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
- ac_header_preproc=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
- ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So? What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
- yes:no: )
- { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
- ac_header_preproc=yes
- ;;
- no:yes:* )
- { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
- (
- cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists. ##
-## ------------------------------------------ ##
-_ASBOX
- ) |
- sed "s/^/$as_me: WARNING: /" >&2
- ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
- cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
-for ac_header in wchar.h
+for ac_header in sys/mman.h sys/stat.h sys/types.h sys/utime.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
diff --git a/contrib/file/configure.in b/contrib/file/configure.in
index 706332ae087a..1ca21c0d4ef2 100644
--- a/contrib/file/configure.in
+++ b/contrib/file/configure.in
@@ -1,7 +1,7 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT
AC_CONFIG_SRCDIR([src/file.c])
-AM_INIT_AUTOMAKE(file, 4.17)
+AM_INIT_AUTOMAKE(file, 4.19)
AM_CONFIG_HEADER([config.h])
AM_MAINTAINER_MODE
@@ -79,15 +79,9 @@ AC_HEADER_STDC
AC_HEADER_MAJOR
AC_HEADER_SYS_WAIT
AC_HEADER_STDINT
-AC_CHECK_HEADERS(fcntl.h locale.h)
-AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h)
-AC_CHECK_HEADERS(stdint.h inttypes.h)
-AC_CHECK_HEADERS(unistd.h)
-AC_CHECK_HEADERS(getopt.h)
-AC_CHECK_HEADERS(locale.h)
-AC_CHECK_HEADERS(utime.h)
-AC_CHECK_HEADERS(sys/utime.h)
-AC_CHECK_HEADERS(wchar.h)
+AC_CHECK_HEADERS(fcntl.h locale.h stdint.h inttypes.h unistd.h getopt.h)
+AC_CHECK_HEADERS(utime.h wchar.h wctype.h)
+AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h sys/utime.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
diff --git a/contrib/file/file.c b/contrib/file/file.c
index a482f63711de..f3fae24eb544 100644
--- a/contrib/file/file.c
+++ b/contrib/file/file.c
@@ -71,7 +71,7 @@
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: file.c,v 1.100 2005/10/17 18:41:44 christos Exp $")
+FILE_RCSID("@(#)$Id: file.c,v 1.104 2006/11/25 17:28:54 christos Exp $")
#endif /* lint */
@@ -81,7 +81,7 @@ FILE_RCSID("@(#)$Id: file.c,v 1.100 2005/10/17 18:41:44 christos Exp $")
#define SYMLINKFLAG ""
#endif
-# define USAGE "Usage: %s [-bcik" SYMLINKFLAG "nNsvz] [-f namefile] [-F separator] [-m magicfiles] file...\n %s -C -m magicfiles\n"
+# define USAGE "Usage: %s [-bcik" SYMLINKFLAG "nNrsvz0] [-f namefile] [-F separator] [-m magicfiles] file...\n %s -C -m magicfiles\n"
#ifndef MAXPATHLEN
#define MAXPATHLEN 512
@@ -90,7 +90,8 @@ FILE_RCSID("@(#)$Id: file.c,v 1.100 2005/10/17 18:41:44 christos Exp $")
private int /* Global command-line options */
bflag = 0, /* brief output format */
nopad = 0, /* Don't pad output */
- nobuffer = 0; /* Do not buffer stdout */
+ nobuffer = 0, /* Do not buffer stdout */
+ nulsep = 0; /* Append '\0' to the separator */
private const char *magicfile = 0; /* where the magic is */
private const char *default_magicfile = MAGIC;
@@ -126,10 +127,11 @@ main(int argc, char *argv[])
int flags = 0;
char *home, *usermagic;
struct stat sb;
-#define OPTSTRING "bcCdf:F:hikLm:nNprsvz"
+ static const char hmagic[] = "/.magic";
+#define OPTSTRING "bcCdf:F:hikLm:nNprsvz0"
#ifdef HAVE_GETOPT_LONG
int longindex;
- private struct option long_options[] =
+ static const struct option long_options[] =
{
{"version", 0, 0, 'v'},
{"help", 0, 0, 0},
@@ -154,6 +156,7 @@ main(int argc, char *argv[])
{"no-pad", 0, 0, 'N'},
{"special-files", 0, 0, 's'},
{"compile", 0, 0, 'C'},
+ {"print0", 0, 0, '0'},
{0, 0, 0, 0},
};
#endif
@@ -178,9 +181,10 @@ main(int argc, char *argv[])
magicfile = usermagic;
else
if ((home = getenv("HOME")) != NULL) {
- if ((usermagic = malloc(strlen(home) + 8)) != NULL) {
+ if ((usermagic = malloc(strlen(home)
+ + sizeof(hmagic))) != NULL) {
(void)strcpy(usermagic, home);
- (void)strcat(usermagic, "/.magic");
+ (void)strcat(usermagic, hmagic);
if (stat(usermagic, &sb)<0)
free(usermagic);
else
@@ -204,6 +208,9 @@ main(int argc, char *argv[])
help();
break;
#endif
+ case '0':
+ nulsep = 1;
+ break;
case 'b':
++bflag;
break;
@@ -385,15 +392,24 @@ unwrap(char *fn)
(void)fclose(f);
}
+/*
+ * Called for each input file on the command line (or in a list of files)
+ */
private void
process(const char *inname, int wid)
{
const char *type;
int std_in = strcmp(inname, "-") == 0;
- if (wid > 0 && !bflag)
- (void)printf("%s%s%*s ", std_in ? "/dev/stdin" : inname,
- separator, (int) (nopad ? 0 : (wid - file_mbswidth(inname))), "");
+ if (wid > 0 && !bflag) {
+ (void)printf("%s", std_in ? "/dev/stdin" : inname);
+ if (nulsep)
+ (void)puts('\0');
+ else
+ (void)printf("%s", separator);
+ (void)printf("%*s ",
+ (int) (nopad ? 0 : (wid - file_mbswidth(inname))), "");
+ }
type = magic_file(magic, std_in ? NULL : inname);
if (type == NULL)
diff --git a/contrib/file/file.h b/contrib/file/file.h
index 8ef2fbaa49bd..bb2fc166dc30 100644
--- a/contrib/file/file.h
+++ b/contrib/file/file.h
@@ -27,7 +27,7 @@
*/
/*
* file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.73 2005/10/20 14:59:01 christos Exp $
+ * @(#)$Id: file.h,v 1.83 2006/12/11 21:48:49 christos Exp $
*/
#ifndef __file_h__
@@ -46,6 +46,7 @@
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
+#include <sys/types.h>
/* Do this here and now, because struct stat gets re-defined on solaris */
#include <sys/stat.h>
@@ -73,7 +74,7 @@
#define MAXstring 32 /* max leng of "string" types */
#define MAGICNO 0xF11E041C
-#define VERSIONNO 2
+#define VERSIONNO 3
#define FILE_MAGICSIZE (32 * 4)
#define FILE_LOAD 0
@@ -116,6 +117,15 @@ struct magic {
#define FILE_MEDATE 21
#define FILE_MELDATE 22
#define FILE_MELONG 23
+#define FILE_QUAD 24
+#define FILE_LEQUAD 25
+#define FILE_BEQUAD 26
+#define FILE_QDATE 27
+#define FILE_LEQDATE 28
+#define FILE_BEQDATE 29
+#define FILE_QLDATE 30
+#define FILE_LEQLDATE 31
+#define FILE_BEQLDATE 32
#define FILE_FORMAT_NAME \
/* 0 */ "invalid 0", \
@@ -141,16 +151,28 @@ struct magic {
/* 20 */ "search", \
/* 21 */ "medate", \
/* 22 */ "meldate", \
-/* 23 */ "melong",
+/* 23 */ "melong", \
+/* 24 */ "quad", \
+/* 25 */ "lequad", \
+/* 26 */ "bequad", \
+/* 27 */ "qdate", \
+/* 28 */ "leqdate", \
+/* 29 */ "beqdate", \
+/* 30 */ "qldate", \
+/* 31 */ "leqldate", \
+/* 32 */ "beqldate",
-#define FILE_FMT_NUM "cduxXi"
-#define FILE_FMT_STR "s"
+
+#define FILE_FMT_NONE 0
+#define FILE_FMT_NUM 1 /* "cduxXi" */
+#define FILE_FMT_STR 2 /* "s" */
+#define FILE_FMT_QUAD 3 /* "ll" */
#define FILE_FORMAT_STRING \
-/* 0 */ NULL, \
+/* 0 */ FILE_FMT_NONE, \
/* 1 */ FILE_FMT_NUM, \
/* 2 */ FILE_FMT_NUM, \
-/* 3 */ NULL, \
+/* 3 */ FILE_FMT_NONE, \
/* 4 */ FILE_FMT_NUM, \
/* 5 */ FILE_FMT_STR, \
/* 6 */ FILE_FMT_STR, \
@@ -170,7 +192,17 @@ struct magic {
/* 20 */ FILE_FMT_STR, \
/* 21 */ FILE_FMT_STR, \
/* 22 */ FILE_FMT_STR, \
-/* 23 */ FILE_FMT_NUM,
+/* 23 */ FILE_FMT_NUM, \
+/* 24 */ FILE_FMT_QUAD, \
+/* 25 */ FILE_FMT_QUAD, \
+/* 26 */ FILE_FMT_QUAD, \
+/* 27 */ FILE_FMT_STR, \
+/* 28 */ FILE_FMT_STR, \
+/* 29 */ FILE_FMT_STR, \
+/* 30 */ FILE_FMT_STR, \
+/* 31 */ FILE_FMT_STR, \
+/* 32 */ FILE_FMT_STR,
+
/* Word 3 */
uint8_t in_op; /* operator for indirection */
@@ -193,16 +225,15 @@ struct magic {
/* Word 5 */
int32_t in_offset; /* offset from indirection */
/* Word 6 */
- uint32_t mask; /* mask before comparison with value */
- /* Word 7 */
- uint32_t dummy3;
- /* Word 8 */
- uint32_t dummp4;
+ uint32_t lineno; /* line number in magic file */
+ /* Word 7,8 */
+ uint64_t mask; /* mask before comparison with value */
/* Words 9-16 */
union VALUETYPE {
uint8_t b;
uint16_t h;
uint32_t l;
+ uint64_t q;
char s[MAXstring];
struct {
char *buf;
@@ -210,6 +241,7 @@ struct magic {
} search;
uint8_t hs[2]; /* 2 bytes of a fixed-endian "short" */
uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */
+ uint8_t hq[8]; /* 8 bytes of a fixed-endian "quad" */
} value; /* either number or string */
/* Words 17..31 */
char desc[MAXDESC]; /* description */
@@ -250,6 +282,7 @@ struct magic_set {
char *pbuf;
size_t psize;
} o;
+ uint32_t offset;
int error;
int flags;
int haderr;
@@ -270,17 +303,23 @@ 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 uint32_t file_signextend(struct magic_set *, struct magic *, uint32_t);
+protected uint64_t file_signextend(struct magic_set *, struct magic *, uint64_t);
protected void file_delmagic(struct magic *, int type, size_t entries);
protected void file_badread(struct magic_set *);
protected void file_badseek(struct magic_set *);
-protected void file_oomem(struct magic_set *);
+protected void file_oomem(struct magic_set *, size_t);
protected void file_error(struct magic_set *, int, const char *, ...);
protected void file_magwarn(struct magic_set *, const char *, ...);
protected void file_mdump(struct magic *);
protected void file_showstr(FILE *, const char *, size_t);
protected size_t file_mbswidth(const char *);
protected const char *file_getbuffer(struct magic_set *);
+protected ssize_t sread(int, void *, size_t);
+
+#ifndef COMPILE_ONLY
+extern const char *file_names[];
+extern const size_t file_nnames;
+#endif
#ifndef HAVE_STRERROR
extern int sys_nerr;
@@ -309,6 +348,5 @@ int snprintf(char *, size_t, const char *, ...);
static const char *rcsid(const char *p) { \
return rcsid(p = id); \
}
-#else
#endif /* __file_h__ */
diff --git a/contrib/file/funcs.c b/contrib/file/funcs.c
index 5ea27f42c12f..824e3a09722e 100644
--- a/contrib/file/funcs.c
+++ b/contrib/file/funcs.c
@@ -33,9 +33,12 @@
#if defined(HAVE_WCHAR_H)
#include <wchar.h>
#endif
+#if defined(HAVE_WCTYPE_H)
+#include <wctype.h>
+#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: funcs.c,v 1.19 2006/03/02 22:10:26 christos Exp $")
+FILE_RCSID("@(#)$Id: funcs.c,v 1.23 2006/12/11 21:48:49 christos Exp $")
#endif /* lint */
#ifndef HAVE_VSNPRINTF
@@ -57,7 +60,7 @@ file_printf(struct magic_set *ms, const char *fmt, ...)
if ((len = vsnprintf(ms->o.ptr, ms->o.len, fmt, ap)) >= ms->o.len) {
va_end(ap);
if ((buf = realloc(ms->o.buf, len + 1024)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, len + 1024);
return -1;
}
ms->o.ptr = buf + (ms->o.ptr - ms->o.buf);
@@ -99,9 +102,9 @@ file_error(struct magic_set *ms, int error, const char *f, ...)
protected void
-file_oomem(struct magic_set *ms)
+file_oomem(struct magic_set *ms, size_t len)
{
- file_error(ms, errno, "cannot allocate memory");
+ file_error(ms, errno, "cannot allocate %zu bytes", len);
}
protected void
@@ -159,11 +162,12 @@ file_reset(struct magic_set *ms)
}
#define OCTALIFY(n, o) \
- *(n)++ = '\\', \
+ /*LINTED*/ \
+ (void)(*(n)++ = '\\', \
*(n)++ = (((uint32_t)*(o) >> 6) & 3) + '0', \
*(n)++ = (((uint32_t)*(o) >> 3) & 7) + '0', \
*(n)++ = (((uint32_t)*(o) >> 0) & 7) + '0', \
- (o)++
+ (o)++)
protected const char *
file_getbuffer(struct magic_set *ms)
@@ -180,7 +184,7 @@ file_getbuffer(struct magic_set *ms)
nsize = ms->o.len * 4 + 1;
if (ms->o.psize < nsize) {
if ((nbuf = realloc(ms->o.pbuf, nsize)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, nsize);
return NULL;
}
ms->o.psize = nsize;
@@ -201,15 +205,15 @@ file_getbuffer(struct magic_set *ms)
eop = op + strlen(ms->o.buf);
while (op < eop) {
- bytesconsumed = mbrtowc(&nextchar, op, eop - op,
- &state);
+ bytesconsumed = mbrtowc(&nextchar, op,
+ (size_t)(eop - op), &state);
if (bytesconsumed == (size_t)(-1) ||
bytesconsumed == (size_t)(-2)) {
mb_conv = 0;
break;
}
- if (iswprint(nextchar) ) {
+ if (iswprint(nextchar)) {
(void)memcpy(np, op, bytesconsumed);
op += bytesconsumed;
np += bytesconsumed;
@@ -238,8 +242,8 @@ file_getbuffer(struct magic_set *ms)
}
/*
- * Yes these suffer from buffer overflows, but if your OS does not have
- * these functions, then maybe you should consider replacing your OS?
+ * Yes these wrappers suffer from buffer overflows, but if your OS does not have
+ * the real functions, maybe you should consider replacing your OS?
*/
#ifndef HAVE_VSNPRINTF
int
diff --git a/contrib/file/install-sh b/contrib/file/install-sh
index 11870f1b0192..4d4a9519eaf8 100755
--- a/contrib/file/install-sh
+++ b/contrib/file/install-sh
@@ -1,19 +1,38 @@
#!/bin/sh
-#
# install - install a program, script, or datafile
-# This comes from X11R5 (mit/util/scripts/install.sh).
+
+scriptversion=2005-05-14.22
+
+# This originates from X11R5 (mit/util/scripts/install.sh), which was
+# later released in X11R6 (xc/config/util/install.sh) with the
+# following copyright and license.
+#
+# Copyright (C) 1994 X Consortium
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
#
-# Copyright 1991 by the Massachusetts Institute of Technology
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
+# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-# Permission to use, copy, modify, distribute, and sell this software and its
-# documentation for any purpose is hereby granted without fee, provided that
-# the above copyright notice appear in all copies and that both that
-# copyright notice and this permission notice appear in supporting
-# documentation, and that the name of M.I.T. not be used in advertising or
-# publicity pertaining to distribution of the software without specific,
-# written prior permission. M.I.T. makes no representations about the
-# suitability of this software for any purpose. It is provided "as is"
-# without express or implied warranty.
+# Except as contained in this notice, the name of the X Consortium shall not
+# be used in advertising or otherwise to promote the sale, use or other deal-
+# ings in this Software without prior written authorization from the X Consor-
+# tium.
+#
+#
+# FSF changes to this file are in the public domain.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
@@ -23,13 +42,11 @@
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
-
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
-
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
@@ -41,211 +58,266 @@ stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
-transformbasename=""
-transform_arg=""
-instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
-chowncmd=""
-chgrpcmd=""
-stripcmd=""
+chowncmd=
+chgrpcmd=
+stripcmd=
rmcmd="$rmprog -f"
mvcmd="$mvprog"
-src=""
-dst=""
-dir_arg=""
-
-while [ x"$1" != x ]; do
- case $1 in
- -c) instcmd="$cpprog"
- shift
- continue;;
-
- -d) dir_arg=true
- shift
- continue;;
-
- -m) chmodcmd="$chmodprog $2"
- shift
- shift
- continue;;
-
- -o) chowncmd="$chownprog $2"
- shift
- shift
- continue;;
-
- -g) chgrpcmd="$chgrpprog $2"
- shift
- shift
- continue;;
-
- -s) stripcmd="$stripprog"
- shift
- continue;;
-
- -t=*) transformarg=`echo $1 | sed 's/-t=//'`
- shift
- continue;;
-
- -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
- shift
- continue;;
-
- *) if [ x"$src" = x ]
- then
- src=$1
- else
- # this colon is to work around a 386BSD /bin/sh bug
- :
- dst=$1
- fi
- shift
- continue;;
- esac
-done
-
-if [ x"$src" = x ]
-then
- echo "install: no input file specified"
- exit 1
-else
- :
-fi
-
-if [ x"$dir_arg" != x ]; then
- dst=$src
- src=""
-
- if [ -d $dst ]; then
- instcmd=:
- chmodcmd=""
- else
- instcmd=$mkdirprog
- fi
-else
-
-# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
-# might cause directories to be created, which would be especially bad
-# if $src (and thus $dsttmp) contains '*'.
-
- if [ -f "$src" ] || [ -d "$src" ]
- then
- :
- else
- echo "install: $src does not exist"
- exit 1
- fi
-
- if [ x"$dst" = x ]
- then
- echo "install: no destination specified"
- exit 1
- else
- :
- fi
-
-# If destination is a directory, append the input filename; if your system
-# does not like double slashes in filenames, you may need to add some logic
-
- if [ -d $dst ]
- then
- dst="$dst"/`basename $src`
- else
- :
- fi
-fi
-
-## this sed command emulates the dirname command
-dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
-
-# Make sure that the destination directory exists.
-# this part is taken from Noah Friedman's mkinstalldirs script
-
-# Skip lots of stat calls in the usual case.
-if [ ! -d "$dstdir" ]; then
-defaultIFS='
- '
-IFS="${IFS-${defaultIFS}}"
-
-oIFS="${IFS}"
-# Some sh's can't handle IFS=/ for some reason.
-IFS='%'
-set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
-IFS="${oIFS}"
-
-pathcomp=''
-
-while [ $# -ne 0 ] ; do
- pathcomp="${pathcomp}${1}"
+src=
+dst=
+dir_arg=
+dstarg=
+no_target_directory=
+
+usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
+ or: $0 [OPTION]... SRCFILES... DIRECTORY
+ or: $0 [OPTION]... -t DIRECTORY SRCFILES...
+ or: $0 [OPTION]... -d DIRECTORIES...
+
+In the 1st form, copy SRCFILE to DSTFILE.
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
+In the 4th, create DIRECTORIES.
+
+Options:
+-c (ignored)
+-d create directories instead of installing files.
+-g GROUP $chgrpprog installed files to GROUP.
+-m MODE $chmodprog installed files to MODE.
+-o USER $chownprog installed files to USER.
+-s $stripprog installed files.
+-t DIRECTORY install into DIRECTORY.
+-T report an error if DSTFILE is a directory.
+--help display this help and exit.
+--version display version info and exit.
+
+Environment variables override the default commands:
+ CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
+"
+
+while test -n "$1"; do
+ case $1 in
+ -c) shift
+ continue;;
+
+ -d) dir_arg=true
+ shift
+ continue;;
+
+ -g) chgrpcmd="$chgrpprog $2"
+ shift
+ shift
+ continue;;
+
+ --help) echo "$usage"; exit $?;;
+
+ -m) chmodcmd="$chmodprog $2"
+ shift
+ shift
+ continue;;
+
+ -o) chowncmd="$chownprog $2"
+ shift
+ shift
+ continue;;
+
+ -s) stripcmd=$stripprog
+ shift
+ continue;;
+
+ -t) dstarg=$2
shift
+ shift
+ continue;;
- if [ ! -d "${pathcomp}" ] ;
- then
- $mkdirprog "${pathcomp}"
- else
- :
- fi
-
- pathcomp="${pathcomp}/"
+ -T) no_target_directory=true
+ shift
+ continue;;
+
+ --version) echo "$0 $scriptversion"; exit $?;;
+
+ *) # When -d is used, all remaining arguments are directories to create.
+ # When -t is used, the destination is already specified.
+ test -n "$dir_arg$dstarg" && break
+ # Otherwise, the last argument is the destination. Remove it from $@.
+ for arg
+ do
+ if test -n "$dstarg"; then
+ # $@ is not empty: it contains at least $arg.
+ set fnord "$@" "$dstarg"
+ shift # fnord
+ fi
+ shift # arg
+ dstarg=$arg
+ done
+ break;;
+ esac
done
-fi
-
-if [ x"$dir_arg" != x ]
-then
- $doit $instcmd $dst &&
-
- if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi &&
- if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi &&
- if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else : ; fi &&
- if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else : ; fi
-else
-
-# If we're going to rename the final executable, determine the name now.
-
- if [ x"$transformarg" = x ]
- then
- dstfile=`basename $dst`
- else
- dstfile=`basename $dst $transformbasename |
- sed $transformarg`$transformbasename
- fi
-
-# don't allow the sed command to completely eliminate the filename
-
- if [ x"$dstfile" = x ]
- then
- dstfile=`basename $dst`
- else
- :
- fi
-
-# Make a temp file name in the proper directory.
-
- dsttmp=$dstdir/#inst.$$#
-# Move or copy the file name to the temp name
-
- $doit $instcmd $src $dsttmp &&
-
- trap "rm -f ${dsttmp}" 0 &&
-
-# and set any options; do chmod last to preserve setuid bits
-
-# If any of these fail, we abort the whole thing. If we want to
-# ignore errors from any of these, just make sure not to ignore
-# errors from the above "$doit $instcmd $src $dsttmp" command.
-
- if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else :;fi &&
- if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else :;fi &&
- if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else :;fi &&
- if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else :;fi &&
-
-# Now rename the file to the real destination.
-
- $doit $rmcmd -f $dstdir/$dstfile &&
- $doit $mvcmd $dsttmp $dstdir/$dstfile
+if test -z "$1"; then
+ if test -z "$dir_arg"; then
+ echo "$0: no input file specified." >&2
+ exit 1
+ fi
+ # It's OK to call `install-sh -d' without argument.
+ # This can happen when creating conditional directories.
+ exit 0
+fi
-fi &&
+for src
+do
+ # Protect names starting with `-'.
+ case $src in
+ -*) src=./$src ;;
+ esac
+
+ if test -n "$dir_arg"; then
+ dst=$src
+ src=
+
+ if test -d "$dst"; then
+ mkdircmd=:
+ chmodcmd=
+ else
+ mkdircmd=$mkdirprog
+ fi
+ else
+ # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
+ # might cause directories to be created, which would be especially bad
+ # if $src (and thus $dsttmp) contains '*'.
+ if test ! -f "$src" && test ! -d "$src"; then
+ echo "$0: $src does not exist." >&2
+ exit 1
+ fi
+
+ if test -z "$dstarg"; then
+ echo "$0: no destination specified." >&2
+ exit 1
+ fi
+
+ dst=$dstarg
+ # Protect names starting with `-'.
+ case $dst in
+ -*) dst=./$dst ;;
+ esac
+ # If destination is a directory, append the input filename; won't work
+ # if double slashes aren't ignored.
+ if test -d "$dst"; then
+ if test -n "$no_target_directory"; then
+ echo "$0: $dstarg: Is a directory" >&2
+ exit 1
+ fi
+ dst=$dst/`basename "$src"`
+ fi
+ fi
+
+ # This sed command emulates the dirname command.
+ dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
+
+ # Make sure that the destination directory exists.
+
+ # Skip lots of stat calls in the usual case.
+ if test ! -d "$dstdir"; then
+ defaultIFS='
+ '
+ IFS="${IFS-$defaultIFS}"
+
+ oIFS=$IFS
+ # Some sh's can't handle IFS=/ for some reason.
+ IFS='%'
+ set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
+ shift
+ IFS=$oIFS
+
+ pathcomp=
+
+ while test $# -ne 0 ; do
+ pathcomp=$pathcomp$1
+ shift
+ if test ! -d "$pathcomp"; then
+ $mkdirprog "$pathcomp"
+ # mkdir can fail with a `File exist' error in case several
+ # install-sh are creating the directory concurrently. This
+ # is OK.
+ test -d "$pathcomp" || exit
+ fi
+ pathcomp=$pathcomp/
+ done
+ fi
+
+ if test -n "$dir_arg"; then
+ $doit $mkdircmd "$dst" \
+ && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
+ && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
+ && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
+ && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
+
+ else
+ dstfile=`basename "$dst"`
+
+ # Make a couple of temp file names in the proper directory.
+ dsttmp=$dstdir/_inst.$$_
+ rmtmp=$dstdir/_rm.$$_
+
+ # Trap to clean up those temp files at exit.
+ trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
+ trap '(exit $?); exit' 1 2 13 15
+
+ # Copy the file name to the temp name.
+ $doit $cpprog "$src" "$dsttmp" &&
+
+ # and set any options; do chmod last to preserve setuid bits.
+ #
+ # If any of these fail, we abort the whole thing. If we want to
+ # ignore errors from any of these, just make sure not to ignore
+ # errors from the above "$doit $cpprog $src $dsttmp" command.
+ #
+ { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
+ && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
+ && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
+ && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
+
+ # Now rename the file to the real destination.
+ { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
+ || {
+ # The rename failed, perhaps because mv can't rename something else
+ # to itself, or perhaps because mv is so ancient that it does not
+ # support -f.
+
+ # Now remove or move aside any old file at destination location.
+ # We try this two ways since rm can't unlink itself on some
+ # systems and the destination file might be busy for other
+ # reasons. In this case, the final cleanup might fail but the new
+ # file should still install successfully.
+ {
+ if test -f "$dstdir/$dstfile"; then
+ $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
+ || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
+ || {
+ echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
+ (exit 1); exit 1
+ }
+ else
+ :
+ fi
+ } &&
+
+ # Now rename the file to the real destination.
+ $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
+ }
+ }
+ fi || { (exit 1); exit 1; }
+done
-exit 0
+# The final little trick to "correctly" pass the exit status to the exit trap.
+{
+ (exit 0); exit 0
+}
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
+# End:
diff --git a/contrib/file/is_tar.c b/contrib/file/is_tar.c
index b6ad2e3c1bc2..646172474a22 100644
--- a/contrib/file/is_tar.c
+++ b/contrib/file/is_tar.c
@@ -45,7 +45,7 @@
#include "tar.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: is_tar.c,v 1.25 2004/09/11 19:15:57 christos Exp $")
+FILE_RCSID("@(#)$Id: is_tar.c,v 1.26 2006/05/03 15:19:25 christos Exp $")
#endif
#define isodigit(c) ( ((c) >= '0') && ((c) <= '7') )
@@ -71,6 +71,12 @@ file_is_tar(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
"application/x-tar, POSIX" : "POSIX tar archive") == -1)
return -1;
return 1;
+ case 3:
+ if (file_printf(ms, (ms->flags & MAGIC_MIME) ?
+ "application/x-tar, POSIX (GNU)" :
+ "POSIX tar archive (GNU)") == -1)
+ return -1;
+ return 1;
default:
return 0;
}
@@ -113,7 +119,9 @@ is_tar(const unsigned char *buf, size_t nbytes)
if (sum != recsum)
return 0; /* Not a tar archive */
- if (0==strcmp(header->header.magic, TMAGIC))
+ if (strcmp(header->header.magic, GNUTMAGIC) == 0)
+ return 3; /* GNU Unix Standard tar archive */
+ if (strcmp(header->header.magic, TMAGIC) == 0)
return 2; /* Unix Standard tar archive */
return 1; /* Old fashioned tar archive */
diff --git a/contrib/file/magic.c b/contrib/file/magic.c
index 03d029159aa2..3f24075b1ed1 100644
--- a/contrib/file/magic.c
+++ b/contrib/file/magic.c
@@ -38,6 +38,7 @@
#ifdef QUICK
#include <sys/mman.h>
#endif
+#include <limits.h> /* for PIPE_BUF */
#if defined(HAVE_UTIMES)
# include <sys/time.h>
@@ -62,7 +63,7 @@
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: magic.c,v 1.32 2005/10/17 15:31:10 christos Exp $")
+FILE_RCSID("@(#)$Id: magic.c,v 1.35 2006/10/31 19:37:17 christos Exp $")
#endif /* lint */
#ifdef __EMX__
@@ -74,6 +75,7 @@ protected int file_os2_apptype(struct magic_set *ms, const char *fn,
private void free_mlist(struct mlist *);
private void close_and_restore(const struct magic_set *, const char *, int,
const struct stat *);
+private int info_from_stat(struct magic_set *, mode_t);
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
@@ -136,9 +138,26 @@ free_mlist(struct mlist *mlist)
free(ml);
}
+private int
+info_from_stat(struct magic_set *ms, mode_t md)
+{
+ /* We cannot open it, but we were able to stat it. */
+ if (md & 0222)
+ if (file_printf(ms, "writable, ") == -1)
+ return -1;
+ if (md & 0111)
+ if (file_printf(ms, "executable, ") == -1)
+ return -1;
+ if (S_ISREG(md))
+ if (file_printf(ms, "regular file, ") == -1)
+ return -1;
+ if (file_printf(ms, "no read permission") == -1)
+ return -1;
+ return 0;
+}
+
public void
-magic_close(ms)
- struct magic_set *ms;
+magic_close(struct magic_set *ms)
{
free_mlist(ms->mlist);
free(ms->o.pbuf);
@@ -221,6 +240,7 @@ magic_file(struct magic_set *ms, const char *inname)
unsigned char *buf;
struct stat sb;
ssize_t nbytes = 0; /* number of bytes read from a datafile */
+ int ispipe = 0;
/*
* one extra for terminating '\0', and
@@ -234,48 +254,75 @@ magic_file(struct magic_set *ms, const char *inname)
goto done;
switch (file_fsmagic(ms, inname, &sb)) {
- case -1:
+ case -1: /* error */
goto done;
- case 0:
+ case 0: /* nothing found */
break;
- default:
+ default: /* matched it and printed type */
rv = 0;
goto done;
}
- if (inname == NULL)
+ if (inname == NULL) {
fd = STDIN_FILENO;
- else if ((fd = open(inname, O_RDONLY|O_BINARY)) < 0) {
+ if (fstat(fd, &sb) == 0 && S_ISFIFO(sb.st_mode))
+ ispipe = 1;
+ } else {
+ int flags = O_RDONLY|O_BINARY;
+
+ if (stat(inname, &sb) == 0 && S_ISFIFO(sb.st_mode)) {
+ flags |= O_NONBLOCK;
+ ispipe = 1;
+ }
+
+ errno = 0;
+ if ((fd = open(inname, flags)) < 0) {
#ifdef __CYGWIN__
- char *tmp = alloca(strlen(inname) + 5);
- (void)strcat(strcpy(tmp, inname), ".exe");
- if ((fd = open(tmp, O_RDONLY|O_BINARY)) < 0) {
+ char *tmp = alloca(strlen(inname) + 5);
+ (void)strcat(strcpy(tmp, inname), ".exe");
+ if ((fd = open(tmp, flags)) < 0) {
#endif
- /* We cannot open it, but we were able to stat it. */
- if (sb.st_mode & 0222)
- if (file_printf(ms, "writable, ") == -1)
- goto done;
- if (sb.st_mode & 0111)
- if (file_printf(ms, "executable, ") == -1)
- goto done;
- if (S_ISREG(sb.st_mode))
- if (file_printf(ms, "regular file, ") == -1)
- goto done;
- if (file_printf(ms, "no read permission") == -1)
+ if (info_from_stat(ms, sb.st_mode) == -1)
+ goto done;
+ rv = 0;
goto done;
- rv = 0;
- goto done;
#ifdef __CYGWIN__
- }
+ }
+#endif
+ }
+#ifdef O_NONBLOCK
+ if ((flags = fcntl(fd, F_GETFL)) != -1) {
+ flags &= ~O_NONBLOCK;
+ (void)fcntl(fd, F_SETFL, flags);
+ }
#endif
}
/*
* try looking at the first HOWMANY bytes
*/
- if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) {
- file_error(ms, errno, "cannot read `%s'", inname);
- goto done;
+ if (ispipe) {
+ ssize_t r = 0;
+
+ while ((r = sread(fd, (void *)&buf[nbytes],
+ (size_t)(HOWMANY - nbytes))) > 0) {
+ nbytes += r;
+ if (r < PIPE_BUF) break;
+ }
+
+ if (nbytes == 0) {
+ /* We can not read it, but we were able to stat it. */
+ if (info_from_stat(ms, sb.st_mode) == -1)
+ goto done;
+ rv = 0;
+ goto done;
+ }
+
+ } else {
+ if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) {
+ file_error(ms, errno, "cannot read `%s'", inname);
+ goto done;
+ }
}
if (nbytes == 0) {
diff --git a/contrib/file/magic.mime b/contrib/file/magic.mime
index 7b811534da3f..3fa67e5928c4 100644
--- a/contrib/file/magic.mime
+++ b/contrib/file/magic.mime
@@ -99,9 +99,7 @@
# svg
-0 string \<?xml
-# text/xml
->38 string \<\!DOCTYPE\040svg image/svg+xml
+38 string \<\!DOCTYPE\040svg image/svg+xml
# xml
@@ -111,8 +109,8 @@
#------------------------------------------------------------------------------
# Java
-0 short 0xcafe
->2 short 0xbabe application/java
+0 beshort 0xcafe
+>2 beshort 0xbabe application/java
#------------------------------------------------------------------------------
# audio: file(1) magic for sound formats
@@ -135,7 +133,7 @@
# DEC systems (e.g. DECstation 5000) use a variant of the Sun/NeXT format
# that uses little-endian encoding and has a different magic number
# (0x0064732E in little-endian encoding).
-0 lelong 0x0064732E
+0 lelong 0x0064732E
>12 lelong 1 audio/x-dec-basic
>12 lelong 2 audio/x-dec-basic
>12 lelong 3 audio/x-dec-basic
@@ -148,25 +146,25 @@
# Bytes 0-3 of AIFF, AIFF-C, & 8SVX audio files are "FORM"
# AIFF audio data
-8 string AIFF audio/x-aiff
+8 string AIFF audio/x-aiff
# AIFF-C audio data
-8 string AIFC audio/x-aiff
+8 string AIFC audio/x-aiff
# IFF/8SVX audio data
-8 string 8SVX audio/x-aiff
+8 string 8SVX audio/x-aiff
# Creative Labs AUDIO stuff
# Standard MIDI data
-0 string MThd audio/unknown
+0 string MThd audio/unknown
#>9 byte >0 (format %d)
#>11 byte >1 using %d channels
# Creative Music (CMF) data
-0 string CTMF audio/unknown
+0 string CTMF audio/unknown
# SoundBlaster instrument data
-0 string SBI audio/unknown
+0 string SBI audio/unknown
# Creative Labs voice data
-0 string Creative\ Voice\ File audio/unknown
+0 string Creative\ Voice\ File audio/unknown
## is this next line right? it came this way...
#>19 byte 0x1A
#>23 byte >0 - version %d
@@ -209,8 +207,8 @@
# ideally should go into "images", but entries below would tag XPM as C source
0 string /*\ XPM image/x-xpmi 7bit
-# 3DS (3d Studio files)
-16 beshort 0x3d3d image/x-3ds
+# 3DS (3d Studio files) Conflicts with diff output 0x3d '='
+#16 beshort 0x3d3d image/x-3ds
# this first will upset you if you're a PL/1 shop... (are there any left?)
# in which case rm it; ascmagic will catch real C programs
@@ -408,10 +406,7 @@
0 string \<!-- text/html
0 string \<h1 text/html
0 string \<H1 text/html
-0 string \<!doctype\ HTML text/html
-0 string \<!DOCTYPE\ HTML text/html
-0 string \<!doctype\ html text/html
-0 string \<!doctype\ HTML text/html
+0 string/c \<!doctype\ html text/html
#------------------------------------------------------------------------------
# images: file(1) magic for image formats (see also "c-lang" for XPM bitmaps)
@@ -530,7 +525,11 @@
#
0 string \376\067\0\043 application/msword
-0 string \320\317\021\340\241\261 application/msword
+# disable this one because it applies also to other
+# Office/OLE documents for which msword is not correct. See PR#2608.
+# from magic file of the apache
+#0 string \320\317\021\340\241\261 application/msword
+512 string \354\245\301 application/msword
0 string \333\245-\0\0\0 application/msword
@@ -566,7 +565,7 @@
#0 string \367\203 TeX generic font data
#0 string \367\131 TeX packed font data
#0 string \367\312 TeX virtual font data
-#0 string This\ is\ TeX, TeX transcript text
+#0 string This\ is\ TeX, TeX transcript text
#0 string This\ is\ METAFONT, METAFONT transcript text
# There is no way to detect TeX Font Metric (*.tfm) files without
@@ -603,7 +602,7 @@
0 belong 0x000001B3 video/mpv
0 belong&0xFF5FFF1F 0x47400010 video/mp2t
0 belong 0x00000001
->4 byte&1F 0x07 video/h264
+>4 byte&0x1F 0x07 video/h264
# FLI animation format
0 leshort 0xAF11 video/fli
@@ -658,7 +657,7 @@
#
# Executables
#
-0 string \177ELF
+0 string \177ELF
>16 leshort 0 application/octet-stream
>16 leshort 1 application/x-object
>16 leshort 2 application/x-executable
@@ -712,19 +711,19 @@
4 string Standard\ Jet\ DB application/msaccess
## magic for XBase files
-#0 byte 0x02
+#0 byte 0x02
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
-#0 byte 0x03
+#0 byte 0x03
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
-#0 byte 0x04
+#0 byte 0x04
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
-#0 byte 0x05
+#0 byte 0x05
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
@@ -740,7 +739,7 @@
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
-#0 byte 0x83
+#0 byte 0x83
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
@@ -748,7 +747,7 @@
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
-#0 byte 0x8e
+#0 byte 0x8e
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
@@ -769,7 +768,7 @@
0 beshort 0x9501 text/PGP key security ring
0 beshort 0x9500 text/PGP key security ring
0 beshort 0xa600 text/PGP encrypted data
-0 string -----BEGIN\040PGP text/PGP armored data
+0 string -----BEGIN\040PGP text/PGP armored data
>15 string PUBLIC\040KEY\040BLOCK- public key block
>15 string MESSAGE- message
>15 string SIGNED\040MESSAGE- signed message
@@ -777,7 +776,7 @@
0 beshort 0x8501 data
#
# GnuPG Magic:
-#
+#
0 beshort 0x9901 text/GnuPG key public ring
0 beshort 0x8501 text/OpenPGP data
@@ -787,7 +786,7 @@
#
# http://www.macromedia.com/software/flash/open/
#
-0 string FWS
+0 string FWS
>3 byte x application/x-shockwave-flash
# The following paramaters are created for Namazu.
@@ -914,7 +913,7 @@
#0 string \000\000\001\000 image/x-ico
# Quark Xpress 3 Files:
-# (made the mimetype up)
+# (made the mimetype up)
0 string \0\0MMXPR3\0 application/x-quark-xpress-3
# EET archive
@@ -924,3 +923,16 @@
# From: Denis Knauf, via gentoo.
0 string fLaC audio/x-flac
0 string CWS application/x-shockwave-flash
+
+# Hangul Document Files:
+# Reversed-engineered HWP magic numbers
+# From: Won-Kyu Park <wkpark@kldp.org>
+512 string R\0o\0o\0t\0 application/x-hwp
+
+0 string/c BEGIN:VCARD text/x-vcard
+0 string WordPro\0 application/vnd.lotus-wordpro
+0 string WordPro\r\373 application/vnd.lotus-wordpro
+0 string CPC\262 image/cpi
+
+#
+128 string DICM application/dicom
diff --git a/contrib/file/magic2mime b/contrib/file/magic2mime
index f3fbe2675af4..dfb12604ceff 100755
--- a/contrib/file/magic2mime
+++ b/contrib/file/magic2mime
@@ -1,6 +1,6 @@
#! /usr/bin/env perl
# -*- PERL -*-
-# $Id: magic2mime,v 1.3 2006/03/02 22:10:26 christos Exp $
+# $Id: magic2mime,v 1.4 2006/11/25 18:36:10 christos Exp $
# Copyright (c) 1996, 1997 vax@linkdead.paranoia.com (VaX#n8)
#
# Usage: echo 'your-file-output-here' | file_to_ctype.pl
@@ -42,6 +42,7 @@
'^Sun/NeXT audio data', 'audio/basic',
'^MPEG', 'video/mpeg',
'^Apple QuickTime movie', 'video/quicktime',
+ '^DICOM medical imaging data', 'application/dicom',
# made up by me
'^bitmap', 'image/x-bitmap',
'^PC bitmap data, Windows 3.x format', 'image/x-msw3bmp',
diff --git a/contrib/file/mkinstalldirs b/contrib/file/mkinstalldirs
index 8ab885ec92d9..259dbfcd3578 100644
--- a/contrib/file/mkinstalldirs
+++ b/contrib/file/mkinstalldirs
@@ -1,29 +1,56 @@
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
-# Author: Noah Friedman <friedman@prep.ai.mit.edu>
+
+scriptversion=2005-06-29.22
+
+# Original author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
-# Public domain
+# Public domain.
+#
+# This file is maintained in Automake, please report
+# bugs to <bug-automake@gnu.org> or send patches to
+# <automake-patches@gnu.org>.
errstatus=0
-dirmode=""
+dirmode=
usage="\
-Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
+Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
+
+Create each directory DIR (with mode MODE, if specified), including all
+leading file name components.
+
+Report bugs to <bug-automake@gnu.org>."
# process command line arguments
while test $# -gt 0 ; do
- case "${1}" in
- -h | --help | --h* ) # -h for help
- echo "${usage}" 1>&2; exit 0 ;;
- -m ) # -m PERM arg
- shift
- test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
- dirmode="${1}"
- shift ;;
- -- ) shift; break ;; # stop option processing
- -* ) echo "${usage}" 1>&2; exit 1 ;; # unknown option
- * ) break ;; # first non-opt arg
- esac
+ case $1 in
+ -h | --help | --h*) # -h for help
+ echo "$usage"
+ exit $?
+ ;;
+ -m) # -m PERM arg
+ shift
+ test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
+ dirmode=$1
+ shift
+ ;;
+ --version)
+ echo "$0 $scriptversion"
+ exit $?
+ ;;
+ --) # stop option processing
+ shift
+ break
+ ;;
+ -*) # unknown option
+ echo "$usage" 1>&2
+ exit 1
+ ;;
+ *) # first non-opt arg
+ break
+ ;;
+ esac
done
for file
@@ -36,64 +63,96 @@ do
done
case $# in
-0) exit 0 ;;
+ 0) exit 0 ;;
esac
+# Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and
+# mkdir -p a/c at the same time, both will detect that a is missing,
+# one will create a, then the other will try to create a and die with
+# a "File exists" error. This is a problem when calling mkinstalldirs
+# from a parallel make. We use --version in the probe to restrict
+# ourselves to GNU mkdir, which is thread-safe.
case $dirmode in
-'')
- if mkdir -p -- . 2>/dev/null; then
- echo "mkdir -p -- $*"
- exec mkdir -p -- "$@"
- fi ;;
-*)
- if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
- echo "mkdir -m $dirmode -p -- $*"
- exec mkdir -m "$dirmode" -p -- "$@"
- fi ;;
+ '')
+ if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
+ echo "mkdir -p -- $*"
+ exec mkdir -p -- "$@"
+ else
+ # On NextStep and OpenStep, the `mkdir' command does not
+ # recognize any option. It will interpret all options as
+ # directories to create, and then abort because `.' already
+ # exists.
+ test -d ./-p && rmdir ./-p
+ test -d ./--version && rmdir ./--version
+ fi
+ ;;
+ *)
+ if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
+ test ! -d ./--version; then
+ echo "mkdir -m $dirmode -p -- $*"
+ exec mkdir -m "$dirmode" -p -- "$@"
+ else
+ # Clean up after NextStep and OpenStep mkdir.
+ for d in ./-m ./-p ./--version "./$dirmode";
+ do
+ test -d $d && rmdir $d
+ done
+ fi
+ ;;
esac
for file
do
- set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
- shift
-
- pathcomp=
- for d
- do
- pathcomp="$pathcomp$d"
- case "$pathcomp" in
- -* ) pathcomp=./$pathcomp ;;
- esac
-
- if test ! -d "$pathcomp"; then
- echo "mkdir $pathcomp"
-
- mkdir "$pathcomp" || lasterr=$?
-
- if test ! -d "$pathcomp"; then
- errstatus=$lasterr
- else
- if test ! -z "$dirmode"; then
- echo "chmod $dirmode $pathcomp"
-
- lasterr=""
- chmod "$dirmode" "$pathcomp" || lasterr=$?
-
- if test ! -z "$lasterr"; then
- errstatus=$lasterr
- fi
+ case $file in
+ /*) pathcomp=/ ;;
+ *) pathcomp= ;;
+ esac
+ oIFS=$IFS
+ IFS=/
+ set fnord $file
+ shift
+ IFS=$oIFS
+
+ for d
+ do
+ test "x$d" = x && continue
+
+ pathcomp=$pathcomp$d
+ case $pathcomp in
+ -*) pathcomp=./$pathcomp ;;
+ esac
+
+ if test ! -d "$pathcomp"; then
+ echo "mkdir $pathcomp"
+
+ mkdir "$pathcomp" || lasterr=$?
+
+ if test ! -d "$pathcomp"; then
+ errstatus=$lasterr
+ else
+ if test ! -z "$dirmode"; then
+ echo "chmod $dirmode $pathcomp"
+ lasterr=
+ chmod "$dirmode" "$pathcomp" || lasterr=$?
+
+ if test ! -z "$lasterr"; then
+ errstatus=$lasterr
fi
fi
- fi
+ fi
+ fi
- pathcomp="$pathcomp/"
- done
+ pathcomp=$pathcomp/
+ done
done
exit $errstatus
# Local Variables:
# mode: shell-script
-# sh-indentation: 3
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
# End:
-# mkinstalldirs ends here
diff --git a/contrib/file/patchlevel.h b/contrib/file/patchlevel.h
index 1f2587ad80b0..334732cc5aa0 100644
--- a/contrib/file/patchlevel.h
+++ b/contrib/file/patchlevel.h
@@ -1,11 +1,17 @@
#define FILE_VERSION_MAJOR 4
-#define patchlevel 17
+#define patchlevel 19
/*
* Patchlevel file for Ian Darwin's MAGIC command.
- * $Id: patchlevel.h,v 1.60 2006/03/02 22:15:12 christos Exp $
+ * $Id: patchlevel.h,v 1.62 2006/12/11 21:49:58 christos Exp $
*
* $Log: patchlevel.h,v $
+ * Revision 1.62 2006/12/11 21:49:58 christos
+ * time for 4.19
+ *
+ * Revision 1.61 2006/10/31 21:18:09 christos
+ * bump
+ *
* Revision 1.60 2006/03/02 22:15:12 christos
* welcome to 4.17
*
diff --git a/contrib/file/print.c b/contrib/file/print.c
index e7c8098d699e..28cca18cbc09 100644
--- a/contrib/file/print.c
+++ b/contrib/file/print.c
@@ -41,7 +41,7 @@
#include <time.h>
#ifndef lint
-FILE_RCSID("@(#)$Id: print.c,v 1.50 2006/03/02 22:07:53 christos Exp $")
+FILE_RCSID("@(#)$Id: print.c,v 1.56 2006/12/08 20:31:07 christos Exp $")
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
@@ -50,18 +50,17 @@ FILE_RCSID("@(#)$Id: print.c,v 1.50 2006/03/02 22:07:53 christos Exp $")
protected void
file_mdump(struct magic *m)
{
- private const char *typ[] = { FILE_FORMAT_NAME };
private const char optyp[] = { FILE_OPS };
- (void) fputc('[', stderr);
+ (void) fprintf(stderr, "[%zu", m->lineno);
(void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),
m->offset);
if (m->flag & INDIR) {
(void) fprintf(stderr, "(%s,",
/* Note: type is unsigned */
- (m->in_type < SZOF(typ)) ?
- typ[m->in_type] : "*bad*");
+ (m->in_type < file_nnames) ?
+ file_names[m->in_type] : "*bad*");
if (m->in_op & FILE_OPINVERSE)
(void) fputc('~', stderr);
(void) fprintf(stderr, "%c%d),",
@@ -71,7 +70,7 @@ file_mdump(struct magic *m)
}
(void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "",
/* Note: type is unsigned */
- (m->type < SZOF(typ)) ? typ[m->type] : "*bad*");
+ (m->type < file_nnames) ? file_names[m->type] : "*bad*");
if (m->mask_op & FILE_OPINVERSE)
(void) fputc('~', stderr);
if (m->mask) {
@@ -80,7 +79,8 @@ file_mdump(struct magic *m)
else
fputc('?', stderr);
if (FILE_STRING != m->type || FILE_PSTRING != m->type)
- (void) fprintf(stderr, "%.8x", m->mask);
+ (void) fprintf(stderr, "%.8llx",
+ (unsigned long long)m->mask);
else {
if (m->mask & STRING_IGNORE_LOWERCASE)
(void) fputc(CHAR_IGNORE_LOWERCASE, stderr);
@@ -106,13 +106,19 @@ file_mdump(struct magic *m)
case FILE_BELONG:
(void) fprintf(stderr, "%d", m->value.l);
break;
+ case FILE_BEQUAD:
+ case FILE_LEQUAD:
+ case FILE_QUAD:
+ (void) fprintf(stderr, "%lld",
+ (unsigned long long)m->value.q);
+ break;
case FILE_PSTRING:
case FILE_STRING:
case FILE_REGEX:
case FILE_BESTRING16:
case FILE_LESTRING16:
case FILE_SEARCH:
- file_showstr(stderr, m->value.s, m->vallen);
+ file_showstr(stderr, m->value.s, (size_t)m->vallen);
break;
case FILE_DATE:
case FILE_LEDATE:
@@ -128,6 +134,18 @@ file_mdump(struct magic *m)
(void)fprintf(stderr, "%s,",
file_fmttime(m->value.l, 0));
break;
+ case FILE_QDATE:
+ case FILE_LEQDATE:
+ case FILE_BEQDATE:
+ (void)fprintf(stderr, "%s,",
+ file_fmttime((uint32_t)m->value.q, 1));
+ break;
+ case FILE_QLDATE:
+ case FILE_LEQLDATE:
+ case FILE_BEQLDATE:
+ (void)fprintf(stderr, "%s,",
+ file_fmttime((uint32_t)m->value.q, 0));
+ break;
default:
(void) fputs("*bad*", stderr);
break;
diff --git a/contrib/file/readelf.c b/contrib/file/readelf.c
index 878a7636b3a9..69318fa626e0 100644
--- a/contrib/file/readelf.c
+++ b/contrib/file/readelf.c
@@ -37,14 +37,16 @@
#include "readelf.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: readelf.c,v 1.54 2006/01/13 00:45:21 christos Exp $")
+FILE_RCSID("@(#)$Id: readelf.c,v 1.61 2006/11/15 15:53:23 christos Exp $")
#endif
#ifdef ELFCORE
-private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t);
+private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t,
+ off_t, int *);
#endif
-private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t);
-private int doshn(struct magic_set *, int, int, int, off_t, int, size_t);
+private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,
+ off_t, int *);
+private int doshn(struct magic_set *, int, int, int, off_t, int, size_t, int *);
private size_t donote(struct magic_set *, unsigned char *, size_t, size_t, int,
int, size_t, int *);
@@ -189,15 +191,16 @@ getu64(int swap, uint64_t value)
#ifdef ELFCORE
size_t prpsoffsets32[] = {
8, /* FreeBSD */
- 28, /* Linux 2.0.36 */
- 32, /* Linux (I forget which kernel version) */
+ 28, /* Linux 2.0.36 (short name) */
+ 44, /* Linux (path name) */
84, /* SunOS 5.x */
};
size_t prpsoffsets64[] = {
16, /* FreeBSD, 64-bit */
- 40, /* Linux (tested on core from 2.4.x) */
- 120, /* SunOS 5.x, 64-bit */
+ 40, /* Linux (tested on core from 2.4.x, short name) */
+ 56, /* Linux (path name) */
+ 120, /* SunOS 5.x, 64-bit */
};
#define NOFFSETS32 (sizeof prpsoffsets32 / sizeof prpsoffsets32[0])
@@ -237,17 +240,24 @@ private const char *os_style_names[] = {
};
#define FLAGS_DID_CORE 1
+#define FLAGS_DID_NOTE 2
private int
dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
- int num, size_t size)
+ int num, size_t size, off_t fsize, int *flags)
{
Elf32_Phdr ph32;
Elf64_Phdr ph64;
size_t offset;
unsigned char nbuf[BUFSIZ];
ssize_t bufsize;
- int flags = 0;
+ off_t savedoffset;
+ struct stat st;
+
+ if (fstat(fd, &st) < 0) {
+ file_badread(ms);
+ return -1;
+ }
if (size != xph_sizeof) {
if (file_printf(ms, ", corrupted program header size") == -1)
@@ -259,7 +269,7 @@ dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
* Loop through all the program headers.
*/
for ( ; num; num--) {
- if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
+ if ((savedoffset = lseek(fd, off, SEEK_SET)) == (off_t)-1) {
file_badseek(ms);
return -1;
}
@@ -267,6 +277,14 @@ dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
file_badread(ms);
return -1;
}
+ if (xph_offset > fsize) {
+ if (lseek(fd, savedoffset, SEEK_SET) == (off_t)-1) {
+ file_badseek(ms);
+ return -1;
+ }
+ continue;
+ }
+
off += size;
if (xph_type != PT_NOTE)
continue;
@@ -290,7 +308,7 @@ dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
if (offset >= (size_t)bufsize)
break;
offset = donote(ms, nbuf, offset, (size_t)bufsize,
- class, swap, 4, &flags);
+ class, swap, 4, flags);
if (offset == 0)
break;
@@ -321,7 +339,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
/*
* We're out of note headers.
*/
- return offset;
+ return (offset >= size) ? offset : size;
}
if (namesz & 0x80000000) {
@@ -349,9 +367,15 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
offset = ELF_ALIGN(doff + descsz);
if (doff + descsz > size) {
- return offset;
+ /*
+ * We're past the end of the buffer.
+ */
+ return (offset >= size) ? offset : size;
}
+ if (*flags & FLAGS_DID_NOTE)
+ goto core;
+
if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
xnh_type == NT_GNU_VERSION && descsz == 16) {
uint32_t desc[4];
@@ -379,6 +403,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
if (file_printf(ms, " %d.%d.%d", getu32(swap, desc[1]),
getu32(swap, desc[2]), getu32(swap, desc[3])) == -1)
return size;
+ *flags |= FLAGS_DID_NOTE;
return size;
}
@@ -403,10 +428,10 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
* p = patchlevel
*/
if (desc > 100000000U) {
- u_int ver_patch = (desc / 100) % 100;
- u_int ver_rel = (desc / 10000) % 100;
- u_int ver_min = (desc / 1000000) % 100;
- u_int ver_maj = desc / 100000000;
+ uint32_t ver_patch = (desc / 100) % 100;
+ uint32_t ver_rel = (desc / 10000) % 100;
+ uint32_t ver_min = (desc / 1000000) % 100;
+ uint32_t ver_maj = desc / 100000000;
if (file_printf(ms, " %u.%u", ver_maj, ver_min) == -1)
return size;
@@ -415,12 +440,16 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
return size;
} else if (ver_rel != 0) {
while (ver_rel > 26) {
- file_printf(ms, "Z");
+ if (file_printf(ms, "Z") == -1)
+ return size;
ver_rel -= 26;
}
- file_printf(ms, "%c", 'A' + ver_rel - 1);
+ if (file_printf(ms, "%c", 'A' + ver_rel - 1)
+ == -1)
+ return size;
}
}
+ *flags |= FLAGS_DID_NOTE;
return size;
}
@@ -498,6 +527,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
return size;
}
}
+ *flags |= FLAGS_DID_NOTE;
return size;
}
@@ -506,6 +536,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
if (file_printf(ms, ", for OpenBSD") == -1)
return size;
/* Content of note is always 0 */
+ *flags |= FLAGS_DID_NOTE;
return size;
}
@@ -519,9 +550,11 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
if (file_printf(ms, " %d.%d.%d", desc / 100000,
desc / 10000 % 10, desc % 10000) == -1)
return size;
+ *flags |= FLAGS_DID_NOTE;
return size;
}
+core:
/*
* Sigh. The 2.0.36 kernel in Debian 2.1, at
* least, doesn't correctly implement name
@@ -551,13 +584,13 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
}
#ifdef ELFCORE
+ if ((*flags & FLAGS_DID_CORE) != 0)
+ return size;
+
if (os_style != -1) {
- if ((*flags & FLAGS_DID_CORE) == 0) {
- if (file_printf(ms, ", %s-style",
- os_style_names[os_style]) == -1)
- return size;
- *flags |= FLAGS_DID_CORE;
- }
+ if (file_printf(ms, ", %s-style", os_style_names[os_style])
+ == -1)
+ return size;
}
switch (os_style) {
@@ -660,17 +693,17 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
break;
}
#endif
+ *flags |= FLAGS_DID_CORE;
return offset;
}
private int
doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
- size_t size)
+ size_t size, int *flags)
{
Elf32_Shdr sh32;
Elf64_Shdr sh64;
int stripped = 1;
- int flags = 0;
void *nbuf;
off_t noff;
@@ -727,7 +760,7 @@ doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
break;
noff = donote(ms, nbuf, (size_t)noff,
(size_t)xsh_size, class, swap, 4,
- &flags);
+ flags);
if (noff == 0)
break;
}
@@ -752,7 +785,7 @@ doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
*/
private int
dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
- int num, size_t size)
+ int num, size_t size, off_t fsize, int *flags)
{
Elf32_Phdr ph32;
Elf64_Phdr ph64;
@@ -761,14 +794,20 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
unsigned char nbuf[BUFSIZ];
int bufsize;
size_t offset, align;
- off_t savedoffset;
- int flags = 0;
+ off_t savedoffset = (off_t)-1;
+ struct stat st;
+ if (fstat(fd, &st) < 0) {
+ file_badread(ms);
+ return -1;
+ }
+
if (size != xph_sizeof) {
if (file_printf(ms, ", corrupted program header size") == -1)
return -1;
return 0;
}
+
if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
file_badseek(ms);
return -1;
@@ -779,11 +818,27 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
file_badread(ms);
return -1;
}
+ if (xph_offset > st.st_size && savedoffset != (off_t)-1) {
+ if (lseek(fd, savedoffset, SEEK_SET) == (off_t)-1) {
+ file_badseek(ms);
+ return -1;
+ }
+ continue;
+ }
+
if ((savedoffset = lseek(fd, (off_t)0, SEEK_CUR)) == (off_t)-1) {
file_badseek(ms);
return -1;
}
+ if (xph_offset > fsize) {
+ if (lseek(fd, savedoffset, SEEK_SET) == (off_t)-1) {
+ file_badseek(ms);
+ return -1;
+ }
+ continue;
+ }
+
switch (xph_type) {
case PT_DYNAMIC:
linking_style = "dynamically";
@@ -820,7 +875,7 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
break;
offset = donote(ms, nbuf, offset,
(size_t)bufsize, class, swap, align,
- &flags);
+ flags);
if (offset == 0)
break;
}
@@ -848,6 +903,9 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
} u;
int class;
int swap;
+ struct stat st;
+ off_t fsize;
+ int flags = 0;
/*
* If we cannot seek, it must be a pipe, socket or fifo.
@@ -855,6 +913,12 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
fd = file_pipe2file(ms, fd, buf, nbytes);
+ if (fstat(fd, &st) == -1) {
+ file_badread(ms);
+ return -1;
+ }
+ fsize = st.st_size;
+
/*
* ELF executables have multiple section headers in arbitrary
* file locations and thus file(1) cannot determine it from easily.
@@ -867,7 +931,7 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
return 0;
- class = buf[4];
+ class = buf[EI_CLASS];
if (class == ELFCLASS32) {
Elf32_Ehdr elfhdr;
@@ -877,14 +941,15 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
u.l = 1;
(void) memcpy(&elfhdr, buf, sizeof elfhdr);
- swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[5];
+ swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
if (getu16(swap, elfhdr.e_type) == ET_CORE) {
#ifdef ELFCORE
if (dophn_core(ms, class, swap, fd,
(off_t)getu32(swap, elfhdr.e_phoff),
getu16(swap, elfhdr.e_phnum),
- (size_t)getu16(swap, elfhdr.e_phentsize)) == -1)
+ (size_t)getu16(swap, elfhdr.e_phentsize),
+ fsize, &flags) == -1)
return -1;
#else
;
@@ -894,14 +959,16 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
if (dophn_exec(ms, class, swap,
fd, (off_t)getu32(swap, elfhdr.e_phoff),
getu16(swap, elfhdr.e_phnum),
- (size_t)getu16(swap, elfhdr.e_phentsize))
+ (size_t)getu16(swap, elfhdr.e_phentsize),
+ fsize, &flags)
== -1)
return -1;
}
if (doshn(ms, class, swap, fd,
(off_t)getu32(swap, elfhdr.e_shoff),
getu16(swap, elfhdr.e_shnum),
- (size_t)getu16(swap, elfhdr.e_shentsize)) == -1)
+ (size_t)getu16(swap, elfhdr.e_shentsize),
+ &flags) == -1)
return -1;
}
return 1;
@@ -915,14 +982,15 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
u.l = 1;
(void) memcpy(&elfhdr, buf, sizeof elfhdr);
- swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[5];
+ swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
if (getu16(swap, elfhdr.e_type) == ET_CORE) {
#ifdef ELFCORE
if (dophn_core(ms, class, swap, fd,
(off_t)elf_getu64(swap, elfhdr.e_phoff),
getu16(swap, elfhdr.e_phnum),
- (size_t)getu16(swap, elfhdr.e_phentsize)) == -1)
+ (size_t)getu16(swap, elfhdr.e_phentsize),
+ fsize, &flags) == -1)
return -1;
#else
;
@@ -932,14 +1000,15 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
if (dophn_exec(ms, class, swap, fd,
(off_t)elf_getu64(swap, elfhdr.e_phoff),
getu16(swap, elfhdr.e_phnum),
- (size_t)getu16(swap, elfhdr.e_phentsize))
- == -1)
+ (size_t)getu16(swap, elfhdr.e_phentsize),
+ fsize, &flags) == -1)
return -1;
}
if (doshn(ms, class, swap, fd,
(off_t)elf_getu64(swap, elfhdr.e_shoff),
getu16(swap, elfhdr.e_shnum),
- (size_t)getu16(swap, elfhdr.e_shentsize)) == -1)
+ (size_t)getu16(swap, elfhdr.e_shentsize), &flags)
+ == -1)
return -1;
}
return 1;
diff --git a/contrib/file/softmagic.c b/contrib/file/softmagic.c
index edcba5e5f80e..77250487bdc6 100644
--- a/contrib/file/softmagic.c
+++ b/contrib/file/softmagic.c
@@ -39,24 +39,28 @@
#ifndef lint
-FILE_RCSID("@(#)$Id: softmagic.c,v 1.78 2006/03/12 22:09:33 christos Exp $")
+FILE_RCSID("@(#)$Id: softmagic.c,v 1.87 2006/12/11 21:48:49 christos Exp $")
#endif /* lint */
private int match(struct magic_set *, struct magic *, uint32_t,
const unsigned char *, size_t);
private int mget(struct magic_set *, union VALUETYPE *, const unsigned char *,
struct magic *, size_t, unsigned int);
-private int mcheck(struct magic_set *, union VALUETYPE *, struct magic *);
+private int magiccheck(struct magic_set *, union VALUETYPE *, struct magic *);
private int32_t mprint(struct magic_set *, union VALUETYPE *, struct magic *);
private void mdebug(uint32_t, const char *, size_t);
private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
- const unsigned char *, size_t, size_t);
+ const unsigned char *, uint32_t, size_t);
private int mconvert(struct magic_set *, union VALUETYPE *, struct magic *);
private int check_mem(struct magic_set *, unsigned int);
+private int print_sep(struct magic_set *, int);
+private void cvt_8(union VALUETYPE *, const struct magic *);
+private void cvt_16(union VALUETYPE *, const struct magic *);
+private void cvt_32(union VALUETYPE *, const struct magic *);
+private void cvt_64(union VALUETYPE *, const struct magic *);
/*
- * softmagic - lookup one file in database
- * (already read from MAGIC by apprentice.c).
+ * softmagic - lookup one file in parsed, in-memory copy of database
* Passed the name and FILE * of one file to be typed.
*/
/*ARGSUSED1*/ /* nbytes passed for regularity, maybe need later */
@@ -64,9 +68,10 @@ protected int
file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
{
struct mlist *ml;
+ int rv;
for (ml = ms->mlist->next; ml != ms->mlist; ml = ml->next)
- if (match(ms, ml->magic, ml->nmagic, buf, nbytes))
- return 1;
+ if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes)) != 0)
+ return rv;
return 0;
}
@@ -109,18 +114,21 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
int32_t oldoff = 0;
int returnval = 0; /* if a match is found it is set to 1*/
int firstline = 1; /* a flag to print X\n X\n- X */
+ int printed_something = 0;
if (check_mem(ms, cont_level) == -1)
return -1;
for (magindex = 0; magindex < nmagic; magindex++) {
/* if main entry matches, print it... */
+ ms->offset = magic[magindex].offset;
int flush = !mget(ms, &p, s, &magic[magindex], nbytes,
cont_level);
if (flush) {
- if (magic[magindex].reln == '!') flush = 0;
+ if (magic[magindex].reln == '!')
+ flush = 0;
} else {
- switch (mcheck(ms, &p, &magic[magindex])) {
+ switch (magiccheck(ms, &p, &magic[magindex])) {
case -1:
return -1;
case 0:
@@ -141,21 +149,21 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
continue;
}
- if (!firstline) { /* we found another match */
- /* put a newline and '-' to do some simple formatting*/
- if (file_printf(ms, "\n- ") == -1)
+ /*
+ * If we are going to print something, we'll need to print
+ * a blank before we print something else.
+ */
+ if (magic[magindex].desc[0]) {
+ need_separator = 1;
+ printed_something = 1;
+ if (print_sep(ms, firstline) == -1)
return -1;
}
if ((ms->c.off[cont_level] = mprint(ms, &p, &magic[magindex]))
== -1)
return -1;
- /*
- * If we printed something, we'll need to print
- * a blank before we print something else.
- */
- if (magic[magindex].desc[0])
- need_separator = 1;
+
/* and any continuations that match */
if (check_mem(ms, ++cont_level) == -1)
return -1;
@@ -171,24 +179,33 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
*/
cont_level = magic[magindex].cont_level;
}
- oldoff = magic[magindex].offset;
+ ms->offset = magic[magindex].offset;
if (magic[magindex].flag & OFFADD) {
- magic[magindex].offset +=
+ ms->offset +=
ms->c.off[cont_level - 1];
}
flush = !mget(ms, &p, s, &magic[magindex], nbytes,
cont_level);
if (flush && magic[magindex].reln != '!')
- goto done;
+ continue;
- switch (flush ? 1 : mcheck(ms, &p, &magic[magindex])) {
+ switch (flush ? 1 : magiccheck(ms, &p, &magic[magindex])) {
case -1:
return -1;
case 0:
break;
default:
/*
+ * If we are going to print something,
+ * make sure that we have a separator first.
+ */
+ if (magic[magindex].desc[0]) {
+ printed_something = 1;
+ if (print_sep(ms, firstline) == -1)
+ return -1;
+ }
+ /*
* This continuation matched.
* Print its message, with
* a blank before it if
@@ -217,12 +234,11 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
if (check_mem(ms, ++cont_level) == -1)
return -1;
}
-done:
- magic[magindex].offset = oldoff;
}
firstline = 0;
- returnval = 1;
- if ((ms->flags & MAGIC_CONTINUE) == 0) {
+ if (printed_something)
+ returnval = 1;
+ if ((ms->flags & MAGIC_CONTINUE) == 0 && printed_something) {
return 1; /* don't keep searching */
}
}
@@ -241,44 +257,113 @@ check_mem(struct magic_set *ms, unsigned int level)
ms->c.off = (ms->c.off == NULL) ? malloc(len) : realloc(ms->c.off, len);
if (ms->c.off != NULL)
return 0;
- file_oomem(ms);
+ file_oomem(ms, len);
return -1;
}
+private int
+check_fmt(struct magic_set *ms, struct magic *m)
+{
+ regex_t rx;
+ int rc;
+
+ if (strchr(m->desc, '%') == NULL)
+ return 0;
+
+ rc = regcomp(&rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB);
+ if (rc) {
+ char errmsg[512];
+ regerror(rc, &rx, errmsg, sizeof(errmsg));
+ file_error(ms, 0, "regex error %d, (%s)", rc, errmsg);
+ return -1;
+ } else {
+ rc = regexec(&rx, m->desc, 0, 0, 0);
+ regfree(&rx);
+ return !rc;
+ }
+}
+
private int32_t
mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
{
- uint32_t v;
- int32_t t=0 ;
+ uint64_t v;
+ int32_t t = 0;
+ char buf[512];
switch (m->type) {
case FILE_BYTE:
- v = file_signextend(ms, m, (size_t)p->b);
- if (file_printf(ms, m->desc, (unsigned char) v) == -1)
+ v = file_signextend(ms, m, (uint64_t)p->b);
+ switch (check_fmt(ms, m)) {
+ case -1:
return -1;
- t = m->offset + sizeof(char);
+ case 1:
+ if (snprintf(buf, sizeof(buf), "%c",
+ (unsigned char)v) < 0)
+ return -1;
+ if (file_printf(ms, m->desc, buf) == -1)
+ return -1;
+ break;
+ default:
+ if (file_printf(ms, m->desc, (unsigned char) v) == -1)
+ return -1;
+ break;
+ }
+ t = ms->offset + sizeof(char);
break;
case FILE_SHORT:
case FILE_BESHORT:
case FILE_LESHORT:
- v = file_signextend(ms, m, (size_t)p->h);
- if (file_printf(ms, m->desc, (unsigned short) v) == -1)
+ v = file_signextend(ms, m, (uint64_t)p->h);
+ switch (check_fmt(ms, m)) {
+ case -1:
return -1;
- t = m->offset + sizeof(short);
+ case 1:
+ if (snprintf(buf, sizeof(buf), "%hu",
+ (unsigned short)v) < 0)
+ return -1;
+ if (file_printf(ms, m->desc, buf) == -1)
+ return -1;
+ break;
+ default:
+ if (file_printf(ms, m->desc, (unsigned short) v) == -1)
+ return -1;
+ break;
+ }
+ t = ms->offset + sizeof(short);
break;
case FILE_LONG:
case FILE_BELONG:
case FILE_LELONG:
case FILE_MELONG:
- v = file_signextend(ms, m, p->l);
- if (file_printf(ms, m->desc, (uint32_t) v) == -1)
+ v = file_signextend(ms, m, (uint64_t)p->l);
+ switch (check_fmt(ms, m)) {
+ case -1:
return -1;
- t = m->offset + sizeof(int32_t);
+ case 1:
+ if (snprintf(buf, sizeof(buf), "%u", (uint32_t)v) < 0)
+ return -1;
+ if (file_printf(ms, m->desc, buf) == -1)
+ return -1;
+ break;
+ default:
+ if (file_printf(ms, m->desc, (uint32_t) v) == -1)
+ return -1;
+ break;
+ }
+ t = ms->offset + sizeof(int32_t);
break;
+ case FILE_QUAD:
+ case FILE_BEQUAD:
+ case FILE_LEQUAD:
+ v = file_signextend(ms, m, p->q);
+ if (file_printf(ms, m->desc, (uint64_t) v) == -1)
+ return -1;
+ t = ms->offset + sizeof(int64_t);
+ break;
case FILE_STRING:
case FILE_PSTRING:
case FILE_BESTRING16:
@@ -286,7 +371,7 @@ mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
if (m->reln == '=' || m->reln == '!') {
if (file_printf(ms, m->desc, m->value.s) == -1)
return -1;
- t = m->offset + m->vallen;
+ t = ms->offset + m->vallen;
}
else {
if (*m->value.s == '\0') {
@@ -296,7 +381,7 @@ mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
}
if (file_printf(ms, m->desc, p->s) == -1)
return -1;
- t = m->offset + strlen(p->s);
+ t = ms->offset + strlen(p->s);
}
break;
@@ -306,7 +391,7 @@ mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
case FILE_MEDATE:
if (file_printf(ms, m->desc, file_fmttime(p->l, 1)) == -1)
return -1;
- t = m->offset + sizeof(time_t);
+ t = ms->offset + sizeof(time_t);
break;
case FILE_LDATE:
@@ -315,17 +400,37 @@ mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
case FILE_MELDATE:
if (file_printf(ms, m->desc, file_fmttime(p->l, 0)) == -1)
return -1;
- t = m->offset + sizeof(time_t);
+ t = ms->offset + sizeof(time_t);
+ break;
+
+ case FILE_QDATE:
+ case FILE_BEQDATE:
+ case FILE_LEQDATE:
+ if (file_printf(ms, m->desc, file_fmttime((uint32_t)p->q, 1))
+ == -1)
+ return -1;
+ t = ms->offset + sizeof(uint64_t);
+ break;
+
+ case FILE_QLDATE:
+ case FILE_BEQLDATE:
+ case FILE_LEQLDATE:
+ if (file_printf(ms, m->desc, file_fmttime((uint32_t)p->q, 0))
+ == -1)
+ return -1;
+ t = ms->offset + sizeof(uint64_t);
break;
+
case FILE_REGEX:
if (file_printf(ms, m->desc, p->s) == -1)
return -1;
- t = m->offset + strlen(p->s);
+ t = ms->offset + strlen(p->s);
break;
+
case FILE_SEARCH:
if (file_printf(ms, m->desc, m->value.s) == -1)
return -1;
- t = m->offset + m->vallen;
+ t = ms->offset + m->vallen;
break;
default:
@@ -335,6 +440,62 @@ mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
return(t);
}
+
+#define DO_CVT(fld, cast) \
+ if (m->mask) \
+ switch (m->mask_op & 0x7F) { \
+ case FILE_OPAND: \
+ p->fld &= cast m->mask; \
+ break; \
+ case FILE_OPOR: \
+ p->fld |= cast m->mask; \
+ break; \
+ case FILE_OPXOR: \
+ p->fld ^= cast m->mask; \
+ break; \
+ case FILE_OPADD: \
+ p->fld += cast m->mask; \
+ break; \
+ case FILE_OPMINUS: \
+ p->fld -= cast m->mask; \
+ break; \
+ case FILE_OPMULTIPLY: \
+ p->fld *= cast m->mask; \
+ break; \
+ case FILE_OPDIVIDE: \
+ p->fld /= cast m->mask; \
+ break; \
+ case FILE_OPMODULO: \
+ p->fld %= cast m->mask; \
+ break; \
+ } \
+ if (m->mask_op & FILE_OPINVERSE) \
+ p->fld = ~p->fld \
+
+private void
+cvt_8(union VALUETYPE *p, const struct magic *m)
+{
+ DO_CVT(b, (uint8_t));
+}
+
+private void
+cvt_16(union VALUETYPE *p, const struct magic *m)
+{
+ DO_CVT(h, (uint16_t));
+}
+
+private void
+cvt_32(union VALUETYPE *p, const struct magic *m)
+{
+ DO_CVT(l, (uint32_t));
+}
+
+private void
+cvt_64(union VALUETYPE *p, const struct magic *m)
+{
+ DO_CVT(q, (uint64_t));
+}
+
/*
* Convert the byte order of the data we are looking at
* While we're here, let's apply the mask operation
@@ -345,99 +506,20 @@ mconvert(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
{
switch (m->type) {
case FILE_BYTE:
- if (m->mask)
- switch (m->mask_op & 0x7F) {
- case FILE_OPAND:
- p->b &= m->mask;
- break;
- case FILE_OPOR:
- p->b |= m->mask;
- break;
- case FILE_OPXOR:
- p->b ^= m->mask;
- break;
- case FILE_OPADD:
- p->b += m->mask;
- break;
- case FILE_OPMINUS:
- p->b -= m->mask;
- break;
- case FILE_OPMULTIPLY:
- p->b *= m->mask;
- break;
- case FILE_OPDIVIDE:
- p->b /= m->mask;
- break;
- case FILE_OPMODULO:
- p->b %= m->mask;
- break;
- }
- if (m->mask_op & FILE_OPINVERSE)
- p->b = ~p->b;
+ cvt_8(p, m);
return 1;
case FILE_SHORT:
- if (m->mask)
- switch (m->mask_op & 0x7F) {
- case FILE_OPAND:
- p->h &= m->mask;
- break;
- case FILE_OPOR:
- p->h |= m->mask;
- break;
- case FILE_OPXOR:
- p->h ^= m->mask;
- break;
- case FILE_OPADD:
- p->h += m->mask;
- break;
- case FILE_OPMINUS:
- p->h -= m->mask;
- break;
- case FILE_OPMULTIPLY:
- p->h *= m->mask;
- break;
- case FILE_OPDIVIDE:
- p->h /= m->mask;
- break;
- case FILE_OPMODULO:
- p->h %= m->mask;
- break;
- }
- if (m->mask_op & FILE_OPINVERSE)
- p->h = ~p->h;
+ cvt_16(p, m);
return 1;
case FILE_LONG:
case FILE_DATE:
case FILE_LDATE:
- if (m->mask)
- switch (m->mask_op & 0x7F) {
- case FILE_OPAND:
- p->l &= m->mask;
- break;
- case FILE_OPOR:
- p->l |= m->mask;
- break;
- case FILE_OPXOR:
- p->l ^= m->mask;
- break;
- case FILE_OPADD:
- p->l += m->mask;
- break;
- case FILE_OPMINUS:
- p->l -= m->mask;
- break;
- case FILE_OPMULTIPLY:
- p->l *= m->mask;
- break;
- case FILE_OPDIVIDE:
- p->l /= m->mask;
- break;
- case FILE_OPMODULO:
- p->l %= m->mask;
- break;
- }
- if (m->mask_op & FILE_OPINVERSE)
- p->l = ~p->l;
+ cvt_32(p, m);
+ return 1;
+ case FILE_QUAD:
+ case FILE_QDATE:
+ case FILE_QLDATE:
+ cvt_64(p, m);
return 1;
case FILE_STRING:
case FILE_BESTRING16:
@@ -468,172 +550,50 @@ mconvert(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
}
case FILE_BESHORT:
p->h = (short)((p->hs[0]<<8)|(p->hs[1]));
- if (m->mask)
- switch (m->mask_op&0x7F) {
- case FILE_OPAND:
- p->h &= m->mask;
- break;
- case FILE_OPOR:
- p->h |= m->mask;
- break;
- case FILE_OPXOR:
- p->h ^= m->mask;
- break;
- case FILE_OPADD:
- p->h += m->mask;
- break;
- case FILE_OPMINUS:
- p->h -= m->mask;
- break;
- case FILE_OPMULTIPLY:
- p->h *= m->mask;
- break;
- case FILE_OPDIVIDE:
- p->h /= m->mask;
- break;
- case FILE_OPMODULO:
- p->h %= m->mask;
- break;
- }
- if (m->mask_op & FILE_OPINVERSE)
- p->h = ~p->h;
+ cvt_16(p, m);
return 1;
case FILE_BELONG:
case FILE_BEDATE:
case FILE_BELDATE:
p->l = (int32_t)
((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3]));
- if (m->mask)
- switch (m->mask_op&0x7F) {
- case FILE_OPAND:
- p->l &= m->mask;
- break;
- case FILE_OPOR:
- p->l |= m->mask;
- break;
- case FILE_OPXOR:
- p->l ^= m->mask;
- break;
- case FILE_OPADD:
- p->l += m->mask;
- break;
- case FILE_OPMINUS:
- p->l -= m->mask;
- break;
- case FILE_OPMULTIPLY:
- p->l *= m->mask;
- break;
- case FILE_OPDIVIDE:
- p->l /= m->mask;
- break;
- case FILE_OPMODULO:
- p->l %= m->mask;
- break;
- }
- if (m->mask_op & FILE_OPINVERSE)
- p->l = ~p->l;
+ cvt_32(p, m);
+ return 1;
+ case FILE_BEQUAD:
+ case FILE_BEQDATE:
+ case FILE_BEQLDATE:
+ p->q = (int64_t)
+ (((int64_t)p->hq[0]<<56)|((int64_t)p->hq[1]<<48)|
+ ((int64_t)p->hq[2]<<40)|((int64_t)p->hq[3]<<32)|
+ (p->hq[4]<<24)|(p->hq[5]<<16)|(p->hq[6]<<8)|(p->hq[7]));
+ cvt_64(p, m);
return 1;
case FILE_LESHORT:
p->h = (short)((p->hs[1]<<8)|(p->hs[0]));
- if (m->mask)
- switch (m->mask_op&0x7F) {
- case FILE_OPAND:
- p->h &= m->mask;
- break;
- case FILE_OPOR:
- p->h |= m->mask;
- break;
- case FILE_OPXOR:
- p->h ^= m->mask;
- break;
- case FILE_OPADD:
- p->h += m->mask;
- break;
- case FILE_OPMINUS:
- p->h -= m->mask;
- break;
- case FILE_OPMULTIPLY:
- p->h *= m->mask;
- break;
- case FILE_OPDIVIDE:
- p->h /= m->mask;
- break;
- case FILE_OPMODULO:
- p->h %= m->mask;
- break;
- }
- if (m->mask_op & FILE_OPINVERSE)
- p->h = ~p->h;
+ cvt_16(p, m);
return 1;
case FILE_LELONG:
case FILE_LEDATE:
case FILE_LELDATE:
p->l = (int32_t)
((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0]));
- if (m->mask)
- switch (m->mask_op&0x7F) {
- case FILE_OPAND:
- p->l &= m->mask;
- break;
- case FILE_OPOR:
- p->l |= m->mask;
- break;
- case FILE_OPXOR:
- p->l ^= m->mask;
- break;
- case FILE_OPADD:
- p->l += m->mask;
- break;
- case FILE_OPMINUS:
- p->l -= m->mask;
- break;
- case FILE_OPMULTIPLY:
- p->l *= m->mask;
- break;
- case FILE_OPDIVIDE:
- p->l /= m->mask;
- break;
- case FILE_OPMODULO:
- p->l %= m->mask;
- break;
- }
- if (m->mask_op & FILE_OPINVERSE)
- p->l = ~p->l;
+ cvt_32(p, m);
+ return 1;
+ case FILE_LEQUAD:
+ case FILE_LEQDATE:
+ case FILE_LEQLDATE:
+ p->q = (int64_t)
+ (((int64_t)p->hq[7]<<56)|((int64_t)p->hq[6]<<48)|
+ ((int64_t)p->hq[5]<<40)|((int64_t)p->hq[4]<<32)|
+ (p->hq[3]<<24)|(p->hq[2]<<16)|(p->hq[1]<<8)|(p->hq[0]));
+ cvt_64(p, m);
return 1;
case FILE_MELONG:
case FILE_MEDATE:
case FILE_MELDATE:
p->l = (int32_t)
((p->hl[1]<<24)|(p->hl[0]<<16)|(p->hl[3]<<8)|(p->hl[2]));
- if (m->mask)
- switch (m->mask_op&0x7F) {
- case FILE_OPAND:
- p->l &= m->mask;
- break;
- case FILE_OPOR:
- p->l |= m->mask;
- break;
- case FILE_OPXOR:
- p->l ^= m->mask;
- break;
- case FILE_OPADD:
- p->l += m->mask;
- break;
- case FILE_OPMINUS:
- p->l -= m->mask;
- break;
- case FILE_OPMULTIPLY:
- p->l *= m->mask;
- break;
- case FILE_OPDIVIDE:
- p->l /= m->mask;
- break;
- case FILE_OPMODULO:
- p->l %= m->mask;
- break;
- }
- if (m->mask_op & FILE_OPINVERSE)
- p->l = ~p->l;
+ cvt_32(p, m);
return 1;
case FILE_REGEX:
case FILE_SEARCH:
@@ -656,7 +616,7 @@ mdebug(uint32_t offset, const char *str, size_t len)
private int
mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
- const unsigned char *s, size_t offset, size_t nbytes)
+ const unsigned char *s, uint32_t offset, size_t nbytes)
{
if (type == FILE_REGEX && indir == 0) {
/*
@@ -670,7 +630,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
return 0;
}
if ((p->search.buf = strdup((const char *)s)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, strlen((const char *)s));
return -1;
}
for (b = p->search.buf; offset &&
@@ -694,6 +654,13 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
if (type == FILE_BESTRING16)
src++;
+ /* check for pointer overflow */
+ if (src < s) {
+ file_error(ms, 0, "invalid offset %zu in mcopy()",
+ offset);
+ return -1;
+ }
+
for (;src < esrc; src++, dst++) {
if (dst < edst)
*dst = *src++;
@@ -731,7 +698,7 @@ private int
mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s,
struct magic *m, size_t nbytes, unsigned int cont_level)
{
- uint32_t offset = m->offset;
+ uint32_t offset = ms->offset;
if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes) == -1)
return -1;
@@ -1208,7 +1175,7 @@ mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s,
if (m->flag & INDIROFFADD) offset += ms->c.off[cont_level-1];
if (mcopy(ms, p, m->type, 0, s, offset, nbytes) == -1)
return -1;
- m->offset = offset;
+ ms->offset = offset;
if ((ms->flags & MAGIC_DEBUG) != 0) {
mdebug(offset, (char *)(void *)p,
@@ -1257,7 +1224,7 @@ mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s,
}
if (m->type == FILE_SEARCH) {
- size_t mlen = m->mask + m->vallen;
+ size_t mlen = (size_t)(m->mask + m->vallen);
size_t flen = nbytes - offset;
if (flen < mlen)
mlen = flen;
@@ -1276,10 +1243,10 @@ mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s,
}
private int
-mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
+magiccheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
{
- uint32_t l = m->value.l;
- uint32_t v;
+ uint64_t l = m->value.q;
+ uint64_t v;
int matched;
if ( (m->value.s[0] == 'x') && (m->value.s[1] == '\0') ) {
@@ -1313,6 +1280,18 @@ mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
v = p->l;
break;
+ case FILE_QUAD:
+ case FILE_LEQUAD:
+ case FILE_BEQUAD:
+ case FILE_QDATE:
+ case FILE_BEQDATE:
+ case FILE_LEQDATE:
+ case FILE_QLDATE:
+ case FILE_BEQLDATE:
+ case FILE_LEQLDATE:
+ v = p->q;
+ break;
+
case FILE_STRING:
case FILE_BESTRING16:
case FILE_LESTRING16:
@@ -1408,21 +1387,25 @@ mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
while (len-- > 0 && (v = *b++ - *a++) == 0)
continue;
if (!v) {
- m->offset += range - 1;
+ ms->offset += range - 1;
break;
}
- if (range + slen >= p->search.buflen)
+ if (range + slen >= p->search.buflen) {
+ v = 1;
break;
+ }
len = slen;
a = (unsigned char*)m->value.s;
b = (unsigned char*)p->search.buf + range;
}
free(p->search.buf);
p->search.buf = NULL;
+ if (v)
+ return 0;
break;
}
default:
- file_error(ms, 0, "invalid type %d in mcheck()", m->type);
+ file_error(ms, 0, "invalid type %d in magiccheck()", m->type);
return -1;
}
@@ -1432,36 +1415,40 @@ mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
switch (m->reln) {
case 'x':
if ((ms->flags & MAGIC_DEBUG) != 0)
- (void) fprintf(stderr, "%u == *any* = 1\n", v);
+ (void) fprintf(stderr, "%llu == *any* = 1\n",
+ (unsigned long long)v);
matched = 1;
break;
case '!':
matched = v != l;
if ((ms->flags & MAGIC_DEBUG) != 0)
- (void) fprintf(stderr, "%u != %u = %d\n",
- v, l, matched);
+ (void) fprintf(stderr, "%llu != %llu = %d\n",
+ (unsigned long long)v, (unsigned long long)l,
+ matched);
break;
case '=':
matched = v == l;
if ((ms->flags & MAGIC_DEBUG) != 0)
- (void) fprintf(stderr, "%u == %u = %d\n",
- v, l, matched);
+ (void) fprintf(stderr, "%llu == %llu = %d\n",
+ (unsigned long long)v, (unsigned long long)l,
+ matched);
break;
case '>':
if (m->flag & UNSIGNED) {
matched = v > l;
if ((ms->flags & MAGIC_DEBUG) != 0)
- (void) fprintf(stderr, "%u > %u = %d\n",
- v, l, matched);
+ (void) fprintf(stderr, "%llu > %llu = %d\n",
+ (unsigned long long)v,
+ (unsigned long long)l, matched);
}
else {
matched = (int32_t) v > (int32_t) l;
if ((ms->flags & MAGIC_DEBUG) != 0)
- (void) fprintf(stderr, "%d > %d = %d\n",
- v, l, matched);
+ (void) fprintf(stderr, "%lld > %lld = %d\n",
+ (long long)v, (long long)l, matched);
}
break;
@@ -1469,29 +1456,32 @@ mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
if (m->flag & UNSIGNED) {
matched = v < l;
if ((ms->flags & MAGIC_DEBUG) != 0)
- (void) fprintf(stderr, "%u < %u = %d\n",
- v, l, matched);
+ (void) fprintf(stderr, "%llu < %llu = %d\n",
+ (unsigned long long)v,
+ (unsigned long long)l, matched);
}
else {
matched = (int32_t) v < (int32_t) l;
if ((ms->flags & MAGIC_DEBUG) != 0)
- (void) fprintf(stderr, "%d < %d = %d\n",
- v, l, matched);
+ (void) fprintf(stderr, "%lld < %lld = %d\n",
+ (long long)v, (long long)l, matched);
}
break;
case '&':
matched = (v & l) == l;
if ((ms->flags & MAGIC_DEBUG) != 0)
- (void) fprintf(stderr, "((%x & %x) == %x) = %d\n",
- v, l, l, matched);
+ (void) fprintf(stderr, "((%llx & %llx) == %llx) = %d\n",
+ (unsigned long long)v, (unsigned long long)l,
+ (unsigned long long)l, matched);
break;
case '^':
matched = (v & l) != l;
if ((ms->flags & MAGIC_DEBUG) != 0)
- (void) fprintf(stderr, "((%x & %x) != %x) = %d\n",
- v, l, l, matched);
+ (void) fprintf(stderr, "((%llx & %llx) != %llx) = %d\n",
+ (unsigned long long)v, (unsigned long long)l,
+ (unsigned long long)l, matched);
break;
default:
@@ -1503,3 +1493,15 @@ mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
return matched;
}
+
+private int
+print_sep(struct magic_set *ms, int firstline)
+{
+ if (firstline)
+ return 0;
+ /*
+ * we found another match
+ * put a newline and '-' to do some simple formatting
+ */
+ return file_printf(ms, "\n- ");
+}
diff --git a/contrib/file/tar.h b/contrib/file/tar.h
index c3fc185eec14..4fb4276fb390 100644
--- a/contrib/file/tar.h
+++ b/contrib/file/tar.h
@@ -32,7 +32,7 @@
*
* Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
*
- * $Id: tar.h,v 1.8 2004/09/11 19:15:58 christos Exp $ # checkin only
+ * $Id: tar.h,v 1.9 2006/05/03 15:19:25 christos Exp $ # checkin only
*/
/*
@@ -82,7 +82,8 @@ union record {
#define CHKBLANKS " " /* 8 blanks, no null */
/* The magic field is filled with this if uname and gname are valid. */
-#define TMAGIC "ustar " /* 7 chars and a null */
+#define TMAGIC "ustar" /* 5 chars and a null */
+#define GNUTMAGIC "ustar " /* 7 chars and a null */
/* The linkflag defines the type of file */
#define LF_OLDNORMAL '\0' /* Normal disk file, Unix compat */