file/src/file.h File Reference

#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <regex.h>
#include <sys/types.h>
#include <sys/stat.h>

Include dependency graph for file.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  magic
union  magic::VALUETYPE
struct  mlist
struct  magic_set
struct  magic_set::cont
struct  magic_set::cont::level_info
struct  magic_set::out

Defines

#define ENABLE_CONDITIONALS
#define MAGIC   "/etc/magic"
#define PATHSEP   ':'
#define private   static
#define public
#define __GNUC_PREREQ__(x, y)   0
#define f__unused
#define MIN(a, b)   (((a) < (b)) ? (a) : (b))
#define HOWMANY   (256 * 1024)
#define MAXMAGIS   8192
#define MAXDESC   64
#define MAXstring   32
#define MAGICNO   0xF11E041C
#define VERSIONNO   4
#define FILE_MAGICSIZE   (32 * 4)
#define FILE_LOAD   0
#define FILE_CHECK   1
#define FILE_COMPILE   2
#define INDIR   1
#define OFFADD   2
#define INDIROFFADD   4
#define UNSIGNED   8
#define FILE_INVALID   0
#define FILE_BYTE   1
#define FILE_SHORT   2
#define FILE_DEFAULT   3
#define FILE_LONG   4
#define FILE_STRING   5
#define FILE_DATE   6
#define FILE_BESHORT   7
#define FILE_BELONG   8
#define FILE_BEDATE   9
#define FILE_LESHORT   10
#define FILE_LELONG   11
#define FILE_LEDATE   12
#define FILE_PSTRING   13
#define FILE_LDATE   14
#define FILE_BELDATE   15
#define FILE_LELDATE   16
#define FILE_REGEX   17
#define FILE_BESTRING16   18
#define FILE_LESTRING16   19
#define FILE_SEARCH   20
#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_NAMES_SIZE   33
#define IS_STRING(t)
#define FILE_FMT_NONE   0
#define FILE_FMT_NUM   1
#define FILE_FMT_STR   2
#define FILE_FMT_QUAD   3
#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_OPS_MASK   0x07
#define FILE_UNUSED_1   0x08
#define FILE_UNUSED_2   0x10
#define FILE_UNUSED_3   0x20
#define FILE_OPINVERSE   0x40
#define FILE_OPINDIRECT   0x80
#define COND_NONE   0
#define COND_IF   1
#define COND_ELIF   2
#define COND_ELSE   3
#define num_mask   _u._mask
#define str_count   _u._s._count
#define str_flags   _u._s._flags
#define BIT(A)   (1 << (A))
#define STRING_COMPACT_BLANK   BIT(0)
#define STRING_COMPACT_OPTIONAL_BLANK   BIT(1)
#define STRING_IGNORE_LOWERCASE   BIT(2)
#define STRING_IGNORE_UPPERCASE   BIT(3)
#define REGEX_OFFSET_START   BIT(4)
#define CHAR_COMPACT_BLANK   'B'
#define CHAR_COMPACT_OPTIONAL_BLANK   'b'
#define CHAR_IGNORE_LOWERCASE   'c'
#define CHAR_IGNORE_UPPERCASE   'C'
#define CHAR_REGEX_OFFSET_START   's'
#define STRING_IGNORE_CASE   (STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE)
#define strerror(e)   (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
#define strtoul(a, b, c)   strtol(a, b, c)
#define O_BINARY   0
#define FILE_RCSID(id)

Functions

const char * file_fmttime (uint32_t, int)
int file_buffer (struct magic_set *ms, int fd, const char *inname, const void *buf, size_t nb)
int file_fsmagic (struct magic_set *ms, const char *, struct stat *sb)
int file_pipe2file (struct magic_set *ms, int, const void *, size_t)
int file_printf (struct magic_set *ms, const char *,...)
int file_reset (struct magic_set *ms)
int file_tryelf (struct magic_set *ms, int, const unsigned char *, size_t)
int file_zmagic (struct magic_set *ms, int fd, const char *name, const unsigned char *buf, size_t nbytes)
int file_ascmagic (struct magic_set *ms, const unsigned char *, size_t)
int file_is_tar (struct magic_set *ms, const unsigned char *, size_t)
int file_softmagic (struct magic_set *ms, const unsigned char *, size_t)
mlistfile_apprentice (struct magic_set *ms, const char *, int)
uint64_t file_signextend (struct magic_set *ms, struct magic *, uint64_t)
void file_delmagic (struct magic *p, int type, size_t entries)
void file_badread (struct magic_set *ms)
void file_badseek (struct magic_set *ms)
void file_oomem (struct magic_set *ms, size_t)
void file_error (struct magic_set *ms, int error, const char *f,...)
void file_magerror (struct magic_set *ms, const char *,...)
void file_magwarn (struct magic_set *ms, const char *,...)
void file_mdump (struct magic *)
void file_showstr (FILE *fp, const char *, size_t)
size_t file_mbswidth (const char *)
const char * file_getbuffer (struct magic_set *ms)
ssize_t sread (int fd, void *buf, size_t n, int canbepipe)
int file_check_mem (struct magic_set *ms, unsigned int)
int snprintf (char *, size_t, const char *,...)

