Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions | Variables
file.h File Reference
#include "config.h"
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include "php.h"
#include "ext/standard/php_string.h"
#include "ext/pcre/php_pcre.h"
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <stdarg.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  VALUETYPE
struct  magic
struct  mlist
struct  level_info
struct  magic_set
struct  magic_set::cont
struct  magic_set::out
union  magic._u
struct  magic._u._s
struct  magic_set.search

Defines

#define ENABLE_CONDITIONALS
#define MAGIC   "/etc/magic"
#define PATHSEP   ':'
#define private   static
#define protected
#define public
#define __GNUC_PREREQ__(x, y)   0
#define MIN(a, b)   (((a) < (b)) ? (a) : (b))
#define MAX(a, b)   (((a) > (b)) ? (a) : (b))
#define HOWMANY   (256 * 1024) /* how much of the file to look at */
#define MAXMAGIS
#define MAXDESC   64 /* max leng of text description/MIME type */
#define MAXstring   32 /* max leng of "string" types */
#define MAGICNO   0xF11E041C
#define VERSIONNO   7
#define FILE_MAGICSIZE   200
#define FILE_LOAD   0
#define FILE_CHECK   1
#define FILE_COMPILE   2
#define INDIR   0x01 /* if '(...)' appears */
#define OFFADD   0x02 /* if '>&' or '>...(&' appears */
#define INDIROFFADD   0x04 /* if '>&(' appears */
#define UNSIGNED   0x08 /* comparison is unsigned */
#define NOSPACE   0x10 /* suppress space character before output */
#define BINTEST
#define TEXTTEST   0 /* for passing to file_softmagic */
#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_FLOAT   33
#define FILE_BEFLOAT   34
#define FILE_LEFLOAT   35
#define FILE_DOUBLE   36
#define FILE_BEDOUBLE   37
#define FILE_LEDOUBLE   38
#define FILE_BEID3   39
#define FILE_LEID3   40
#define FILE_INDIRECT   41
#define FILE_NAMES_SIZE   42/* size of array to contain all names */
#define IS_LIBMAGIC_STRING(t)
#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_FMT_FLOAT   4 /* "eEfFgG" */
#define FILE_FMT_DOUBLE   5 /* "eEfFgG" */
#define FILE_FACTOR_OP_PLUS   '+'
#define FILE_FACTOR_OP_MINUS   '-'
#define FILE_FACTOR_OP_TIMES   '*'
#define FILE_FACTOR_OP_DIV   '/'
#define FILE_FACTOR_OP_NONE   '\0'
#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 /* mask for above ops */
#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_range   _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 STRING_DEFAULT_RANGE   100
#define CAST(T, b)   (b)
#define EVENT_HAD_ERR   0x01
#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)

Typedefs

typedef unsigned long unichar

Functions

protected const char * file_fmttime (uint32_t, int)
protected int file_buffer (struct magic_set *, php_stream *, const char *, const void *, size_t)
protected int file_fsmagic (struct magic_set *ms, const char *fn, struct stat *sb, php_stream *stream)
protected int file_pipe2file (struct magic_set *, int, const void *, size_t)
protected int file_printf (struct magic_set *, const char *,...)
protected int file_reset (struct magic_set *)
protected int file_tryelf (struct magic_set *, int, const unsigned char *, size_t)
protected int file_trycdf (struct magic_set *, int, const unsigned char *, size_t)
protected int file_ascmagic (struct magic_set *, const unsigned char *, size_t)
protected int file_ascmagic_with_encoding (struct magic_set *, const unsigned char *, size_t, unichar *, size_t, const char *, const char *)
protected int file_encoding (struct magic_set *, const unsigned char *, size_t, unichar **, size_t *, const char **, const char **, const char **)
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, int)
protected struct mlistfile_apprentice (struct magic_set *, const char *, int)
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 *, size_t)
protected void file_error (struct magic_set *, int, const char *,...)
protected void file_magerror (struct magic_set *, const char *,...)
protected void file_magwarn (struct magic_set *, const char *,...)
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, int)
protected int file_check_mem (struct magic_set *, unsigned int)
protected int file_looks_utf8 (const unsigned char *, size_t, unichar *, size_t *)
size_t strlcpy (char *dst, const char *src, size_t siz)
size_t strlcat (char *dst, const char *src, size_t siz)

Variables

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

Class Documentation

union VALUETYPE

Definition at line 116 of file file.h.

Class Members
uint8_t b
double d
float f
uint16_t h
uint8_t hl
uint8_t hq
uint8_t hs
uint32_t l
uint64_t q
char s
unsigned char us
struct magic

Definition at line 130 of file file.h.

Class Members
union magic _u
char apple
uint8_t cond
uint16_t cont_level
char desc
uint8_t factor
uint8_t factor_op
uint8_t flag
int32_t in_offset
uint8_t in_op
uint8_t in_type
uint32_t lineno
uint8_t mask_op
char mimetype
uint32_t offset
uint8_t reln
uint8_t type
uint8_t vallen
struct mlist

Definition at line 290 of file file.h.

Collaboration diagram for mlist:
Class Members
struct magic * magic
int mapped
struct mlist * next
uint32_t nmagic
struct mlist * prev
struct level_info

Definition at line 305 of file file.h.

Class Members
int got_match
int last_cond
int last_match
int32_t off
struct magic_set

Definition at line 313 of file file.h.

Collaboration diagram for magic_set:
Class Members
struct cont c
int error
int event_flags
const char * file
int flags
size_t line
struct mlist * mlist
struct out o
uint32_t offset
struct magic_set search
struct magic_set::cont

Definition at line 315 of file file.h.

Collaboration diagram for magic_set::cont:
Class Members
size_t len
struct level_info * li
struct magic_set::out

Definition at line 319 of file file.h.

Class Members
char * buf
char * pbuf
union magic._u

Definition at line 254 of file file.h.

Class Members
uint64_t _mask
_u _s
struct magic._u._s

Definition at line 256 of file file.h.

Class Members
uint32_t _count
uint32_t _flags
struct magic_set.search

Definition at line 332 of file file.h.

Class Members
size_t offset
size_t rm_len
const char * s
size_t s_len

Define Documentation

#define __GNUC_PREREQ__ (   x,
 
)    0

Definition at line 89 of file file.h.

#define BINTEST
Value:
0x20   /* test is for a binary type (set only
                               for top-level tests) */

Definition at line 139 of file file.h.

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

Definition at line 274 of file file.h.

#define CAST (   T,
 
)    (b)

Definition at line 302 of file file.h.

#define CHAR_COMPACT_BLANK   'B'

Definition at line 280 of file file.h.

#define CHAR_COMPACT_OPTIONAL_BLANK   'b'

Definition at line 281 of file file.h.

#define CHAR_IGNORE_LOWERCASE   'c'

Definition at line 282 of file file.h.

#define CHAR_IGNORE_UPPERCASE   'C'

