there is no conflict, you are receding

This commit is contained in:
pooka 2003-05-25 21:46:09 +00:00
parent 707e8ba692
commit 90651bdae0
11 changed files with 208 additions and 103 deletions

View File

@ -143,10 +143,10 @@ RECURSIVE_TARGETS = info-recursive dvi-recursive pdf-recursive \
all-recursive install-data-recursive install-exec-recursive \
installdirs-recursive install-recursive uninstall-recursive \
check-recursive installcheck-recursive
DIST_COMMON = README Makefile.am Makefile.in acconfig.h acinclude.m4 \
aclocal.m4 config.guess config.h.in config.sub configure \
configure.in depcomp install-sh ltcf-c.sh ltconfig ltmain.sh \
missing mkinstalldirs
DIST_COMMON = README ChangeLog Makefile.am Makefile.in acconfig.h \
acinclude.m4 aclocal.m4 config.guess config.h.in config.sub \
configure configure.in depcomp install-sh ltcf-c.sh ltconfig \
ltmain.sh missing mkinstalldirs
DIST_SUBDIRS = $(SUBDIRS)
all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-recursive

13
dist/file/README vendored
View File

@ -1,5 +1,5 @@
** README for file(1) Command **
@(#) Id: README,v 1.31 2003/03/24 15:01:39 christos Exp
@(#) Id: README,v 1.33 2003/05/23 21:31:56 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,
@ -39,7 +39,7 @@ In addition, the /etc/magic file is built from a subdirectory
for easier(?) maintenance. I will act as a clearinghouse for
magic numbers assigned to all sorts of data files that
are in reasonable circulation. Send your magic numbers,
in magic(4) format please, to the maintainer, Christos Zoulas.
in magic(5) format please, to the maintainer, Christos Zoulas.
LEGAL.NOTICE - read this first.
README - read this second (you are currently reading this file).
@ -89,11 +89,10 @@ E-mail: christos@astron.com
Phone: Do not even think of telephoning me about this program. Send cash first!
Parts of this software were developed at SoftQuad Inc., 56 Aberfoyle
Cres, # 810, Toronto, Ontario CANADA M8X 2W4. Phone: 416-239-4801 or
800-387-2777. Email: mail@sq.com. Call for information on SGML editing
and browsing, Unix text processing, and customised products on Unix,
DOS and Mac.
Parts of this software were developed at SoftQuad Inc., developers
of SGML/HTML/XML publishing software, in Toronto, Canada.
SoftQuad was swallowed up by Corel in 2002
and does not exist any longer.
From: Kees Zeelenberg

2
dist/file/configure vendored
View File

@ -1555,7 +1555,7 @@ fi
# Define the identity of the package.
PACKAGE=file
VERSION=4.00
VERSION=4.03
cat >>confdefs.h <<_ACEOF

View File

@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/file.c)
AM_INIT_AUTOMAKE(file, 4.00)
AM_INIT_AUTOMAKE(file, 4.03)
AM_CONFIG_HEADER(config.h)
AM_MAINTAINER_MODE

87
dist/file/doc/file.1 vendored
View File

@ -1,20 +1,24 @@
.\" $NetBSD: file.1,v 1.2 2003/03/26 00:20:43 pooka Exp $
.\" $NetBSD: file.1,v 1.3 2003/05/25 21:46:10 pooka Exp $
.\"
.TH FILE 1 "Copyright but distributable"
.\" Id: file.man,v 1.45 2003/03/23 04:19:49 christos Exp
.\" Id: file.man,v 1.49 2003/05/23 21:31:57 christos Exp
.SH NAME
file
\- determine file type
.SH SYNOPSIS
.B file
[
.B \-bciknsvzL
.B \-bcikLnNsvz
]
[
.B \-f
.I namefile
]
[
.B \-F
.I separator
]
[
.B \-m
.I magicfiles
]
@ -27,7 +31,7 @@ file
.B \-m
magicfile ]
.SH DESCRIPTION
This manual page documents version 4.00 of the
This manual page documents version 4.03 of the
.B file
command.
.PP
@ -151,20 +155,20 @@ Any file that cannot be identified as having been written
in any of the character sets listed above is simply said to be ``data''.
.SH OPTIONS
.TP 8
.B \-b
.B "\-b, \-\-brief"
Do not prepend filenames to output lines (brief mode).
.TP 8
.B \-c
.B "\-c, \-\-checking\-printout"
Cause a checking printout of the parsed form of the magic file.
This is usually used in conjunction with
.B \-m
to debug a new magic file before installing it.
.TP 8
.B \-C
.B "\-C, \-\-compile"
Write a magic.mgc output file that contains a pre-parsed version of
file.
.TP 8
.BI \-f " namefile"
.BI "\-f, \-\-files\-from" " namefile"
Read the names of the files to be examined from
.I namefile
(one per line)
@ -174,7 +178,11 @@ Either
or at least one filename argument must be present;
to test the standard input, use ``\-'' as a filename argument.
.TP 8
.B \-i
.BI "\-F, \-\-separator" " separator"
Use the specified string as the separator between the filename and the
file result returned. Defaults to ``:''.
.TP 8
.B "\-i, \-\-mime"
Causes the file command to output mime type strings rather than the more
traditional human readable ones. Thus it may say
``text/plain; charset=us-ascii''
@ -186,30 +194,28 @@ text file types, directories etc), and makes use of an alternative
``magic'' file.
(See ``FILES'' section, below).
.TP 8
.B \-k
.B "\-k, \-\-keep\-going"
Don't stop at the first match, keep going.
.TP 8
.BI \-m " list"
Specify an alternate list of files containing magic numbers.
This can be a single file, or a colon-separated list of files.
.TP 8
.B \-n
Force stdout to be flushed after checking each file.
This is only useful if checking a list of files.
It is intended to be used by programs that want filetype output from a pipe.
.TP 8
.B \-v
Print the version of the program and exit.
.TP 8
.B \-z
Try to look inside compressed files.
.TP 8
.B \-L
.B "\-L, \-\-dereference"
option causes symlinks to be followed, as the like-named option in
.BR ls (1).
(on systems that support symbolic links).
.TP 8
.B \-s
.BI "\-m, \-\-magic\-file" " list"
Specify an alternate list of files containing magic numbers.
This can be a single file, or a colon-separated list of files.
If a compiled magic file is found alongside, it will be used instead.
.TP 8
.B "\-n, \-\-no\-buffer"
Force stdout to be flushed after checking each file.
This is only useful if checking a list of files.
It is intended to be used by programs that want filetype output from a pipe.
.TP 8
.B "\-N, \-\-no\-pad"
Don't pad filenames so that they align in the output.
.TP 8
.B "\-s, \-\-special\-files"
Normally,
.B file
only attempts to read and determine the type of argument files which
@ -229,16 +235,33 @@ This option also causes
to disregard the file size as reported by
.BR stat (2)
since on some systems it reports a zero size for raw disk partitions.
.TP 8
.B "\-v, \-\-version"
Print the version of the program and exit.
.TP 8
.B "\-z, \-\-uncompress"
Try to look inside compressed files.
.TP 8
.B "\-\-help"
Print a help message and exit.
.SH FILES
.TP
.I /usr/share/misc/magic.mgc
\- defaults compiled list of magic numbers
.PP
Default compiled list of magic numbers
.TP
.I /usr/share/misc/magic
\- default list of magic numbers
.PP
Default list of magic numbers
.TP
.I /usr/share/misc/magic.mime.mgc
Default compiled list of magic numbers, used to output mime types when
the -i option is specified.
.TP
.I /usr/share/misc/magic.mime
\- default list of magic numbers, used to output mime types when the -i option
Default list of magic numbers, used to output mime types when the -i option
is specified.
.TP
.I /etc/magic
Local additions to magic wisdom.
.SH ENVIRONMENT
The environment variable

