Back to index

php5  5.3.10
Defines | Functions | Variables
is_tar.c File Reference
#include "file.h"
#include "magic.h"
#include <string.h>
#include <ctype.h>
#include "tar.h"

Go to the source code of this file.

Defines

#define isodigit(c)   ( ((c) >= '0') && ((c) <= '7') )

Functions

private int is_tar (const unsigned char *, size_t)
private int from_oct (int, const char *)
protected int file_is_tar (struct magic_set *ms, const unsigned char *buf, size_t nbytes)

Variables

static const char tartype [][32]

Define Documentation

#define isodigit (   c)    ( ((c) >= '0') && ((c) <= '7') )

Definition at line 51 of file is_tar.c.


Function Documentation

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

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:

private int from_oct ( int  digs,
const char *  where 
)

Definition at line 138 of file is_tar.c.

{
       int    value;

       while (isspace((unsigned char)*where)) {  /* Skip spaces */
              where++;
              if (--digs <= 0)
                     return -1;           /* All blank field */
       }
       value = 0;
       while (digs > 0 && isodigit(*where)) {    /* Scan til nonoctal */
              value = (value << 3) | (*where++ - '0');
              --digs;
       }

       if (digs > 0 && *where && !isspace((unsigned char)*where))
              return -1;                  /* Ended on non-space/nul */

       return value;
}

Here is the caller graph for this function:

private int is_tar ( const unsigned char *  buf,
size_t  nbytes 
)

Definition at line 93 of file is_tar.c.

{
       const union record *header = (const union record *)(const void *)buf;
       int    i;
       int    sum, recsum;
       const char    *p;

       if (nbytes < sizeof(union record))
              return 0;

       recsum = from_oct(8,  header->header.chksum);

       sum = 0;
       p = header->charptr;
       for (i = sizeof(union record); --i >= 0;) {
              /*
               * We cannot use unsigned char here because of old compilers,
               * e.g. V7.
               */
              sum += 0xFF & *p++;
       }

       /* Adjust checksum to count the "chksum" field as blanks. */
       for (i = sizeof(header->header.chksum); --i >= 0;)
              sum -= 0xFF & header->header.chksum[i];
       sum += ' '* sizeof header->header.chksum; 

       if (sum != recsum)
              return 0;     /* Not a tar archive */
       
       if (strcmp(header->header.magic, GNUTMAGIC) == 0) 
              return 3;            /* GNU Unix Standard tar archive */
       if (strcmp(header->header.magic, TMAGIC) == 0) 
              return 2;            /* Unix Standard tar archive */

       return 1;                   /* Old fashioned tar archive */
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char tartype[][32] [static]
Initial value:
 {
       "tar archive",
       "POSIX tar archive",
       "POSIX tar archive (GNU)",
}

Definition at line 56 of file is_tar.c.