Definition at line 283 of file file.h.

#define CHAR_REGEX_OFFSET_START   's'

Definition at line 284 of file file.h.

#define COND_ELIF   2

Definition at line 243 of file file.h.

#define COND_ELSE   3

Definition at line 244 of file file.h.

#define COND_IF   1

Definition at line 242 of file file.h.

#define COND_NONE   0

Definition at line 241 of file file.h.

Definition at line 65 of file file.h.

#define EVENT_HAD_ERR   0x01

Definition at line 327 of file file.h.

#define FILE_BEDATE   9

Definition at line 158 of file file.h.

#define FILE_BEDOUBLE   37

Definition at line 186 of file file.h.

#define FILE_BEFLOAT   34

Definition at line 183 of file file.h.

#define FILE_BEID3   39

Definition at line 188 of file file.h.

#define FILE_BELDATE   15

Definition at line 164 of file file.h.

#define FILE_BELONG   8

Definition at line 157 of file file.h.

#define FILE_BEQDATE   29

Definition at line 178 of file file.h.

#define FILE_BEQLDATE   32

Definition at line 181 of file file.h.

#define FILE_BEQUAD   26

Definition at line 175 of file file.h.

#define FILE_BESHORT   7

Definition at line 156 of file file.h.

#define FILE_BESTRING16   18

Definition at line 167 of file file.h.

#define FILE_BYTE   1

Definition at line 150 of file file.h.

#define FILE_CHECK   1

Definition at line 113 of file file.h.

#define FILE_COMPILE   2

Definition at line 114 of file file.h.

#define FILE_DATE   6

Definition at line 155 of file file.h.

#define FILE_DEFAULT   3

Definition at line 152 of file file.h.

#define FILE_DOUBLE   36

Definition at line 185 of file file.h.

#define FILE_FACTOR_OP_DIV   '/'

Definition at line 221 of file file.h.

#define FILE_FACTOR_OP_MINUS   '-'

Definition at line 219 of file file.h.

#define FILE_FACTOR_OP_NONE   '\0'

Definition at line 222 of file file.h.

#define FILE_FACTOR_OP_PLUS   '+'

Definition at line 218 of file file.h.

#define FILE_FACTOR_OP_TIMES   '*'

Definition at line 220 of file file.h.

#define FILE_FLOAT   33

Definition at line 182 of file file.h.

#define FILE_FMT_DOUBLE   5 /* "eEfFgG" */

Definition at line 207 of file file.h.

#define FILE_FMT_FLOAT   4 /* "eEfFgG" */

Definition at line 206 of file file.h.

#define FILE_FMT_NONE   0

Definition at line 202 of file file.h.

#define FILE_FMT_NUM   1 /* "cduxXi" */

Definition at line 203 of file file.h.

#define FILE_FMT_QUAD   3 /* "ll" */

Definition at line 205 of file file.h.

#define FILE_FMT_STR   2 /* "s" */

Definition at line 204 of file file.h.

#define FILE_INDIRECT   41

Definition at line 190 of file file.h.

#define FILE_INVALID   0

Definition at line 149 of file file.h.

#define FILE_LDATE   14

Definition at line 163 of file file.h.

#define FILE_LEDATE   12

Definition at line 161 of file file.h.

#define FILE_LEDOUBLE   38

Definition at line 187 of file file.h.

#define FILE_LEFLOAT   35

Definition at line 184 of file file.h.

#define FILE_LEID3   40

Definition at line 189 of file file.h.

#define FILE_LELDATE   16

Definition at line 165 of file file.h.

#define FILE_LELONG   11

Definition at line 160 of file file.h.

#define FILE_LEQDATE   28

Definition at line 177 of file file.h.

#define FILE_LEQLDATE   31

Definition at line 180 of file file.h.

#define FILE_LEQUAD   25

Definition at line 174 of file file.h.

#define FILE_LESHORT   10

Definition at line 159 of file file.h.

#define FILE_LESTRING16   19

Definition at line 168 of file file.h.

#define FILE_LOAD   0

Definition at line 112 of file file.h.

#define FILE_LONG   4

Definition at line 153 of file file.h.

#define FILE_MAGICSIZE   200

Definition at line 110 of file file.h.

#define FILE_MEDATE   21

Definition at line 170 of file file.h.

#define FILE_MELDATE   22

Definition at line 171 of file file.h.

#define FILE_MELONG   23

Definition at line 172 of file file.h.

#define FILE_NAMES_SIZE   42/* size of array to contain all names */

Definition at line 191 of file file.h.

#define FILE_OPADD   3

Definition at line 228 of file file.h.

#define FILE_OPAND   0

Definition at line 225 of file file.h.

#define FILE_OPDIVIDE   6

Definition at line 231 of file file.h.

#define FILE_OPINDIRECT   0x80

Definition at line 238 of file file.h.

#define FILE_OPINVERSE   0x40

Definition at line 237 of file file.h.

#define FILE_OPMINUS   4

Definition at line 229 of file file.h.

#define FILE_OPMODULO   7

Definition at line 232 of file file.h.

#define FILE_OPMULTIPLY   5

Definition at line 230 of file file.h.

#define FILE_OPOR   1

Definition at line 226 of file file.h.

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

Definition at line 224 of file file.h.

#define FILE_OPS_MASK   0x07 /* mask for above ops */

Definition at line 233 of file file.h.

#define FILE_OPXOR   2

Definition at line 227 of file file.h.

#define FILE_PSTRING   13

Definition at line 162 of file file.h.

#define FILE_QDATE   27

Definition at line 176 of file file.h.

#define FILE_QLDATE   30

Definition at line 179 of file file.h.

#define FILE_QUAD   24

Definition at line 173 of file file.h.

#define FILE_RCSID (   id)
Value:
static const char *rcsid(const char *p) { \
       return rcsid(p = id); \
}

Definition at line 429 of file file.h.

#define FILE_REGEX   17

Definition at line 166 of file file.h.

#define FILE_SEARCH   20

Definition at line 169 of file file.h.

#define FILE_SHORT   2

Definition at line 151 of file file.h.

#define FILE_STRING   5

Definition at line 154 of file file.h.

#define FILE_UNUSED_1   0x08

Definition at line 234 of file file.h.

#define FILE_UNUSED_2   0x10

Definition at line 235 of file file.h.

#define FILE_UNUSED_3   0x20

Definition at line 236 of file file.h.

#define HOWMANY   (256 * 1024) /* how much of the file to look at */

Definition at line 102 of file file.h.

#define INDIR   0x01 /* if '(...)' appears */

Definition at line 134 of file file.h.

#define INDIROFFADD   0x04 /* if '>&(' appears */

Definition at line 136 of file file.h.

#define IS_LIBMAGIC_STRING (   t)
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 193 of file file.h.

#define MAGIC   "/etc/magic"

Definition at line 68 of file file.h.

#define MAGICNO   0xF11E041C