Variables

const char * file_names []
const size_t file_nnames
int sys_nerr
char * sys_errlist []


Define Documentation

#define __GNUC_PREREQ__ ( x,
 )     0

Definition at line 78 of file file.h.

#define BIT (  )     (1 << (A))

Definition at line 240 of file file.h.

#define CHAR_COMPACT_BLANK   'B'

Definition at line 246 of file file.h.

Referenced by file_mdump(), parse(), and string_modifier_check().

#define CHAR_COMPACT_OPTIONAL_BLANK   'b'

Definition at line 247 of file file.h.

Referenced by file_mdump(), parse(), and string_modifier_check().

#define CHAR_IGNORE_LOWERCASE   'c'

Definition at line 248 of file file.h.

Referenced by file_mdump(), and parse().

#define CHAR_IGNORE_UPPERCASE   'C'

Definition at line 249 of file file.h.

Referenced by file_mdump(), and parse().

#define CHAR_REGEX_OFFSET_START   's'

Definition at line 250 of file file.h.

Referenced by file_mdump(), parse(), and string_modifier_check().

#define COND_ELIF   2

Definition at line 203 of file file.h.

Referenced by check_cond(), get_cond(), and match().

#define COND_ELSE   3

Definition at line 204 of file file.h.

Referenced by check_cond(), get_cond(), and match().

#define COND_IF   1

Definition at line 202 of file file.h.

Referenced by check_cond(), and get_cond().

#define COND_NONE   0

Definition at line 201 of file file.h.

Referenced by check_cond(), file_check_mem(), and get_cond().

#define ENABLE_CONDITIONALS

Definition at line 54 of file file.h.

#define f__unused

Definition at line 86 of file file.h.

#define FILE_BEDATE   9

Definition at line 133 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), and mprint().

#define FILE_BELDATE   15

Definition at line 139 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), and mprint().

#define FILE_BELONG   8

Definition at line 132 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), mprint(), and parse().

#define FILE_BEQDATE   29

Definition at line 153 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), and mprint().

#define FILE_BEQLDATE   32

Definition at line 156 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), and mprint().

#define FILE_BEQUAD   26

Definition at line 150 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), and mprint().

#define FILE_BESHORT   7

Definition at line 131 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), mprint(), and parse().

#define FILE_BESTRING16   18

Definition at line 142 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), getvalue(), magiccheck(), mconvert(), mcopy(), mprint(), and string_modifier_check().

#define FILE_BYTE   1

Definition at line 125 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), mprint(), and parse().

#define FILE_CHECK   1

Definition at line 106 of file file.h.

Referenced by apprentice_file(), magic_check(), main(), and parse().

#define FILE_COMPILE   2

Definition at line 107 of file file.h.

Referenced by apprentice_1(), getstr(), magic_compile(), and main().

#define FILE_DATE   6

Definition at line 130 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), and mprint().

#define FILE_DEFAULT   3

Definition at line 127 of file file.h.

Referenced by apprentice_file(), apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), match(), mconvert(), mget(), and mprint().

#define FILE_FMT_NONE   0

Definition at line 168 of file file.h.

Referenced by check_format().

#define FILE_FMT_NUM   1

Definition at line 169 of file file.h.

Referenced by check_format_type().

#define FILE_FMT_QUAD   3

Definition at line 171 of file file.h.

Referenced by check_format_type().

#define FILE_FMT_STR   2

Definition at line 170 of file file.h.

Referenced by check_format_type().

#define FILE_INVALID   0

Definition at line 124 of file file.h.

Referenced by parse().

#define FILE_LDATE   14

Definition at line 138 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), and mprint().

#define FILE_LEDATE   12

Definition at line 136 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), and mprint().

#define FILE_LELDATE   16

Definition at line 140 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), and mprint().

#define FILE_LELONG   11

Definition at line 135 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), mprint(), and parse().

#define FILE_LEQDATE   28

Definition at line 152 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), and mprint().

#define FILE_LEQLDATE   31

Definition at line 155 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), and mprint().

#define FILE_LEQUAD   25

Definition at line 149 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), and mprint().

#define FILE_LESHORT   10

