NetBSD/usr.bin/file/file.h

167 lines
5.1 KiB
C
Raw Normal View History

2000-05-15 02:53:37 +04:00
/* $NetBSD: file.h,v 1.19 2000/05/14 22:53:38 christos Exp $ */
1997-01-09 23:18:21 +03:00
1993-03-21 12:45:37 +03:00
/*
* file.h - definitions for file(1) program
2000-05-15 02:53:37 +04:00
* @(#)Id: file.h,v 1.31 2000/04/11 02:32:35 christos Exp
1993-03-21 12:45:37 +03:00
*
* Copyright (c) Ian F. Darwin, 1987.
* Written by Ian F. Darwin.
*
* This software is not subject to any license of the American Telephone
* and Telegraph Company or of the Regents of the University of California.
*
* Permission is granted to anyone to use this software for any purpose on
* any computer system, and to alter it and redistribute it freely, subject
* to the following restrictions:
*
* 1. The author is not responsible for the consequences of use of this
* software, no matter how awful, even if they arise from flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits must appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits must appear in the documentation.
*
* 4. This notice may not be removed or altered.
*/
1997-01-28 03:49:36 +03:00
#ifndef __file_h__
#define __file_h__
#include <inttypes.h>
1999-11-01 20:39:26 +03:00
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
1997-01-28 03:49:36 +03:00
typedef int int32;
typedef unsigned int uint32;
1995-04-28 23:23:38 +04:00
#ifndef HOWMANY
1999-11-01 20:39:26 +03:00
# define HOWMANY 16384 /* how much of the file to look at */
1995-04-28 23:23:38 +04:00
#endif
#define MAXMAGIS 4096 /* max entries in /etc/magic */
1993-03-21 12:45:37 +03:00
#define MAXDESC 50 /* max leng of text description */
#define MAXstring 32 /* max leng of "string" types */
struct magic {
short flag;
#define INDIR 1 /* if '>(...)' appears, */
#define UNSIGNED 2 /* comparison is unsigned */
1996-10-06 00:20:24 +04:00
#define ADD 4 /* if '>&' appears, */
short cont_level; /* level of ">" */
struct {
1999-11-01 20:39:26 +03:00
unsigned char type; /* byte short long */
1997-01-28 03:49:36 +03:00
int32 offset; /* offset from indirection */
} in;
1997-01-28 03:49:36 +03:00
int32 offset; /* offset to magic number */
unsigned char reln; /* relation (0=eq, '>'=gt, etc) */
unsigned char type; /* int, short, long or string. */
1993-03-21 12:45:37 +03:00
char vallen; /* length of string value, if any */
#define BYTE 1
#define SHORT 2
#define LONG 4
#define STRING 5
#define DATE 6
#define BESHORT 7
#define BELONG 8
#define BEDATE 9
#define LESHORT 10
#define LELONG 11
#define LEDATE 12
1993-03-21 12:45:37 +03:00
union VALUETYPE {
unsigned char b;
unsigned short h;
1997-01-28 03:49:36 +03:00
uint32 l;
1993-03-21 12:45:37 +03:00
char s[MAXstring];
unsigned char hs[2]; /* 2 bytes of a fixed-endian "short" */
unsigned char hl[4]; /* 2 bytes of a fixed-endian "long" */
1993-03-21 12:45:37 +03:00
} value; /* either number or string */
1997-01-28 03:49:36 +03:00
uint32 mask; /* mask before comparison with value */
char nospflag; /* supress space character */
1993-03-21 12:45:37 +03:00
char desc[MAXDESC]; /* description */
};
2000-05-15 02:53:37 +04:00
#define BIT(A) (1 << (A))
#define STRING_IGNORE_LOWERCASE BIT(0)
#define STRING_COMPACT_BLANK BIT(1)
#define STRING_COMPACT_OPTIONAL_BLANK BIT(2)
#define CHAR_IGNORE_LOWERCASE 'c'
#define CHAR_COMPACT_BLANK 'B'
#define CHAR_COMPACT_OPTIONAL_BLANK 'b'
#include <stdio.h> /* Include that here, to make sure __P gets defined */
#include <errno.h>
#ifndef __P
1999-11-01 20:39:26 +03:00
# if defined(__STDC__) || defined(__cplusplus)
# define __P(a) a
# else
# define __P(a) ()
# define const
# endif
#endif
1998-09-20 19:27:15 +04:00
extern int apprentice __P((const char *, int));
extern int ascmagic __P((unsigned char *, int));
extern void error __P((const char *, ...));
extern void ckfputs __P((const char *, FILE *));
struct stat;
extern int fsmagic __P((const char *, struct stat *));
extern int is_compress __P((const unsigned char *, int *));
1995-03-26 01:35:28 +03:00
extern int is_tar __P((unsigned char *, int));
extern void magwarn __P((const char *, ...));
extern void mdump __P((struct magic *));
extern void process __P((const char *, int));
1995-03-26 01:35:28 +03:00
extern void showstr __P((FILE *, const char *, int));
extern int softmagic __P((unsigned char *, int));
1995-05-21 04:13:24 +04:00
extern int tryit __P((unsigned char *, int, int));
1995-03-26 01:35:28 +03:00
extern int zmagic __P((unsigned char *, int));
extern void ckfprintf __P((FILE *, const char *, ...));
1997-01-28 03:49:36 +03:00
extern uint32 signextend __P((struct magic *, unsigned int32));
extern int internatmagic __P((unsigned char *, int));
1999-11-01 20:39:26 +03:00
extern void tryelf __P((int, unsigned char *, int));
extern char *progname; /* the program name */
1998-09-20 19:27:15 +04:00
extern const char *magicfile; /* name of the magic file */
extern int lineno; /* current line number in magic file */
extern struct magic *magic; /* array of magic entries */
extern int nmagic; /* number of valid magic[]s */
extern int debug; /* enable debugging? */
extern int zflag; /* process compressed files? */
extern int lflag; /* follow symbolic links? */
1999-11-01 20:39:26 +03:00
extern int sflag; /* read/analyze block special files? */
2000-05-15 02:53:37 +04:00
extern int iflag; /* Output types as mime-types */
extern int optind; /* From getopt(3) */
extern char *optarg;
1999-11-01 20:39:26 +03:00
#ifndef HAVE_STRERROR
extern int sys_nerr;
extern char *sys_errlist[];
#define strerror(e) \
(((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
#endif
1999-11-01 20:39:26 +03:00
#ifndef HAVE_STRTOUL
#define strtoul(a, b, c) strtol(a, b, c)
#endif
1997-01-28 03:49:36 +03:00
1998-09-20 19:27:15 +04:00
#ifdef __STDC__
#define FILE_RCSID(id) \
static const char *rcsid(const char *p) { \
return rcsid(p = id); \
}
#else
#define FILE_RCSID(id) static char *rcsid[] = id;
#endif
1997-01-28 03:49:36 +03:00
#endif /* __file_h__ */