Definition at line 108 of file file.h.

#define MAX (   a,
 
)    (((a) > (b)) ? (a) : (b))

Definition at line 98 of file file.h.

#define MAXDESC   64 /* max leng of text description/MIME type */

Definition at line 105 of file file.h.

#define MAXMAGIS
Value:
8192          /* max entries in any one magic file
                               or directory */

Definition at line 104 of file file.h.

#define MAXstring   32 /* max leng of "string" types */

Definition at line 106 of file file.h.

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

Definition at line 94 of file file.h.

#define NOSPACE   0x10 /* suppress space character before output */

Definition at line 138 of file file.h.

#define num_mask   _u._mask

Definition at line 261 of file file.h.

#define O_BINARY   0

Definition at line 421 of file file.h.

#define OFFADD   0x02 /* if '>&' or '>...(&' appears */

Definition at line 135 of file file.h.

#define PATHSEP   ':'

Definition at line 74 of file file.h.

#define private   static

Definition at line 77 of file file.h.

#define protected

Definition at line 79 of file file.h.

#define public

Definition at line 81 of file file.h.

#define REGEX_OFFSET_START   BIT(4)

Definition at line 279 of file file.h.

#define str_flags   _u._s._flags

Definition at line 263 of file file.h.

#define str_range   _u._s._count

Definition at line 262 of file file.h.

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

Definition at line 400 of file file.h.

#define STRING_COMPACT_BLANK   BIT(0)

Definition at line 275 of file file.h.

Definition at line 276 of file file.h.

#define STRING_DEFAULT_RANGE   100

Definition at line 286 of file file.h.

Definition at line 285 of file file.h.

#define STRING_IGNORE_LOWERCASE   BIT(2)

Definition at line 277 of file file.h.

#define STRING_IGNORE_UPPERCASE   BIT(3)

Definition at line 278 of file file.h.

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

Definition at line 405 of file file.h.

#define TEXTTEST   0 /* for passing to file_softmagic */

Definition at line 140 of file file.h.

#define UNSIGNED   0x08 /* comparison is unsigned */

Definition at line 137 of file file.h.

#define VERSIONNO   7

Definition at line 109 of file file.h.


Typedef Documentation

typedef unsigned long unichar

Definition at line 345 of file file.h.


Function Documentation

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

Definition at line 331 of file apprentice.c.

