php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
apprentice.c File Reference
#include "file.h"
#include "magic.h"
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <fcntl.h>
#include <limits.h>
#include "../data_file.c"

Go to the source code of this file.

Data Structures

struct  magic_entry
 
struct  magic_entry_set
 
struct  magic_map
 
struct  type_tbl_s
 

Macros

#define EATAB
 
#define LOWCASE(l)
 
#define MAP_FAILED   (void *) -1
 
#define MAP_FILE   0
 
#define ALLOC_CHUNK   CAST(size_t, 10)
 
#define ALLOC_INCR   CAST(size_t, 200)
 
#define MAP_TYPE_USER   0
 
#define MAP_TYPE_MALLOC   1
 
#define MAP_TYPE_MMAP   2
 
#define DECLARE_FIELD(name)
 
#define XX(s)
 
#define XX_NULL   "", 0
 
#define MULT   10U
 
#define SET_LENGTH(a)
 
#define CHECKLEN()
 

Functions

file_private int getvalue (struct magic_set *ms, struct magic *, const char **, int)
 
file_private int hextoint (int)
 
file_private const char * getstr (struct magic_set *, struct magic *, const char *, int)
 
file_private int parse (struct magic_set *, struct magic_entry *, const char *, size_t, int)
 
file_private void eatsize (const char **)
 
file_private int apprentice_1 (struct magic_set *, const char *, int)
 
file_private ssize_t apprentice_magic_strength_1 (const struct magic *)
 
file_private int apprentice_sort (const void *, const void *)
 
file_private void apprentice_list (struct mlist *, int)
 
file_private struct magic_mapapprentice_load (struct magic_set *, const char *, int)
 
file_private struct mlistmlist_alloc (void)
 
file_private void mlist_free_all (struct magic_set *)
 
file_private void mlist_free (struct mlist *)
 
file_private void byteswap (struct magic *, uint32_t)
 
file_private void bs1 (struct magic *)
 
file_private uint16_t swap2 (uint16_t)
 
file_private uint32_t swap4 (uint32_t)
 
file_private uint64_t swap8 (uint64_t)
 
file_private char * mkdbname (struct magic_set *, const char *, int)
 
file_private struct magic_mapapprentice_map (struct magic_set *, const char *)
 
file_private void apprentice_unmap (struct magic_map *)
 
file_private int apprentice_compile (struct magic_set *, struct magic_map *, const char *)
 
file_private int check_format_type (const char *, int, const char **)
 
file_private int check_format (struct magic_set *, struct magic *)
 
file_private int get_op (char)
 
file_private int parse_mime (struct magic_set *, struct magic_entry *, const char *, size_t)
 
file_private int parse_strength (struct magic_set *, struct magic_entry *, const char *, size_t)
 
file_private int parse_apple (struct magic_set *, struct magic_entry *, const char *, size_t)
 
file_private int parse_ext (struct magic_set *, struct magic_entry *, const char *, size_t)
 
file_private int get_type (const struct type_tbl_s *tbl, const char *l, const char **t)
 
file_private off_t maxoff_t (void)
 
file_private int get_standard_integer_type (const char *l, const char **t)
 
file_private void init_file_tables (void)
 
file_private int add_mlist (struct mlist *mlp, struct magic_map *map, size_t idx)
 
file_protected void file_ms_free (struct magic_set *ms)
 
file_protected struct magic_setfile_ms_alloc (int flags)
 
file_private void mlist_free_one (struct mlist *ml)
 
file_protected int file_apprentice (struct magic_set *ms, const char *fn, int action)
 
file_private size_t nonmagic (const char *str)
 
file_private size_t typesize (int type)
 
file_protected size_t file_magic_strength (const struct magic *m, size_t nmagic __attribute__((__unused__)))
 
file_private void set_test_type (struct magic *mstart, struct magic *m)
 
file_private int addentry (struct magic_set *ms, struct magic_entry *me, struct magic_entry_set *mset)
 
file_private void load_1 (struct magic_set *ms, int action, const char *fn, int *errs, struct magic_entry_set *mset)
 
file_private int cmpstrp (const void *p1, const void *p2)
 
file_private uint32_t set_text_binary (struct magic_set *ms, struct magic_entry *me, uint32_t nme, uint32_t starttest)
 