Definition at line 134 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), mprint(), and parse().

#define FILE_LESTRING16   19

Definition at line 143 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), getvalue(), magiccheck(), mconvert(), mcopy(), mprint(), and string_modifier_check().

#define FILE_LOAD   0

Definition at line 105 of file file.h.

Referenced by magic_load().

#define FILE_LONG   4

Definition at line 128 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), mprint(), and parse().

#define FILE_MAGICSIZE   (32 * 4)

Definition at line 103 of file file.h.

Referenced by apprentice_1().

#define FILE_MEDATE   21

Definition at line 145 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), and mprint().

#define FILE_MELDATE   22

Definition at line 146 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), and mprint().

#define FILE_MELONG   23

Definition at line 147 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), mprint(), and parse().

#define FILE_NAMES_SIZE   33

Definition at line 157 of file file.h.

Referenced by init_file_tables().

#define FILE_OPADD   3

Definition at line 188 of file file.h.

Referenced by get_op(), and mget().

#define FILE_OPAND   0

Definition at line 185 of file file.h.

Referenced by get_op(), and mget().

#define FILE_OPDIVIDE   6

Definition at line 191 of file file.h.

Referenced by get_op(), mget(), and parse().

#define FILE_OPINDIRECT   0x80

Definition at line 198 of file file.h.

Referenced by mget(), and parse().

#define FILE_OPINVERSE   0x40

Definition at line 197 of file file.h.

Referenced by file_mdump(), mget(), and parse().

#define FILE_OPMINUS   4

Definition at line 189 of file file.h.

Referenced by get_op(), and mget().

#define FILE_OPMODULO   7

Definition at line 192 of file file.h.

Referenced by get_op(), and mget().

#define FILE_OPMULTIPLY   5

Definition at line 190 of file file.h.

Referenced by get_op(), and mget().

#define FILE_OPOR   1

Definition at line 186 of file file.h.

Referenced by get_op(), and mget().

#define FILE_OPS   "&|^+-*/%"

Definition at line 184 of file file.h.

Referenced by file_mdump().

#define FILE_OPS_MASK   0x07

Definition at line 193 of file file.h.

Referenced by file_mdump(), and mget().

#define FILE_OPXOR   2

Definition at line 187 of file file.h.

Referenced by get_op(), and mget().

#define FILE_PSTRING   13

Definition at line 137 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), getvalue(), magiccheck(), mconvert(), mcopy(), mget(), mprint(), and string_modifier_check().

#define FILE_QDATE   27

Definition at line 151 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), and mprint().

#define FILE_QLDATE   30

Definition at line 154 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), and mprint().

#define FILE_QUAD   24

Definition at line 148 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), and mprint().

#define FILE_RCSID ( id   ) 

Value:

static const char *rcsid(const char *p) /*@*/ { \
        return rcsid(p = id); \
}

Definition at line 409 of file file.h.

#define FILE_REGEX   17

Definition at line 141 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), getvalue(), magiccheck(), mconvert(), mcopy(), mget(), mprint(), and string_modifier_check().

#define FILE_SEARCH   20

Definition at line 144 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), getvalue(), magiccheck(), mconvert(), mcopy(), mget(), mprint(), and string_modifier_check().

#define FILE_SHORT   2

Definition at line 126 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), magiccheck(), mconvert(), mget(), and mprint().

#define FILE_STRING   5

Definition at line 129 of file file.h.

Referenced by apprentice_magic_strength(), file_mdump(), file_signextend(), getvalue(), magiccheck(), mconvert(), mcopy(), mget(), mprint(), and string_modifier_check().

#define FILE_UNUSED_1   0x08

Definition at line 194 of file file.h.

#define FILE_UNUSED_2   0x10

Definition at line 195 of file file.h.

#define FILE_UNUSED_3   0x20

Definition at line 196 of file file.h.

#define HOWMANY   (256 * 1024)

Definition at line 95 of file file.h.

Referenced by magic_file(), and uncompressbuf().

#define INDIR   1

Definition at line 114 of file file.h.

Referenced by file_mdump(), mget(), and parse().

#define INDIROFFADD   4

Definition at line 116 of file file.h.

Referenced by mget(), and parse().

#define IS_STRING (  ) 

Value:

((t) == FILE_STRING || \
         (t) == FILE_PSTRING || \
         (t) == FILE_BESTRING16 || \
         (t) == FILE_LESTRING16 || \
         (t) == FILE_REGEX || \
         (t) == FILE_SEARCH || \
         (t) == FILE_DEFAULT)

Definition at line 159 of file file.h.

Referenced by bs1(), file_mdump(), and parse().

#define MAGIC   "/etc/magic"