{
       char *p, *mfn;
       int file_err, errs = -1;
       struct mlist *mlist;

       init_file_tables();

       if (fn == NULL)
              fn = getenv("MAGIC");
       if (fn == NULL) {
              mlist = emalloc(sizeof(*mlist));
              mlist->next = mlist->prev = mlist;
              apprentice_1(ms, fn, action, mlist);
              return mlist;
       }

       mfn = estrdup(fn);
       fn = mfn;

       mlist = emalloc(sizeof(*mlist));
       mlist->next = mlist->prev = mlist;

       while (fn) {
              p = strchr(fn, PATHSEP);
              if (p)
                     *p++ = '\0';
              if (*fn == '\0')
                     break;
              file_err = apprentice_1(ms, fn, action, mlist);
              errs = MAX(errs, file_err);
              fn = p;
       }
       if (errs == -1) {
              efree(mfn);
              efree(mlist);
              mlist = NULL;
              file_error(ms, 0, "could not find any magic files!");
              return NULL;
       }
       efree(mfn);
       return mlist;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 74 of file ascmagic.c.

{
       unichar *ubuf = NULL;
       size_t ulen;
       int rv = 1;

       const char *code = NULL;
       const char *code_mime = NULL;
       const char *type = NULL;

       if (ms->flags & MAGIC_APPLE)
              return 0;

       nbytes = trim_nuls(buf, nbytes);

       /* If file doesn't look like any sort of text, give up. */
       if (file_encoding(ms, buf, nbytes, &ubuf, &ulen, &code, &code_mime,
           &type) == 0) {
              rv = 0;
              goto done;
       }

       rv = file_ascmagic_with_encoding(ms, buf, nbytes, ubuf, ulen, code, 
           type);

 done:
       if (ubuf)
              free(ubuf);

       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected int file_ascmagic_with_encoding ( struct magic_set ,
const unsigned char *  ,
size_t  ,
unichar ,
size_t  ,
const char *  ,
const char *   
)

Definition at line 107 of file ascmagic.c.

{
       unsigned char *utf8_buf = NULL, *utf8_end;
       size_t mlen, i;
       const struct names *p;
       int rv = -1;
       int mime = ms->flags & MAGIC_MIME;

       const char *subtype = NULL;
       const char *subtype_mime = NULL;

       int has_escapes = 0;
       int has_backspace = 0;
       int seen_cr = 0;

       int n_crlf = 0;
       int n_lf = 0;
       int n_cr = 0;
       int n_nel = 0;

       size_t last_line_end = (size_t)-1;
       int has_long_lines = 0;

       if (ms->flags & MAGIC_APPLE)
              return 0;

       nbytes = trim_nuls(buf, nbytes);

       /* If we have fewer than 2 bytes, give up. */
       if (nbytes <= 1) {
              rv = 0;
              goto done;
       }

       /* Convert ubuf to UTF-8 and try text soft magic */
       /* malloc size is a conservative overestimate; could be
          improved, or at least realloced after conversion. */
       mlen = ulen * 6;
       utf8_buf = emalloc(mlen);

       if ((utf8_end = encode_utf8(utf8_buf, mlen, ubuf, ulen)) == NULL)
              goto done;
       if ((rv = file_softmagic(ms, utf8_buf, (size_t)(utf8_end - utf8_buf),
           TEXTTEST)) != 0)
              goto done;
       else
              rv = -1;

       /* look for tokens from names.h - this is expensive! */
       if ((ms->flags & MAGIC_NO_CHECK_TOKENS) != 0)
              goto subtype_identified;

       i = 0;
       while (i < ulen) {
              size_t end;

              /* skip past any leading space */
              while (i < ulen && ISSPC(ubuf[i]))
                     i++;
              if (i >= ulen)
                     break;

              /* find the next whitespace */
              for (end = i + 1; end < nbytes; end++)
                     if (ISSPC(ubuf[end]))
                            break;

              /* compare the word thus isolated against the token list */
              for (p = names; p < names + NNAMES; p++) {
                     if (ascmatch((const unsigned char *)p->name, ubuf + i,
                         end - i)) {
                            subtype = types[p->type].human;
                            subtype_mime = types[p->type].mime;
                            goto subtype_identified;
                     }
              }

              i = end;
       }

subtype_identified:

       /* Now try to discover other details about the file. */
       for (i = 0; i < ulen; i++) {
              if (ubuf[i] == '\n') {
                     if (seen_cr)
                            n_crlf++;
                     else
                            n_lf++;
                     last_line_end = i;
              } else if (seen_cr)
                     n_cr++;

              seen_cr = (ubuf[i] == '\r');
              if (seen_cr)
                     last_line_end = i;

              if (ubuf[i] == 0x85) { /* X3.64/ECMA-43 "next line" character */
                     n_nel++;
                     last_line_end = i;
              }

              /* If this line is _longer_ than MAXLINELEN, remember it. */
              if (i > last_line_end + MAXLINELEN)
                     has_long_lines = 1;

              if (ubuf[i] == '\033')
                     has_escapes = 1;
              if (ubuf[i] == '\b')
                     has_backspace = 1;
       }

       /* Beware, if the data has been truncated, the final CR could have
          been followed by a LF.  If we have HOWMANY bytes, it indicates
          that the data might have been truncated, probably even before
          this function was called. */
       if (seen_cr && nbytes < HOWMANY)
              n_cr++;

       if (strcmp(type, "binary") == 0) {
              rv = 0;
              goto done;
       }
       if (mime) {
              if ((mime & MAGIC_MIME_TYPE) != 0) {
                     if (subtype_mime) {
                            if (file_printf(ms, "%s", subtype_mime) == -1)
                                   goto done;
                     } else {
                            if (file_printf(ms, "text/plain") == -1)
                                   goto done;
                     }
              }
       } else {
              if (file_printf(ms, "%s", code) == -1)
                     goto done;

              if (subtype) {
                     if (file_printf(ms, " %s", subtype) == -1)
                            goto done;
              }

              if (file_printf(ms, " %s", type) == -1)
                     goto done;

              if (has_long_lines)
                     if (file_printf(ms, ", with very long lines") == -1)
                            goto done;

              /*
               * Only report line terminators if we find one other than LF,
               * or if we find none at all.
               */
              if ((n_crlf == 0 && n_cr == 0 && n_nel == 0 && n_lf == 0) ||
                  (n_crlf != 0 || n_cr != 0 || n_nel != 0)) {
                     if (file_printf(ms, ", with") == -1)
                            goto done;

                     if (n_crlf == 0 && n_cr == 0 && n_nel == 0 && n_lf == 0) {
                            if (file_printf(ms, " no") == -1)
                                   goto done;
                     } else {
                            if (n_crlf) {
                                   if (file_printf(ms, " CRLF") == -1)
                                          goto done;
                                   if (n_cr || n_lf || n_nel)
                                          if (file_printf(ms, ",") == -1)
                                                 goto done;
                            }
                            if (n_cr) {
                                   if (file_printf(ms, " CR") == -1)
                                          goto done;
                                   if (n_lf || n_nel)
                                          if (file_printf(ms, ",") == -1)
                                                 goto done;
                            }
                            if (n_lf) {
                                   if (file_printf(ms, " LF") == -1)
                                          goto done;
                                   if (n_nel)
                                          if (file_printf(ms, ",") == -1)
                                                 goto done;
                            }
                            if (n_nel)
                                   if (file_printf(ms, " NEL") == -1)
                                          goto done;
                     }

                     if (file_printf(ms, " line terminators") == -1)
                            goto done;
              }

              if (has_escapes)
                     if (file_printf(ms, ", with escape sequences") == -1)
                            goto done;
              if (has_backspace)
                     if (file_printf(ms, ", with overstriking") == -1)
                            goto done;
       }
       rv = 1;
done:
       if (utf8_buf)
              efree(utf8_buf);

       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected void file_badread ( struct magic_set )

Definition at line 150 of file funcs.c.

{
       file_error(ms, errno, "error reading");
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected void file_badseek ( struct magic_set )

Definition at line 144 of file funcs.c.

{
       file_error(ms, errno, "error seeking");
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected int file_buffer ( struct magic_set ,
php_stream *  ,
const char *  ,
const void *  ,
size_t   
)

Definition at line 156 of file funcs.c.

{
       int m = 0, rv = 0, looks_text = 0;
       int mime = ms->flags & MAGIC_MIME;
       const unsigned char *ubuf = buf;
       unichar *u8buf = NULL;
       size_t ulen;
       const char *code = NULL;
       const char *code_mime = "binary";
       const char *type = NULL;



       if (nb == 0) {
              if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
                  file_printf(ms, mime ? "application/x-empty" :
                  "empty") == -1)
                     return -1;
              return 1;
       } else if (nb == 1) {
              if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
                  file_printf(ms, mime ? "application/octet-stream" :
                  "very short file (no magic)") == -1)
                     return -1;
              return 1;
       }

       if ((ms->flags & MAGIC_NO_CHECK_ENCODING) == 0) {
              looks_text = file_encoding(ms, ubuf, nb, &u8buf, &ulen,
                  &code, &code_mime, &type);
       }

#if defined(__EMX__)
       if ((ms->flags & MAGIC_NO_CHECK_APPTYPE) == 0 && inname) {
              switch (file_os2_apptype(ms, inname, buf, nb)) {
              case -1:
                     return -1;
              case 0:
                     break;
              default:
                     return 1;
              }
       }
#endif

#if PHP_FILEINFO_UNCOMPRESS
       if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) == 0)
              if ((m = file_zmagic(ms, stream, inname, ubuf, nb)) != 0) {
                     if ((ms->flags & MAGIC_DEBUG) != 0)
                            (void)fprintf(stderr, "zmagic %d\n", m);
                     goto done;
       }
#endif

       /* Check if we have a tar file */
       if ((ms->flags & MAGIC_NO_CHECK_TAR) == 0)
              if ((m = file_is_tar(ms, ubuf, nb)) != 0) {
                     if ((ms->flags & MAGIC_DEBUG) != 0)
                            (void)fprintf(stderr, "tar %d\n", m);
                     goto done;
              }

       /* Check if we have a CDF file */
       if ((ms->flags & MAGIC_NO_CHECK_CDF) == 0) {
              int fd;
              TSRMLS_FETCH();
              if (stream && SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD, (void **)&fd, 0)) {
                     if ((m = file_trycdf(ms, fd, ubuf, nb)) != 0) {
                            if ((ms->flags & MAGIC_DEBUG) != 0)
                                   (void)fprintf(stderr, "cdf %d\n", m);
                            goto done;
                     }
              }
       }

       /* try soft magic tests */
       if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)
              if ((m = file_softmagic(ms, ubuf, nb, BINTEST)) != 0) {
                     if ((ms->flags & MAGIC_DEBUG) != 0)
                            (void)fprintf(stderr, "softmagic %d\n", m);
#ifdef BUILTIN_ELF
                     if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && m == 1 &&
                         nb > 5 && fd != -1) {
                            /*
                             * We matched something in the file, so this
                             * *might* be an ELF file, and the file is at
                             * least 5 bytes long, so if it's an ELF file
                             * it has at least one byte past the ELF magic
                             * number - try extracting information from the
                             * ELF headers that cannot easily * be
                             * extracted with rules in the magic file.
                             */
                            if ((m = file_tryelf(ms, fd, ubuf, nb)) != 0)
                                   if ((ms->flags & MAGIC_DEBUG) != 0)
                                          (void)fprintf(stderr,
                                              "elf %d\n", m);
                     }