file_private void set_last_default (struct magic_set *ms, struct magic_entry *me, uint32_t nme)
 
file_private int coalesce_entries (struct magic_set *ms, struct magic_entry *me, uint32_t nme, struct magic **ma, uint32_t *nma)
 
file_private void magic_entry_free (struct magic_entry *me, uint32_t nme)
 
file_protected uint64_t file_signextend (struct magic_set *ms, struct magic *m, uint64_t v)
 
file_private int string_modifier_check (struct magic_set *ms, struct magic *m)
 
file_private int get_cond (const char *l, const char **t)
 
file_private int check_cond (struct magic_set *ms, int cond, uint32_t cont_level)
 
file_private int parse_indirect_modifier (struct magic_set *ms, struct magic *m, const char **lp)
 
file_private void parse_op_modifier (struct magic_set *ms, struct magic *m, const char **lp, int op)
 
file_private int parse_string_modifier (struct magic_set *ms, struct magic *m, const char **lp)
 
file_private int parse_strength (struct magic_set *ms, struct magic_entry *me, const char *line, size_t len __attribute__((__unused__)))
 
file_private int goodchar (unsigned char x, const char *extra)
 
file_private int parse_extra (struct magic_set *ms, struct magic_entry *me, const char *line, size_t llen, zend_off_t off, size_t len, const char *name, const char *extra, int nt)
 
file_protected void file_showstr (FILE *fp, const char *s, size_t len)
 
file_protected uintmax_t file_varint2uintmax_t (const unsigned char *us, int t, size_t *l)
 
file_protected size_t file_pstring_length_size (struct magic_set *ms, const struct magic *m)
 
file_protected size_t file_pstring_get_length (struct magic_set *ms, const struct magic *m, const char *ss)
 
file_protected int file_magicfind (struct magic_set *ms, const char *name, struct mlist *v)
 

Variables

int file_formats [FILE_NAMES_SIZE]
 
const size_t file_nformats = FILE_NAMES_SIZE
 
const char * file_names [FILE_NAMES_SIZE]
 
const size_t file_nnames = FILE_NAMES_SIZE
 
file_private size_t magicsize = sizeof(struct magic)
 
file_private const char usg_hdr [] = "cont\toffset\ttype\topcode\tmask\tvalue\tdesc"
 
struct { 
 
   const char *   name 
 
   size_t   len 
 