Definition at line 57 of file file.h.

Referenced by file_apprentice().

#define MAGICNO   0xF11E041C

Definition at line 101 of file file.h.

Referenced by apprentice_map().

#define MAXDESC   64

Definition at line 98 of file file.h.

#define MAXMAGIS   8192

Definition at line 97 of file file.h.

Referenced by apprentice_file().

#define MAXstring   32

Definition at line 99 of file file.h.

#define MIN ( a,
 )     (((a) < (b)) ? (a) : (b))

Definition at line 91 of file file.h.

Referenced by magiccheck().

#define num_mask   _u._mask

Definition at line 221 of file file.h.

#define O_BINARY   0

Definition at line 406 of file file.h.

Referenced by apprentice_compile(), apprentice_map(), and magic_file().

#define OFFADD   2

Definition at line 115 of file file.h.

Referenced by match(), and parse().

#define PATHSEP   ':'

Definition at line 63 of file file.h.

Referenced by file_apprentice().

#define private   static

Definition at line 66 of file file.h.

#define public

Definition at line 70 of file file.h.

#define REGEX_OFFSET_START   BIT(4)

Definition at line 245 of file file.h.

Referenced by file_mdump(), mprint(), parse(), and string_modifier_check().

#define str_count   _u._s._count

Definition at line 222 of file file.h.

#define str_flags   _u._s._flags

Definition at line 223 of file file.h.

#define strerror (  )     (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")

Definition at line 388 of file file.h.

Referenced by checkOwners(), checkPassPhrase(), cpioStrerror(), dbiOpen(), doScript(), fdFgets(), fdWritable(), file_error_core(), file_fsmagic(), fsmStage(), Fstrerror(), getFdErrstr(), getFilesystemList(), getOutputFrom(), load(), lzdClose(), lzdWrite(), main(), makeGPGSignature(), makePGPSignature(), packageBinaries(), prepFetch(), processSourceFiles(), rpmdbRebuild(), rpmdsGetconf(), rpmfcClassify(), rpmGetFilesystemUsage(), rpmProblemString(), rpmQueryVerify(), runScript(), ufdRead(), ufdWrite(), uncompressbuf(), unwrap(), and urlStrerror().

#define STRING_COMPACT_BLANK   BIT(0)

Definition at line 241 of file file.h.

Referenced by file_mdump(), file_strncmp(), parse(), and string_modifier_check().

#define STRING_COMPACT_OPTIONAL_BLANK   BIT(1)

Definition at line 242 of file file.h.

Referenced by file_mdump(), file_strncmp(), parse(), and string_modifier_check().

#define STRING_IGNORE_CASE   (STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE)

Definition at line 251 of file file.h.

Referenced by magiccheck().

#define STRING_IGNORE_LOWERCASE   BIT(2)

Definition at line 243 of file file.h.

Referenced by file_mdump(), file_strncmp(), and parse().

#define STRING_IGNORE_UPPERCASE   BIT(3)

Definition at line 244 of file file.h.

Referenced by file_mdump(), file_strncmp(), and parse().

#define strtoul ( a,
b,
 )     strtol(a, b, c)

Definition at line 393 of file file.h.

Referenced by addCanon(), parse(), parseFormat(), parseNum(), rpmEVRparse(), rpmQueryVerify(), and strntoul().

#define UNSIGNED   8

Definition at line 117 of file file.h.

Referenced by file_mdump(), file_signextend(), magiccheck(), and parse().

#define VERSIONNO   4

Definition at line 102 of file file.h.

Referenced by apprentice_map().


Function Documentation

struct mlist* file_apprentice ( struct magic_set ms,
const char *  ,
int   
) [read]

Definition at line 359 of file apprentice.c.

References apprentice_1(), file_error(), file_oomem(), magic_set::flags, getenv(), init_file_tables(), MAGIC, MAGIC_MIME, mime, and PATHSEP.

Referenced by magic_check(), magic_compile(), and magic_load().

int file_ascmagic ( struct magic_set ms,
const unsigned char *  ,
size_t   
)

Definition at line 83 of file ascmagic.c.

References ascmatch(), magic_set::flags, from_ebcdic(), ISSPC, looks_ascii(), looks_extended(), looks_latin1(), looks_unicode(), looks_utf8(), MAGIC_NO_CHECK_FORTRAN, MAGIC_NO_CHECK_TOKENS, MAGIC_NO_CHECK_TROFF, names::name, NNAMES, names::type, and types.

Referenced by file_buffer().

void file_badread ( struct magic_set ms  ) 

Definition at line 150 of file funcs.c.

References errno, and file_error().

Referenced by apprentice_map().