#endif
                     goto done;
              }

       /* try text properties (and possibly text tokens) */
       if ((ms->flags & MAGIC_NO_CHECK_TEXT) == 0) {

              if ((m = file_ascmagic(ms, ubuf, nb)) != 0) {
                     if ((ms->flags & MAGIC_DEBUG) != 0)
                            (void)fprintf(stderr, "ascmagic %d\n", m);
                     goto done;
              }

              /* try to discover text encoding */
              if ((ms->flags & MAGIC_NO_CHECK_ENCODING) == 0) {
                     if (looks_text == 0)
                            if ((m = file_ascmagic_with_encoding( ms, ubuf,
                                nb, u8buf, ulen, code, type)) != 0) {
                                   if ((ms->flags & MAGIC_DEBUG) != 0)
                                          (void)fprintf(stderr,
                                              "ascmagic/enc %d\n", m);
                                   goto done;
                            }
              }
       }

       /* give up */
       m = 1;
       if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
           file_printf(ms, mime ? "application/octet-stream" : "data") == -1) {
           rv = -1;
       }
 done:
       if ((ms->flags & MAGIC_MIME_ENCODING) != 0) {
              if (ms->flags & MAGIC_MIME_TYPE)
                     if (file_printf(ms, "; charset=") == -1)
                            rv = -1;
              if (file_printf(ms, "%s", code_mime) == -1)
                     rv = -1;
       }
       if (u8buf)
              free(u8buf);
       if (rv)
              return rv;

       return m;
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected int file_check_mem ( struct magic_set ,
unsigned  int 
)

Definition at line 405 of file funcs.c.

{
       size_t len;

       if (level >= ms->c.len) {
              len = (ms->c.len += 20) * sizeof(*ms->c.li);
              ms->c.li = (ms->c.li == NULL) ? emalloc(len) : erealloc(ms->c.li, len);
       }
       ms->c.li[level].got_match = 0;
#ifdef ENABLE_CONDITIONALS
       ms->c.li[level].last_match = 0;
       ms->c.li[level].last_cond = COND_NONE;
#endif /* ENABLE_CONDITIONALS */
       return 0;
}

Here is the caller graph for this function:

protected void file_delmagic ( struct magic ,
int  type,
size_t  entries 
)

Definition at line 307 of file apprentice.c.

{
       if (p == NULL)
              return;
       switch (type) {
       case 3:
              /* Do nothing, it's part of the code segment */
              break;

       case 1:
              p--;
              /*FALLTHROUGH*/

       case 0:
              efree(p);
              break;

       default:
              abort();
       }
}

Here is the caller graph for this function:

protected int file_encoding ( struct magic_set ,
const unsigned char *  ,
size_t  ,
unichar **  ,
size_t ,
const char **  ,
const char **  ,
const char **   
)

Definition at line 62 of file encoding.c.