   int(*   fun )(struct magic_set *, struct
      magic_entry *, const char *,
       size_t) 
 
bang [] 
 
file_private const char ext [] = ".mgc"
 

Macro Definition Documentation

◆ ALLOC_CHUNK

#define ALLOC_CHUNK   CAST(size_t, 10)

Definition at line 85 of file apprentice.c.

◆ ALLOC_INCR

#define ALLOC_INCR   CAST(size_t, 200)

Definition at line 86 of file apprentice.c.

◆ CHECKLEN

#define CHECKLEN ( )
Value:
do { \
for (len = cnt = 0; isdigit(CAST(unsigned char, *ptr)); ptr++, cnt++) \
len = len * 10 + (*ptr - '0'); \
if (cnt > 5 || len > 1024) \
goto toolong; \
} while (/*CONSTCOND*/0)
size_t len
Definition apprentice.c:174
void * ptr
Definition ffi.c:3814
#define CAST(T, b)
Definition file.h:425

◆ DECLARE_FIELD

#define DECLARE_FIELD ( name)
Value:
{ # name, sizeof(# name) - 1, parse_ ## name }
zend_string * name

◆ EATAB

#define EATAB
Value:
{while (isascii(CAST(unsigned char, *l)) && \
isspace(CAST(unsigned char, *l))) ++l;}

Definition at line 63 of file apprentice.c.

◆ LOWCASE

#define LOWCASE ( l)
Value:
(isupper(CAST(unsigned char, l)) ? \
tolower(CAST(unsigned char, l)) : (l))

Definition at line 65 of file apprentice.c.

◆ MAP_FAILED

#define MAP_FAILED   (void *) -1

Definition at line 78 of file apprentice.c.

◆ MAP_FILE

#define MAP_FILE   0

Definition at line 82 of file apprentice.c.

◆ MAP_TYPE_MALLOC

#define MAP_TYPE_MALLOC   1

Definition at line 89 of file apprentice.c.

◆ MAP_TYPE_MMAP

#define MAP_TYPE_MMAP   2

Definition at line 90 of file apprentice.c.

◆ MAP_TYPE_USER

#define MAP_TYPE_USER   0

Definition at line 88 of file apprentice.c.

◆ MULT

#define MULT   10U

◆ SET_LENGTH

#define SET_LENGTH ( a)
Value:
m->str_flags = (m->str_flags & ~PSTRING_LEN) | (a)
#define PSTRING_LEN
Definition file.h:385
$obj a
Definition test.php:84

◆ XX

#define XX ( s)
Value:
s, (sizeof(s) - 1)
char s[4]
Definition cdf.c:77

◆ XX_NULL

#define XX_NULL   "", 0

Function Documentation

◆ add_mlist()

file_private int add_mlist ( struct mlist * mlp,
struct magic_map * map,
size_t idx )

Definition at line 444 of file apprentice.c.

◆ addentry()

file_private int addentry ( struct magic_set * ms,
struct magic_entry * me,
struct magic_entry_set * mset )

Definition at line 1228 of file apprentice.c.

◆ apprentice_1()

file_private int apprentice_1 ( struct magic_set * ms,
const char * fn,
int action )

Definition at line 467 of file apprentice.c.

◆ apprentice_compile()

file_private int apprentice_compile ( struct magic_set * ms,
struct magic_map * map,
const char * fn )

Definition at line 3352 of file apprentice.c.

◆ apprentice_list()

file_private void apprentice_list ( struct mlist * mlist,
int mode )

Definition at line 1095 of file apprentice.c.

◆ apprentice_load()

file_private struct magic_map * apprentice_load ( struct magic_set * ms,
const char * fn,
int action )

Definition at line 1454 of file apprentice.c.

◆ apprentice_magic_strength_1()

file_private ssize_t apprentice_magic_strength_1 ( const struct magic * m)

Definition at line 879 of file apprentice.c.

◆ apprentice_map()

file_private struct magic_map * apprentice_map ( struct magic_set * ms,
const char * fn )

Definition at line 3206 of file apprentice.c.

◆ apprentice_sort()

file_private int apprentice_sort ( const void * a,
const void * b )

Definition at line 1077 of file apprentice.c.

◆ apprentice_unmap()

file_private void apprentice_unmap ( struct magic_map * map)

Definition at line 596 of file apprentice.c.

◆ bs1()

file_private void bs1 ( struct magic * m)

Definition at line 3562 of file apprentice.c.

◆ byteswap()

file_private void byteswap ( struct magic * magic,
uint32_t nmagic )

Definition at line 3458 of file apprentice.c.

◆ check_cond()

file_private int check_cond ( struct magic_set * ms,
int cond,
uint32_t cont_level )

Definition at line 1775 of file apprentice.c.

◆ check_format()

file_private int check_format ( struct magic_set * ms,
struct magic * m )

Definition at line 2730 of file apprentice.c.

◆ check_format_type()

file_private int check_format_type ( const char * ptr,
int type,
const char ** estr )

Definition at line 2536 of file apprentice.c.

◆ cmpstrp()

file_private int cmpstrp ( const void * p1,
const void * p2 )

Definition at line 1350 of file apprentice.c.

◆ coalesce_entries()

file_private int coalesce_entries ( struct magic_set * ms,
struct magic_entry * me,
uint32_t nme,
struct magic ** ma,
uint32_t * nma )

Definition at line 1411 of file apprentice.c.

◆ eatsize()

file_private void eatsize ( const char ** p)

Definition at line 3179 of file apprentice.c.

◆ file_apprentice()

file_protected int file_apprentice ( struct magic_set * ms,
const char * fn,
int action )

Definition at line 663 of file apprentice.c.

◆ file_magic_strength()

file_protected size_t file_magic_strength ( const struct magic * m,
size_t nmagic __attribute__(__unused__) )

Definition at line 1016 of file apprentice.c.

◆ file_magicfind()

file_protected int file_magicfind ( struct magic_set * ms,
const char * name,
struct mlist * v )

Definition at line 3651 of file apprentice.c.

◆ file_ms_alloc()

file_protected struct magic_set * file_ms_alloc ( int flags)

Definition at line 549 of file apprentice.c.

◆ file_ms_free()

file_protected void file_ms_free ( struct magic_set * ms)

Definition at line 526 of file apprentice.c.

◆ file_pstring_get_length()

file_protected size_t file_pstring_get_length ( struct magic_set * ms,
const struct magic * m,
const char * ss )

Definition at line 3598 of file apprentice.c.

◆ file_pstring_length_size()

file_protected size_t file_pstring_length_size ( struct magic_set * ms,
const struct magic * m )

Definition at line 3579 of file apprentice.c.

◆ file_showstr()

file_protected void file_showstr ( FILE * fp,
const char * s,
size_t len )

Definition at line 3119 of file apprentice.c.

◆ file_signextend()

file_protected uint64_t file_signextend ( struct magic_set * ms,
struct magic * m,
uint64_t v )

Definition at line 1578 of file apprentice.c.

◆ file_varint2uintmax_t()

file_protected uintmax_t file_varint2uintmax_t ( const unsigned char * us,
int t,
size_t * l )

Definition at line 3529 of file apprentice.c.

◆ get_cond()

file_private int get_cond ( const char * l,
const char ** t )

Definition at line 1749 of file apprentice.c.

◆ get_op()

file_private int get_op ( char c)

Definition at line 1723 of file apprentice.c.

◆ get_standard_integer_type()

file_private int get_standard_integer_type ( const char * l,
const char ** t )

Definition at line 341 of file apprentice.c.

◆ get_type()

file_private int get_type ( const struct type_tbl_s * tbl,
const char * l,
const char ** t )

Definition at line 317 of file apprentice.c.

◆ getstr()

file_private const char * getstr ( struct magic_set * ms,
struct magic * m,
const char * s,
int warn )

Definition at line 2923 of file apprentice.c.

◆ getvalue()

file_private int getvalue ( struct magic_set * ms,
struct magic * m,
const char ** p,
int action )

Definition at line 2786 of file apprentice.c.

◆ goodchar()

file_private int goodchar ( unsigned char x,
const char * extra )

Definition at line 2441 of file apprentice.c.

◆ hextoint()

file_private int hextoint ( int c)

Definition at line 3101 of file apprentice.c.

◆ init_file_tables()

file_private void init_file_tables ( void )

Definition at line 426 of file apprentice.c.

◆ load_1()

file_private void load_1 ( struct magic_set * ms,
int action,
const char * fn,
int * errs,
struct magic_entry_set * mset )

Definition at line 1257 of file apprentice.c.

◆ magic_entry_free()

file_private void magic_entry_free ( struct magic_entry * me,
uint32_t nme )

Definition at line 1443 of file apprentice.c.

◆ maxoff_t()

file_private off_t maxoff_t ( void )

Definition at line 332 of file apprentice.c.

◆ mkdbname()

file_private char * mkdbname ( struct magic_set * ms,
const char * fn,
int strip )

Definition at line 3410 of file apprentice.c.

◆ mlist_alloc()

file_private struct mlist * mlist_alloc ( void )

Definition at line 616 of file apprentice.c.

◆ mlist_free()

file_private void mlist_free ( struct mlist * mlist)

Definition at line 646 of file apprentice.c.

◆ mlist_free_all()

file_private void mlist_free_all ( struct magic_set * ms)

Definition at line 627 of file apprentice.c.

◆ mlist_free_one()

file_private void mlist_free_one ( struct mlist * ml)

Definition at line 638 of file apprentice.c.

◆ nonmagic()

file_private size_t nonmagic ( const char * str)

Definition at line 769 of file apprentice.c.

◆ parse()

file_private int parse ( struct magic_set * ms,
struct magic_entry * me,
const char * line,
size_t lineno,
int action )

Definition at line 1964 of file apprentice.c.

◆ parse_apple()

file_private int parse_apple ( struct magic_set * ms,
struct magic_entry * me,
const char * line,
size_t len )

Definition at line 2500 of file apprentice.c.

◆ parse_ext()

file_private int parse_ext ( struct magic_set * ms,
struct magic_entry * me,
const char * line,
size_t len )

Definition at line 2512 of file apprentice.c.

◆ parse_extra()

file_private int parse_extra ( struct magic_set * ms,
struct magic_entry * me,
const char * line,
size_t llen,
zend_off_t off,
size_t len,
const char * name,
const char * extra,
int nt )

Definition at line 2447 of file apprentice.c.

◆ parse_indirect_modifier()

file_private int parse_indirect_modifier ( struct magic_set * ms,
struct magic * m,
const char ** lp )

Definition at line 1819 of file apprentice.c.

◆ parse_mime()

file_private int parse_mime ( struct magic_set * ms,
struct magic_entry * me,
const char * line,
size_t len )

Definition at line 2527 of file apprentice.c.

◆ parse_op_modifier()

file_private void parse_op_modifier ( struct magic_set * ms,
struct magic * m,
const char ** lp,
int op )

Definition at line 1840 of file apprentice.c.

◆ parse_strength() [1/2]

file_private int parse_strength ( struct magic_set * ,
struct magic_entry * ,
const char * ,
size_t  )

◆ parse_strength() [2/2]

file_private int parse_strength ( struct magic_set * ms,
struct magic_entry * me,
const char * line,
size_t len __attribute__(__unused__) )

Definition at line 2381 of file apprentice.c.

◆ parse_string_modifier()

file_private int parse_string_modifier ( struct magic_set * ms,
struct magic * m,
const char ** lp )

Definition at line 1857 of file apprentice.c.

◆ set_last_default()

file_private void set_last_default ( struct magic_set * ms,
struct magic_entry * me,
uint32_t nme )

Definition at line 1390 of file apprentice.c.

◆ set_test_type()

file_private void set_test_type ( struct magic * mstart,
struct magic * m )

Definition at line 1137 of file apprentice.c.

◆ set_text_binary()

file_private uint32_t set_text_binary ( struct magic_set * ms,
struct magic_entry * me,
uint32_t nme,
uint32_t starttest )

Definition at line 1357 of file apprentice.c.

◆ string_modifier_check()

file_private int string_modifier_check ( struct magic_set * ms,
struct magic * m )

Definition at line 1664 of file apprentice.c.

◆ swap2()

file_private uint16_t swap2 ( uint16_t sv)

Definition at line 3470 of file apprentice.c.

◆ swap4()

file_private uint32_t swap4 ( uint32_t sv)

Definition at line 3484 of file apprentice.c.

◆ swap8()

file_private uint64_t swap8 ( uint64_t sv)

Definition at line 3500 of file apprentice.c.

◆ typesize()

file_private size_t typesize ( int type)

Definition at line 809 of file apprentice.c.

Variable Documentation

◆ [struct]

file_private struct { ... } bang[]
Initial value:
= {
#define DECLARE_FIELD(name)
DECLARE_FIELD(apple),
DECLARE_FIELD(strength),
{ NULL, 0, NULL }
}
#define DECLARE_FIELD(name)
file_private const char ext[]
#define NULL
Definition gdcache.h:45

◆ ext

file_private const char ext[] = ".mgc"

Definition at line 3405 of file apprentice.c.

◆ file_formats

int file_formats[FILE_NAMES_SIZE]

Definition at line 112 of file apprentice.c.

◆ file_names

const char* file_names[FILE_NAMES_SIZE]

Definition at line 114 of file apprentice.c.

◆ file_nformats

const size_t file_nformats = FILE_NAMES_SIZE

Definition at line 113 of file apprentice.c.

◆ file_nnames

const size_t file_nnames = FILE_NAMES_SIZE

Definition at line 115 of file apprentice.c.

◆ fun

int(* fun) (struct magic_set *, struct magic_entry *, const char *, size_t) ( struct magic_set * ,
struct magic_entry * ,
const char * ,
size_t  )

Definition at line 175 of file apprentice.c.

◆ len

size_t len

Definition at line 174 of file apprentice.c.

◆ magicsize

file_private size_t magicsize = sizeof(struct magic)

Definition at line 168 of file apprentice.c.

◆ name

const char* name

Definition at line 173 of file apprentice.c.

◆ usg_hdr

file_private const char usg_hdr[] = "cont\toffset\ttype\topcode\tmask\tvalue\tdesc"

Definition at line 170 of file apprentice.c.