13
dist/file/doc/magic.5 vendored
View File

@ -1,4 +1,4 @@
.\" $NetBSD: magic.5,v 1.3 2003/03/31 17:09:30 perry Exp $
.\" $NetBSD: magic.5,v 1.4 2003/05/25 21:46:10 pooka Exp $
.\"
.TH MAGIC 5 "Public Domain"
.\" install as magic.4 on USG, magic.5 on V7 or Berkeley systems.
@ -8,7 +8,7 @@ magic \- file command's magic number file
This manual page documents the format of the magic file as
used by the
.BR file (1)
command, version 4.00.
command, version 4.03.
The
.BR file
command identifies the type of a file using,
@ -46,7 +46,10 @@ The string type specification can be optionally followed
by /[Bbc]*.
The ``B'' flag compacts whitespace in the target, which must
contain at least one whitespace character.
If the magic has "n" consecutive blanks, the target needs at least "n"
If the magic has
.I n
consecutive blanks, the target needs at least
.I n
consecutive blanks to match.
The ``b'' flag treats every blank in the target as an optional blank.
Finally the ``c'' flag, specifies case insensitive matching: lowercase
@ -179,7 +182,7 @@ the file.
The value at that offset is read, and is used again as an offset
in the file.
Indirect offsets are of the form:
.BI (( x [.[bslBSL]][+-][ y ]).
.BI (( x [.[bslBSL]][+\-][ y ]).
The value of
.I x
is used as an offset in the file. A byte, short or long is read at that offset
@ -239,4 +242,4 @@ indirect offsets.
.\" the changes I posted to the S5R2 version.
.\"
.\" Modified for Ian Darwin's version of the file command.
.\" @(#)Id: magic.man,v 1.23 2003/03/23 04:19:49 christos Exp
.\" @(#)Id: magic.man,v 1.26 2003/05/23 21:31:57 christos Exp

View File

@ -122,7 +122,7 @@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
data_DATA = magic magic.mime magic.mgc magic.mime.mgc
pkgdata_DATA = magic magic.mime magic.mgc magic.mime.mgc
EXTRA_DIST = magic2mime Localstuff Header magic.mime $(magic_FRAGMENTS)
@ -159,6 +159,7 @@ Magdir/citrus \
Magdir/claris \
Magdir/clipper \
Magdir/commands \
Magdir/communications \
Magdir/compress \
Magdir/console \
Magdir/convex \
@ -175,12 +176,14 @@ Magdir/editors \
Magdir/elf \
Magdir/encore \
Magdir/epoc \
Magdir/fcs \
Magdir/filesystems \
Magdir/flash \
Magdir/fonts \
Magdir/frame \
Magdir/freebsd \
Magdir/fsav \
Magdir/games \
Magdir/gimp \
Magdir/gnu \
Magdir/grace \
@ -215,6 +218,7 @@ Magdir/mcrypt \
Magdir/mime \
Magdir/mips \
Magdir/mirage \
Magdir/misctools \
Magdir/mkid \
Magdir/mlssa \
Magdir/mmdf \
@ -228,6 +232,7 @@ Magdir/netbsd \
Magdir/netscape \
Magdir/news \
Magdir/nitpicker \
Magdir/ocaml \
Magdir/octave \
Magdir/olf \
Magdir/os2 \
@ -257,6 +262,7 @@ Magdir/sendmail \
Magdir/sequent \
Magdir/sgml \
Magdir/sharc \
Magdir/sinclair \
Magdir/sketch \
Magdir/smalltalk \
Magdir/sniffer \
@ -284,7 +290,7 @@ Magdir/vms \
Magdir/vmware \
Magdir/vorbis \
Magdir/vxl \
Magdir/wordperfect \
Magdir/wordprocessors \
Magdir/xdelta \
Magdir/xenix \
Magdir/zilog \
@ -295,7 +301,7 @@ mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
DIST_SOURCES =
DATA = $(data_DATA)
DATA = $(pkgdata_DATA)
DIST_COMMON = Makefile.am Makefile.in
all: all-am
@ -316,23 +322,23 @@ clean-libtool:
distclean-libtool:
-rm -f libtool
uninstall-info-am:
dataDATA_INSTALL = $(INSTALL_DATA)
install-dataDATA: $(data_DATA)
pkgdataDATA_INSTALL = $(INSTALL_DATA)
install-pkgdataDATA: $(pkgdata_DATA)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(datadir)
@list='$(data_DATA)'; for p in $$list; do \
$(mkinstalldirs) $(DESTDIR)$(pkgdatadir)
@list='$(pkgdata_DATA)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f="`echo $$p | sed -e 's|^.*/||'`"; \
echo " $(dataDATA_INSTALL) $$d$$p $(DESTDIR)$(datadir)/$$f"; \
$(dataDATA_INSTALL) $$d$$p $(DESTDIR)$(datadir)/$$f; \
echo " $(pkgdataDATA_INSTALL) $$d$$p $(DESTDIR)$(pkgdatadir)/$$f"; \
$(pkgdataDATA_INSTALL) $$d$$p $(DESTDIR)$(pkgdatadir)/$$f; \
done
uninstall-dataDATA:
uninstall-pkgdataDATA:
@$(NORMAL_UNINSTALL)
@list='$(data_DATA)'; for p in $$list; do \
@list='$(pkgdata_DATA)'; for p in $$list; do \
f="`echo $$p | sed -e 's|^.*/||'`"; \
echo " rm -f $(DESTDIR)$(datadir)/$$f"; \
rm -f $(DESTDIR)$(datadir)/$$f; \
echo " rm -f $(DESTDIR)$(pkgdatadir)/$$f"; \
rm -f $(DESTDIR)$(pkgdatadir)/$$f; \
done
tags: TAGS
TAGS:
@ -378,7 +384,7 @@ check: check-am
all-am: Makefile $(DATA)
installdirs:
$(mkinstalldirs) $(DESTDIR)$(datadir)
$(mkinstalldirs) $(DESTDIR)$(pkgdatadir)
install: install-am
install-exec: install-exec-am
@ -421,7 +427,7 @@ info: info-am
info-am:
install-data-am: install-dataDATA
install-data-am: install-pkgdataDATA
install-exec-am:
@ -447,17 +453,17 @@ ps: ps-am
ps-am:
uninstall-am: uninstall-dataDATA uninstall-info-am
uninstall-am: uninstall-info-am uninstall-pkgdataDATA
.PHONY: all all-am check check-am clean clean-generic clean-libtool \
distclean distclean-generic distclean-libtool distdir dvi \
dvi-am info info-am install install-am install-data \
install-data-am install-dataDATA install-exec install-exec-am \
install-info install-info-am install-man install-strip \
install-data-am install-exec install-exec-am install-info \
install-info-am install-man install-pkgdataDATA install-strip \
installcheck installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-generic \
mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am \
uninstall-dataDATA uninstall-info-am
uninstall-info-am uninstall-pkgdataDATA
magic: Header Localstuff $(magic_FRAGMENTS)

View File

@ -93,14 +93,15 @@
>14 string >/0 ultratracker V1.%.1s module sound data
0 string UN05 MikMod UNI format module sound data
0 string Extended\ Module: Fasttracker II module sound data
21 string !SCREAM! Screamtracker 2 module sound data
21 string/c !SCREAM! Screamtracker 2 module sound data
21 string BMOD2STM Screamtracker 2 module sound data
1080 string M.K. 4-channel Protracker module sound data
1080 string M!K! 4-channel Protracker module sound data
1080 string FLT4 4-channel Startracker module sound data
1080 string 4CHN 4-channel Fasttracker module sound data
1080 string 6CHN 6-channel Fasttracker module sound data
1080 string 8CHN 8-channel Fasttracker module sound data
1080 string CD81 8-channel Oktalyzer module sound data
1080 string CD81 8-channel Octalyser module sound data
1080 string OKTA 8-channel Oktalyzer module sound data
# Not good enough.
#1082 string CH
@ -244,3 +245,16 @@
# From: Dan Fandrich <dan@coneharvesters.com>
0 string fLaC FLAC audio stream data
# (ISDN) VBOX voice message file (Wolfram Kleff)
0 string VBOX VBOX voice message data
# ReBorn Song Files (.rbs)
# David J. Singer <doc@deadvirgins.org.uk>
8 string RB40 RBS Song file
>29 string ReBorn created by ReBorn
>37 string Propellerhead created by ReBirth
# Synthesizer Generator and Kimwitu share their file format
0 string A#S#C#S#S#L#V#3 Synthesizer Generator or Kimwitu data
# Kimwitu++ uses a slightly different magic
0 string A#S#C#S#S#L#HUB Kimwitu++ data

View File

@ -37,6 +37,8 @@
>8 string RMMP \b, multimedia movie
# Microsoft WAVE format (*.wav)
>8 string WAVE \b, WAVE audio
# Corel Draw Picture
>8 string CDRA \b, Corel Draw Picture
>>20 leshort 1 \b, Microsoft PCM
>>>34 leshort >0 \b, %d bit
>>20 leshort 2 \b, Microsoft ADPCM
@ -56,6 +58,8 @@
>8 string AVI\ \b, AVI
# Animated Cursor format
>8 string ACON \b, animated cursor
# Corel Draw Picture
>8 string CDRA \b, Corel Draw Picture
#
# XXX - some of the below may only appear in little-endian form.
@ -87,6 +91,8 @@
>8 string RMMP \b, multimedia movie
# Microsoft WAVE format (*.wav)
>8 string WAVE \b, WAVE audio
# Corel Draw Picture
>8 string CDRA \b, Corel Draw Picture
>>20 leshort 1 \b, Microsoft PCM
>>>34 leshort >0 \b, %d bit
>>22 beshort =1 \b, mono
@ -99,6 +105,8 @@
>8 string ACON \b, animated cursor
# Notation Interchange File Format (big-endian only)
>8 string NIFF \b, Notation Interchange File Format
# Corel Draw Picture
>8 string CDRA \b, Corel Draw Picture
# SoundFont 2 <mpruett@sgi.com>
>8 string sfbk SoundFont 2

60
dist/file/src/file.h vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: file.h,v 1.2 2003/04/15 21:36:18 pooka Exp $ */
/* $NetBSD: file.h,v 1.3 2003/05/25 21:46:10 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -34,7 +34,7 @@
*/
/*
* file.h - definitions for file(1) program
* @(#)Id: file.h,v 1.48 2003/03/24 01:16:28 christos Exp
* @(#)Id: file.h,v 1.55 2003/05/23 21:31:58 christos Exp
*/
#ifndef __file_h__
@ -74,26 +74,25 @@
# define HOWMANY 65536 /* how much of the file to look at */
#endif
#define MAXMAGIS 4096 /* max entries in /etc/magic */
#define MAXDESC 50 /* max leng of text description */
#define MAXDESC 64 /* max leng of text description */
#define MAXstring 32 /* max leng of "string" types */
#define MAGICNO 0xF11E041C
#define VERSIONNO 1
#define VERSIONNO 2
#define FILE_MAGICSIZE (32 * 4)
#define FILE_CHECK 1
#define FILE_COMPILE 2
#ifndef __GNUC__
#define __attribute__(a)
#endif
struct magic {
/* Word 1 */
uint16_t cont_level; /* level of ">" */
uint8_t nospflag; /* supress space character */
uint8_t flag;
#define INDIR 1 /* if '>(...)' appears, */
#define UNSIGNED 2 /* comparison is unsigned */
#define OFFADD 4 /* if '>&' appears, */
/* Word 2 */
uint8_t reln; /* relation (0=eq, '>'=gt, etc) */
uint8_t vallen; /* length of string value, if any */
uint8_t type; /* int, short, long or string. */
@ -114,19 +113,32 @@ struct magic {
#define FILE_BELDATE 15
#define FILE_LELDATE 16
#define FILE_REGEX 17
/* Word 3 */
uint8_t in_op; /* operator for indirection */
uint8_t mask_op; /* operator for mask */
#define FILE_OPAND 1
#define FILE_OPOR 2
#define FILE_OPXOR 3
#define FILE_OPADD 4
#define FILE_OPMINUS 5
#define FILE_OPMULTIPLY 6
#define FILE_OPDIVIDE 7
#define FILE_OPMODULO 8
uint8_t dummy1;
uint8_t dummy2;
#define FILE_OPS "&|^+-*/%"
#define FILE_OPAND 0
#define FILE_OPOR 1
#define FILE_OPXOR 2
#define FILE_OPADD 3
#define FILE_OPMINUS 4
#define FILE_OPMULTIPLY 5
#define FILE_OPDIVIDE 6
#define FILE_OPMODULO 7
#define FILE_OPINVERSE 0x80
int32_t offset; /* offset to magic number */
int32_t in_offset; /* offset from indirection */
/* Word 4 */
uint32_t offset; /* offset to magic number */
/* Word 5 */
uint32_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;
/* Words 9-16 */
union VALUETYPE {
uint8_t b;
uint16_t h;
@ -136,9 +148,9 @@ struct magic {
uint8_t hs[2]; /* 2 bytes of a fixed-endian "short" */
uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */
} value; /* either number or string */
uint32_t mask; /* mask before comparison with value */
/* Words 17..31 */
char desc[MAXDESC]; /* description */
} __attribute__((__packed__));
};
#define BIT(A) (1 << (A))
#define STRING_IGNORE_LOWERCASE BIT(0)
@ -176,8 +188,8 @@ struct magic_set {
};
struct stat;
protected char *file_fmttime(long, int);
protected int file_buffer(struct magic_set *, const void *buf, size_t);
protected char *file_fmttime(uint32_t, int);
protected int file_buffer(struct magic_set *, const void *, size_t);
protected int file_fsmagic(struct magic_set *, const char *, struct stat *);
protected int file_pipe2file(struct magic_set *, int, const void *, size_t);
protected int file_printf(struct magic_set *, const char *, ...);
@ -185,7 +197,7 @@ protected int file_reset(struct magic_set *);
protected int file_tryelf(struct magic_set *, int, const unsigned char *, size_t);
protected int file_zmagic(struct magic_set *, const unsigned char *, size_t);
protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t);
protected int file_is_tar(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);
@ -195,7 +207,7 @@ protected void file_oomem(struct magic_set *);
protected void file_error(struct magic_set *, const char *, ...);
protected void file_magwarn(const char *, ...);
protected void file_mdump(struct magic *);
protected void file_showstr(FILE *, const char *, int);
protected void file_showstr(FILE *, const char *, size_t);
#ifndef HAVE_STRERROR
extern int sys_nerr;

56
dist/file/src/magic.c vendored
View File

@ -1,5 +1,33 @@
/* $NetBSD: magic.c,v 1.3 2003/03/25 23:41:17 pooka Exp $ */
/* $NetBSD: magic.c,v 1.4 2003/05/25 21:46:11 pooka Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice immediately at the beginning of the file, without modification,
* this list of conditions, and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "magic.h"
#include "file.h"
@ -39,9 +67,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: magic.c,v 1.5 2003/03/24 01:34:21 christos Exp")
FILE_RCSID("@(#)Id: magic.c,v 1.7 2003/05/23 21:31:58 christos Exp")
#else
__RCSID("$NetBSD: magic.c,v 1.3 2003/03/25 23:41:17 pooka Exp $");
__RCSID("$NetBSD: magic.c,v 1.4 2003/05/25 21:46:11 pooka Exp $");
#endif
#endif /* lint */
@ -168,7 +196,7 @@ magic_file(struct magic_set *ms, const char *inname)
int fd = 0;
unsigned char buf[HOWMANY+1]; /* one extra for terminating '\0' */
struct stat sb;
int nbytes = 0; /* number of bytes read from a datafile */
ssize_t nbytes = 0; /* number of bytes read from a datafile */
if (file_reset(ms) == -1)
return NULL;
@ -182,7 +210,12 @@ magic_file(struct magic_set *ms, const char *inname)
return ms->o.buf;
}
if ((fd = open(inname, O_RDONLY)) < 0) {
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif
if (inname == NULL)
fd = STDIN_FILENO;
else if ((fd = open(inname, O_RDONLY)) < 0) {
/* We can't open it, but we were able to stat it. */
if (sb.st_mode & 0002)
if (file_printf(ms, "writable, ") == -1)
@ -198,18 +231,22 @@ magic_file(struct magic_set *ms, const char *inname)
*/
if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) {
file_error(ms, "Cannot read `%s' %s", inname, strerror(errno));
(void)close(fd);
return NULL;
}
if (nbytes == 0) {
if (file_printf(ms, (ms->flags & MAGIC_MIME) ?
"application/x-empty" : "empty") == -1)
"application/x-empty" : "empty") == -1) {
(void)close(fd);
return NULL;
}
} else {
buf[nbytes++] = '\0'; /* null-terminate it */
#ifdef __EMX__
switch (file_os2_apptype(ms, inname, buf, nbytes)) {
case -1:
(void)close(fd);
return NULL;
case 0:
break;
@ -217,8 +254,10 @@ magic_file(struct magic_set *ms, const char *inname)
return ms->o.buf;
}
#endif
if (file_buffer(ms, buf, nbytes) == -1)
if (file_buffer(ms, buf, (size_t)nbytes) == -1) {
(void)close(fd);
return NULL;
}
#ifdef BUILTIN_ELF
if (nbytes > 5) {
/*
@ -229,11 +268,12 @@ magic_file(struct magic_set *ms, const char *inname)
* information from the ELF headers that can't easily
* be extracted with rules in the magic file.
*/
file_tryelf(ms, fd, buf, nbytes);
file_tryelf(ms, fd, buf, (size_t)nbytes);
}
#endif
}
close(fd);
return ms->haderr ? NULL : ms->o.buf;
}