{
       size_t mlen;
       int rv = 1, ucs_type;
       unsigned char *nbuf = NULL;

       mlen = (nbytes + 1) * sizeof(nbuf[0]);
       if ((nbuf = CAST(unsigned char *, calloc((size_t)1, mlen))) == NULL) {
              file_oomem(ms, mlen);
              goto done;
       }
       mlen = (nbytes + 1) * sizeof((*ubuf)[0]);
       if ((*ubuf = CAST(unichar *, calloc((size_t)1, mlen))) == NULL) {
              file_oomem(ms, mlen);
              goto done;
       }

       *type = "text";
       if (looks_ascii(buf, nbytes, *ubuf, ulen)) {
              *code = "ASCII";
              *code_mime = "us-ascii";
       } else if (looks_utf8_with_BOM(buf, nbytes, *ubuf, ulen) > 0) {
              *code = "UTF-8 Unicode (with BOM)";
              *code_mime = "utf-8";
       } else if (file_looks_utf8(buf, nbytes, *ubuf, ulen) > 1) {
              *code = "UTF-8 Unicode";
              *code_mime = "utf-8";
       } else if ((ucs_type = looks_ucs16(buf, nbytes, *ubuf, ulen)) != 0) {
              if (ucs_type == 1) {
                     *code = "Little-endian UTF-16 Unicode";
                     *code_mime = "utf-16le";
              } else {
                     *code = "Big-endian UTF-16 Unicode";
                     *code_mime = "utf-16be";
              }
       } else if (looks_latin1(buf, nbytes, *ubuf, ulen)) {
              *code = "ISO-8859";
              *code_mime = "iso-8859-1";
       } else if (looks_extended(buf, nbytes, *ubuf, ulen)) {
              *code = "Non-ISO extended-ASCII";
              *code_mime = "unknown-8bit";
       } else {
              from_ebcdic(buf, nbytes, nbuf);

              if (looks_ascii(nbuf, nbytes, *ubuf, ulen)) {
                     *code = "EBCDIC";
                     *code_mime = "ebcdic";
              } else if (looks_latin1(nbuf, nbytes, *ubuf, ulen)) {
                     *code = "International EBCDIC";
                     *code_mime = "ebcdic";
              } else { /* Doesn't look like text at all */
                     rv = 0;
                     *type = "binary";
              }
       }

 done:
       if (nbuf)
              free(nbuf);

       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected void file_error ( struct magic_set ,
int  ,
const char *  ,
  ... 
)

Definition at line 116 of file funcs.c.

{
       va_list va;
       va_start(va, f);
       file_error_core(ms, error, f, va, 0);
       va_end(va);
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected const char* file_fmttime ( uint32_t  ,
int   
)

Definition at line 69 of file print.c.

{
       char *pp;
       time_t t = (time_t)v;
       struct tm *tm;

       if (local) {
              pp = ctime(&t);
       } else {
#ifndef HAVE_DAYLIGHT
              private int daylight = 0;
#ifdef HAVE_TM_ISDST
              private time_t now = (time_t)0;

              if (now == (time_t)0) {
                     struct tm *tm1;
                     (void)time(&now);
                     tm1 = localtime(&now);
                     if (tm1 == NULL)
                            return "*Invalid time*";
                     daylight = tm1->tm_isdst;
              }
#endif /* HAVE_TM_ISDST */
#endif /* HAVE_DAYLIGHT */
              if (daylight)
                     t += 3600;
              tm = gmtime(&t);
              if (tm == NULL)
                     return "*Invalid time*";
              pp = asctime(tm);
       }

       pp[strcspn(pp, "\n")] = '\0';
       return pp;
}

Here is the caller graph for this function:

protected int file_fsmagic ( struct magic_set ms,
const char *  fn,
struct stat *  sb,
php_stream *  stream 
)

Definition at line 93 of file fsmagic.c.

{
       int mime = ms->flags & MAGIC_MIME;
       TSRMLS_FETCH();

       if (ms->flags & MAGIC_APPLE)
              return 0;

       if (!fn && !stream) {
              return 0;
       }

       if (stream) {
              php_stream_statbuf ssb;
              if (php_stream_stat(stream, &ssb) < 0) {
                     if (ms->flags & MAGIC_ERROR) {
                            file_error(ms, errno, "cannot stat `%s'", fn);
                            return -1;
                     }
                     return 1;
              }
              memcpy(sb, &ssb.sb, sizeof(struct stat));
       } else {
              if (php_sys_stat(fn, sb) != 0) {
                     if (ms->flags & MAGIC_ERROR) {
                            file_error(ms, errno, "cannot stat `%s'", fn);
                            return -1;
                     }
                     return 1;
              }
       }

       if (!mime) {
#ifdef S_ISUID
              if (sb->st_mode & S_ISUID) 
                     if (file_printf(ms, "setuid ") == -1)
                            return -1;
#endif
#ifdef S_ISGID
              if (sb->st_mode & S_ISGID) 
                     if (file_printf(ms, "setgid ") == -1)
                            return -1;
#endif
#ifdef S_ISVTX
              if (sb->st_mode & S_ISVTX) 
                     if (file_printf(ms, "sticky ") == -1)
                            return -1;
#endif
       }

       switch (sb->st_mode & S_IFMT) {
#ifndef PHP_WIN32
# ifdef S_IFCHR
              case S_IFCHR:
                     /* 
                      * If -s has been specified, treat character special files
                      * like ordinary files.  Otherwise, just report that they
                      * are block special files and go on to the next file.
                      */
                     if ((ms->flags & MAGIC_DEVICES) != 0) {
                            break;
                     }
                     if (mime) {
                            if (handle_mime(ms, mime, "x-character-device") == -1)
                                   return -1;
                     } else {
#  ifdef HAVE_STAT_ST_RDEV
#   ifdef dv_unit
                            if (file_printf(ms, "character special (%d/%d/%d)",
                                major(sb->st_rdev), dv_unit(sb->st_rdev),
                                          dv_subunit(sb->st_rdev)) == -1)
                                   return -1;
#   else
                            if (file_printf(ms, "character special (%ld/%ld)",
                                (long)major(sb->st_rdev), (long)minor(sb->st_rdev))
                                == -1)
                                   return -1;
#   endif
#  else
                            if (file_printf(ms, "character special") == -1)
                                   return -1;
#  endif
                     }
                     return 1;
# endif
#endif

#ifdef S_IFIFO
                     case S_IFIFO:
                            if((ms->flags & MAGIC_DEVICES) != 0)
                                   break;
                            if (mime) {
                                   if (handle_mime(ms, mime, "x-fifo") == -1)
                                          return -1;
                            } else if (file_printf(ms, "fifo (named pipe)") == -1)
                                   return -1;
                            return 1;
#endif
#ifdef S_IFDOOR
                            case S_IFDOOR:
                                   if (mime) {
                                          if (handle_mime(ms, mime, "x-door") == -1)
                                                 return -1;
                                   } else if (file_printf(ms, "door") == -1)
                                          return -1;
                                   return 1;
#endif

#ifdef S_IFLNK
       case S_IFLNK:
              /* stat is used, if it made here then the link is broken */
                     if (ms->flags & MAGIC_ERROR) {
                         file_error(ms, errno, "unreadable symlink `%s'", fn);
                         return -1;
                     }
       return 1;
#endif

#ifdef S_IFSOCK
#ifndef __COHERENT__
       case S_IFSOCK:
              if (mime) {
                     if (handle_mime(ms, mime, "x-socket") == -1)
                            return -1;
              } else if (file_printf(ms, "socket") == -1)
                     return -1;
              return 1;
#endif
#endif

              case S_IFREG:
                     break;

              default:
                     file_error(ms, 0, "invalid mode 0%o", sb->st_mode);
                     return -1;
                     /*NOTREACHED*/
       }

       /*
        * regular file, check next possibility
        *
        * If stat() tells us the file has zero length, report here that
        * the file is empty, so we can skip all the work of opening and 
        * reading the file.
        * But if the -s option has been given, we skip this optimization,
        * since on some systems, stat() reports zero size for raw disk
        * partitions.  (If the block special device really has zero length,
        * the fact that it is empty will be detected and reported correctly
        * when we read the file.)
        */
       if ((ms->flags & MAGIC_DEVICES) == 0 && sb->st_size == 0) {
              if (mime) {
                     if (handle_mime(ms, mime, "x-empty") == -1)
                            return -1;
              } else if (file_printf(ms, "empty") == -1)
                     return -1;
              return 1;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected const char* file_getbuffer ( struct magic_set )

Definition at line 331 of file funcs.c.

{
       char *pbuf, *op, *np;
       size_t psize, len;

       if (ms->event_flags & EVENT_HAD_ERR)
              return NULL;

       if (ms->flags & MAGIC_RAW)
              return ms->o.buf;

       if (ms->o.buf == NULL)
              return NULL;

       /* * 4 is for octal representation, + 1 is for NUL */
       len = strlen(ms->o.buf);
       if (len > (SIZE_MAX - 1) / 4) {
              return NULL;
       }
       psize = len * 4 + 1;
       pbuf = erealloc(ms->o.pbuf, psize);
       ms->o.pbuf = pbuf;

#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)
       {
              mbstate_t state;
              wchar_t nextchar;
              int mb_conv = 1;
              size_t bytesconsumed;
              char *eop;
              (void)memset(&state, 0, sizeof(mbstate_t));

              np = ms->o.pbuf;
              op = ms->o.buf;
              eop = op + len;

              while (op < eop) {
                     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)) {
                            (void)memcpy(np, op, bytesconsumed);
                            op += bytesconsumed;
                            np += bytesconsumed;
                     } else {
                            while (bytesconsumed-- > 0)
                                   OCTALIFY(np, op);
                     }
              }
              *np = '\0';

              /* Parsing succeeded as a multi-byte sequence */
              if (mb_conv != 0)
                     return ms->o.pbuf;
       }
#endif

       for (np = ms->o.pbuf, op = ms->o.buf; *op; op++) {
              if (isprint((unsigned char)*op)) {
                     *np++ = *op;
              } else {
                     OCTALIFY(np, op);
              }
       }
       *np = '\0';
       return ms->o.pbuf;
}

Here is the caller graph for this function:

protected int file_is_tar ( struct magic_set ,
const unsigned char *  ,
size_t   
)

Definition at line 63 of file is_tar.c.

{
       /*
        * Do the tar test first, because if the first file in the tar
        * archive starts with a dot, we can confuse it with an nroff file.
        */
       int tar;
       int mime = ms->flags & MAGIC_MIME;

       if ((ms->flags & MAGIC_APPLE) != 0)
              return 0;

       tar = is_tar(buf, nbytes);
       if (tar < 1 || tar > 3)
              return 0;

       if (file_printf(ms, "%s", mime ? "application/x-tar" :
           tartype[tar - 1]) == -1)
              return -1;
       return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected int file_looks_utf8 ( const unsigned char *  ,
size_t  ,
unichar ,
size_t  
)

Definition at line 275 of file encoding.c.

{
       size_t i;
       int n;
       unichar c;
       int gotone = 0, ctrl = 0;

       if (ubuf)
              *ulen = 0;

       for (i = 0; i < nbytes; i++) {
              if ((buf[i] & 0x80) == 0) {    /* 0xxxxxxx is plain ASCII */
                     /*
                      * Even if the whole file is valid UTF-8 sequences,
                      * still reject it if it uses weird control characters.
                      */

                     if (text_chars[buf[i]] != T)
                            ctrl = 1;

                     if (ubuf)
                            ubuf[(*ulen)++] = buf[i];
              } else if ((buf[i] & 0x40) == 0) { /* 10xxxxxx never 1st byte */
                     return -1;
              } else {                       /* 11xxxxxx begins UTF-8 */
                     int following;

                     if ((buf[i] & 0x20) == 0) {        /* 110xxxxx */
                            c = buf[i] & 0x1f;
                            following = 1;
                     } else if ((buf[i] & 0x10) == 0) { /* 1110xxxx */
                            c = buf[i] & 0x0f;
                            following = 2;
                     } else if ((buf[i] & 0x08) == 0) { /* 11110xxx */
                            c = buf[i] & 0x07;
                            following = 3;
                     } else if ((buf[i] & 0x04) == 0) { /* 111110xx */
                            c = buf[i] & 0x03;
                            following = 4;
                     } else if ((buf[i] & 0x02) == 0) { /* 1111110x */
                            c = buf[i] & 0x01;
                            following = 5;
                     } else
                            return -1;

                     for (n = 0; n < following; n++) {
                            i++;
                            if (i >= nbytes)
                                   goto done;

                            if ((buf[i] & 0x80) == 0 || (buf[i] & 0x40))
                                   return -1;

                            c = (c << 6) + (buf[i] & 0x3f);
                     }

                     if (ubuf)
                            ubuf[(*ulen)++] = c;
                     gotone = 1;
              }
       }
done:
       return ctrl ? 0 : (gotone ? 2 : 1);
}

Here is the caller graph for this function:

protected void file_magerror ( struct magic_set ,
const char *  ,
  ... 
)

Definition at line 129 of file funcs.c.

{
       va_list va;
       va_start(va, f);
       file_error_core(ms, 0, f, va, ms->line);
       va_end(va);
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected void file_magwarn ( struct magic_set ,
const char *  ,
  ... 
)

Definition at line 53 of file print.c.

{
       va_list va;
       char *expanded_format;
       TSRMLS_FETCH();

       va_start(va, f);
       vasprintf(&expanded_format, f, va);
       va_end(va);
       
       php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Warning: %s", expanded_format);

       free(expanded_format);
}

Here is the caller graph for this function:

protected size_t file_mbswidth ( const char *  )
protected void file_oomem ( struct magic_set ,
size_t   
)

Definition at line 138 of file funcs.c.

{
       file_error(ms, errno, "cannot allocate %zu bytes", len);
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected int file_pipe2file ( struct magic_set ,
int  ,
const void *  ,
size_t   
)

Definition at line 244 of file compress.c.

{
       char buf[4096];
       int r, tfd;

       (void)strlcpy(buf, "/tmp/file.XXXXXX", sizeof buf);
#ifndef HAVE_MKSTEMP
       {
              char *ptr = mktemp(buf);
              tfd = open(ptr, O_RDWR|O_TRUNC|O_EXCL|O_CREAT, 0600);
              r = errno;
              (void)unlink(ptr);
              errno = r;
       }
#else
       tfd = mkstemp(buf);
       r = errno;
       (void)unlink(buf);
       errno = r;
#endif
       if (tfd == -1) {
              file_error(ms, errno,
                  "cannot create temporary file for pipe copy");
              return -1;
       }

       if (swrite(tfd, startbuf, nbytes) != (ssize_t)nbytes)
              r = 1;
       else {
              while ((r = sread(fd, buf, sizeof(buf), 1)) > 0)
                     if (swrite(tfd, buf, (size_t)r) != r)
                            break;
       }

       switch (r) {
       case -1:
              file_error(ms, errno, "error copying from pipe to temp file");
              return -1;
       case 0:
              break;
       default:
              file_error(ms, errno, "error while writing to temp file");
              return -1;
       }

       /*
        * We duplicate the file descriptor, because fclose on a
        * tmpfile will delete the file, but any open descriptors
        * can still access the phantom inode.
        */
       if ((fd = dup2(tfd, fd)) == -1) {
              file_error(ms, errno, "could not dup descriptor for temp file");
              return -1;
       }
       (void)close(tfd);
       if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
              file_badseek(ms);
              return -1;
       }
       return fd;
}

Here is the call graph for this function:

protected int file_printf ( struct magic_set ,
const char *  ,
  ... 
)

Definition at line 53 of file funcs.c.

{
       va_list ap;
       int len;
       char *buf = NULL, *newstr;

       va_start(ap, fmt);
       len = vspprintf(&buf, 0, fmt, ap);
       va_end(ap);

       if (ms->o.buf != NULL) {
              len = spprintf(&newstr, 0, "%s%s", ms->o.buf, (buf ? buf : ""));
              if (buf) {
                     efree(buf);
              }
              efree(ms->o.buf);
              ms->o.buf = newstr;
       } else {
              ms->o.buf = buf;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 303 of file funcs.c.

{
       if (ms->mlist == NULL) {
              file_error(ms, 0, "no magic files loaded");
              return -1;
       }
       if (ms->o.buf) {
              efree(ms->o.buf);
              ms->o.buf = NULL;
       }
       if (ms->o.pbuf) {
              efree(ms->o.pbuf);
              ms->o.pbuf = NULL;
       }
       ms->event_flags &= ~EVENT_HAD_ERR;
       ms->error = -1;
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected void file_showstr ( FILE *  ,
const char *  ,
size_t   
)

Definition at line 1939 of file apprentice.c.

{
       char   c;

       for (;;) {
              c = *s++;
              if (len == ~0U) {
                     if (c == '\0')
                            break;
              }
              else  {
                     if (len-- == 0)
                            break;
              }
              if (c >= 040 && c <= 0176)  /* TODO isprint && !iscntrl */
                     (void) fputc(c, fp);
              else {
                     (void) fputc('\\', fp);
                     switch (c) {
                     case '\a':
                            (void) fputc('a', fp);
                            break;

                     case '\b':
                            (void) fputc('b', fp);
                            break;

                     case '\f':
                            (void) fputc('f', fp);
                            break;

                     case '\n':
                            (void) fputc('n', fp);
                            break;

                     case '\r':
                            (void) fputc('r', fp);
                            break;

                     case '\t':
                            (void) fputc('t', fp);
                            break;

                     case '\v':
                            (void) fputc('v', fp);
                            break;

                     default:
                            (void) fprintf(fp, "%.3o", c & 0377);
                            break;
                     }
              }
       }
}

Here is the caller graph for this function:

protected uint64_t file_signextend ( struct magic_set ,
struct magic ,
uint64_t   
)

Definition at line 810 of file apprentice.c.

{
       if (!(m->flag & UNSIGNED)) {
              switch(m->type) {
              /*
               * Do not remove the casts below.  They are
               * vital.  When later compared with the data,
               * the sign extension must have happened.
               */
              case FILE_BYTE:
                     v = (char) v;
                     break;
              case FILE_SHORT:
              case FILE_BESHORT:
              case FILE_LESHORT:
                     v = (short) v;
                     break;
              case FILE_DATE:
              case FILE_BEDATE:
              case FILE_LEDATE:
              case FILE_MEDATE:
              case FILE_LDATE:
              case FILE_BELDATE:
              case FILE_LELDATE:
              case FILE_MELDATE:
              case FILE_LONG:
              case FILE_BELONG:
              case FILE_LELONG:
              case FILE_MELONG:
              case FILE_FLOAT:
              case FILE_BEFLOAT:
              case FILE_LEFLOAT:
                     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:
              case FILE_DOUBLE:
              case FILE_BEDOUBLE:
              case FILE_LEDOUBLE:
                     v = (int64_t) v;
                     break;
              case FILE_STRING:
              case FILE_PSTRING:
              case FILE_BESTRING16:
              case FILE_LESTRING16:
              case FILE_REGEX:
              case FILE_SEARCH:
              case FILE_DEFAULT:
              case FILE_INDIRECT:
                     break;
              default:
                     if (ms->flags & MAGIC_CHECK)
                         file_magwarn(ms, "cannot happen: m->type=%d\n",
                                m->type);
                     return ~0U;
              }
       }
       return v;
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected int file_softmagic ( struct magic_set ,
const unsigned char *  ,
size_t  ,
int   
)

Definition at line 74 of file softmagic.c.

{
       struct mlist *ml;
       int rv;
       for (ml = ms->mlist->next; ml != ms->mlist; ml = ml->next)
              if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, mode)) != 0)
                     return rv;

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected int file_trycdf ( struct magic_set ,
int  ,
const unsigned char *  ,
size_t   
)

Definition at line 200 of file readcdf.c.

{
       cdf_info_t info;
       cdf_header_t h;
       cdf_sat_t sat, ssat;
       cdf_stream_t sst, scn;
       cdf_dir_t dir;
       int i;
       const char *expn = "";

       info.i_fd = fd;
       info.i_buf = buf;
       info.i_len = nbytes;
       if (ms->flags & MAGIC_APPLE)
              return 0;
       if (cdf_read_header(&info, &h) == -1)
              return 0;
#ifdef CDF_DEBUG
       cdf_dump_header(&h);
#endif

       if ((i = cdf_read_sat(&info, &h, &sat)) == -1) {
              expn = "Can't read SAT";
              goto out0;
       }
#ifdef CDF_DEBUG
       cdf_dump_sat("SAT", &sat, CDF_SEC_SIZE(&h));
#endif

       if ((i = cdf_read_ssat(&info, &h, &sat, &ssat)) == -1) {
              expn = "Can't read SSAT";
              goto out1;
       }
#ifdef CDF_DEBUG
       cdf_dump_sat("SSAT", &ssat, CDF_SHORT_SEC_SIZE(&h));
#endif

       if ((i = cdf_read_dir(&info, &h, &sat, &dir)) == -1) {
              expn = "Can't read directory";
              goto out2;
       }

       if ((i = cdf_read_short_stream(&info, &h, &sat, &dir, &sst)) == -1) {
              expn = "Cannot read short stream";
              goto out3;
       }
#ifdef CDF_DEBUG
       cdf_dump_dir(&info, &h, &sat, &ssat, &sst, &dir);
#endif

       if ((i = cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir,
           &scn)) == -1) {
              expn = "Cannot read summary info";
              goto out4;
       }
#ifdef CDF_DEBUG
       cdf_dump_summary_info(&h, &scn);
#endif
       if ((i = cdf_file_summary_info(ms, &scn)) == -1)
              expn = "Can't expand summary_info";
       free(scn.sst_tab);
out4:
       free(sst.sst_tab);
out3:
       free(dir.dir_tab);
out2:
       free(ssat.sat_tab);
out1:
       free(sat.sat_tab);
out0:
       if (i != 1) {
              if (file_printf(ms, "CDF V2 Document") == -1)
                     return -1;
              if (*expn)
                     if (file_printf(ms, ", corrupt: %s", expn) == -1)
                            return -1;
              i = 1;
       }
       return i;
}

Here is the call graph for this function:

Here is the caller graph for this function:

protected int file_tryelf ( struct magic_set ,
int  ,
const unsigned char *  ,
size_t   
)

Here is the caller graph for this function:

protected ssize_t sread ( int  ,
void *  ,
size_t  ,
int   
)

Definition at line 179 of file compress.c.

{
       int rv;
#ifdef FIONREAD
       int t = 0;
#endif
       size_t rn = n;

       if (fd == STDIN_FILENO)
              goto nocheck;

#ifdef FIONREAD
       if ((canbepipe && (ioctl(fd, FIONREAD, &t) == -1)) || (t == 0)) {
#ifdef FD_ZERO
              int cnt;
              for (cnt = 0;; cnt++) {
                     fd_set check;
                     struct timeval tout = {0, 100 * 1000};
                     int selrv;

                     FD_ZERO(&check);
                     FD_SET(fd, &check);

                     /*
                      * Avoid soft deadlock: do not read if there
                      * is nothing to read from sockets and pipes.
                      */
                     selrv = select(fd + 1, &check, NULL, NULL, &tout);
                     if (selrv == -1) {
                            if (errno == EINTR || errno == EAGAIN)
                                   continue;
                     } else if (selrv == 0 && cnt >= 5) {
                            return 0;
                     } else
                            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))) {
              case -1:
                     if (errno == EINTR)
                            continue;
                     return -1;
              case 0:
                     return rn - n;
              default:
                     n -= rv;
                     buf = ((char *)buf) + rv;
                     break;
              }
       while (n > 0);
       return rn;
}

Here is the call graph for this function:

Here is the caller graph for this function:

size_t strlcat ( char *  dst,
const char *  src,
size_t  siz 
)

Here is the caller graph for this function:

size_t strlcpy ( char *  dst,
const char *  src,
size_t  siz 
)

Here is the caller graph for this function:


Variable Documentation

const char* file_names[]

Definition at line 104 of file apprentice.c.

Definition at line 105 of file apprentice.c.

char* sys_errlist[]