/* {{{ macros and type definitions */
typedef struct _php_fileinfo {
- long options;
+ php_int_t options;
struct magic_set *magic;
} php_fileinfo;
Create a new fileinfo resource. */
PHP_FUNCTION(finfo_open)
{
- long options = MAGIC_NONE;
+ php_int_t options = MAGIC_NONE;
char *file = NULL;
int file_len = 0;
php_fileinfo *finfo;
FILEINFO_DECLARE_INIT_OBJECT(object)
char resolved_path[MAXPATHLEN];
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lp", &options, &file, &file_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ip", &options, &file, &file_len) == FAILURE) {
FILEINFO_DESTROY_OBJECT(object);
RETURN_FALSE;
}
Set libmagic configuration options. */
PHP_FUNCTION(finfo_set_flags)
{
- long options;
+ php_int_t options;
php_fileinfo *finfo;
zval *zfinfo;
FILEINFO_DECLARE_INIT_OBJECT(object)
if (object) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &options) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i", &options) == FAILURE) {
RETURN_FALSE;
}
FILEINFO_FROM_OBJECT(finfo, object);
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zfinfo, &options) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ri", &zfinfo, &options) == FAILURE) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE(finfo, php_fileinfo *, zfinfo, -1, "file_info", le_fileinfo);
static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mimetype_emu) /* {{{ */
{
- long options = 0;
+ php_int_t options = 0;
char *ret_val = NULL, *buffer = NULL;
int buffer_len;
php_fileinfo *finfo = NULL;
goto common;
}
} else if (object) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lr", &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ir", &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
RETURN_FALSE;
}
FILEINFO_FROM_OBJECT(finfo, object);
magic = finfo->magic;
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|lr", &zfinfo, &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|ir", &zfinfo, &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE(finfo, php_fileinfo *, zfinfo, -1, "file_info", le_fileinfo);
case FILEINFO_MODE_STREAM:
{
php_stream *stream;
- off_t streampos;
+ php_off_t streampos;
php_stream_from_zval_no_verify(stream, what);
if (!stream) {
uint32_t i, j;
size_t files = 0, maxfiles = 0;
char **filearr = NULL;
- struct stat st;
+ php_stat_t st;
struct magic_map *map;
struct magic_entry_set mset[MAGIC_SETS];
php_stream *dir;
php_stream_closedir(dir);
goto out;
}
- if (stat(mfn, &st) == -1 || !S_ISREG(st.st_mode)) {
+ if (zend_stat(mfn, &st) == -1 || !S_ISREG(st.st_mode)) {
continue;
}
if (files >= maxfiles) {
if (NULL != fn) {
nentries = (uint32_t)(st.sb.st_size / sizeof(struct magic));
entries = (uint32_t)(st.sb.st_size / sizeof(struct magic));
- if ((off_t)(entries * sizeof(struct magic)) != st.sb.st_size) {
+ if ((php_off_t)(entries * sizeof(struct magic)) != st.sb.st_size) {
file_error(ms, 0, "Size of `%s' %llu is not a multiple of %zu",
dbname, (unsigned long long)st.sb.st_size,
sizeof(struct magic));
assert(nm + sizeof(ar) < m);
- if (php_stream_seek(stream,(off_t)sizeof(struct magic), SEEK_SET) != sizeof(struct magic)) {
+ if (php_stream_seek(stream,(php_off_t)sizeof(struct magic), SEEK_SET) != sizeof(struct magic)) {
file_error(ms, errno, "error seeking `%s'", dbname);
goto out;
}
}
static ssize_t
-cdf_read(const cdf_info_t *info, off_t off, void *buf, size_t len)
+cdf_read(const cdf_info_t *info, php_off_t off, void *buf, size_t len)
{
size_t siz = (size_t)off + len;
- if ((off_t)(off + len) != (off_t)siz) {
+ if ((php_off_t)(off + len) != (php_off_t)siz) {
errno = EINVAL;
return -1;
}
if (info->i_fd == -1)
return -1;
- if (FINFO_LSEEK_FUNC(info->i_fd, off, SEEK_SET) == (off_t)-1)
+ if (FINFO_LSEEK_FUNC(info->i_fd, off, SEEK_SET) == (php_off_t)-1)
return -1;
if (FINFO_READ_FUNC(info->i_fd, buf, len) != (ssize_t)len)
char buf[512];
(void)memcpy(cdf_bo.s, "\01\02\03\04", 4);
- if (cdf_read(info, (off_t)0, buf, sizeof(buf)) == -1)
+ if (cdf_read(info, (php_off_t)0, buf, sizeof(buf)) == -1)
return -1;
cdf_unpack_header(h, buf);
cdf_swap_header(h);
size_t ss = CDF_SEC_SIZE(h);
size_t pos = CDF_SEC_POS(h, id);
assert(ss == len);
- return cdf_read(info, (off_t)pos, ((char *)buf) + offs, len);
+ return cdf_read(info, (php_off_t)pos, ((char *)buf) + offs, len);
}
ssize_t
return -1;
}
(void)close(tfd);
- if (FINFO_LSEEK_FUNC(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
+ if (FINFO_LSEEK_FUNC(fd, (php_off_t)0, SEEK_SET) == (php_off_t)-1) {
file_badseek(ms);
return -1;
}
(void) close(0);
if (fd != -1) {
(void) dup(fd);
- (void) FINFO_LSEEK_FUNC(0, (off_t)0, SEEK_SET);
+ (void) FINFO_LSEEK_FUNC(0, (php_off_t)0, SEEK_SET);
} else {
(void) dup(fdin[0]);
(void) close(fdin[0]);
case ET_CORE:
flags |= FLAGS_IS_CORE;
if (dophn_core(ms, clazz, swap, fd,
- (off_t)elf_getu(swap, elfhdr.e_phoff),
+ (php_off_t)elf_getu(swap, elfhdr.e_phoff),
elf_getu16(swap, elfhdr.e_phnum),
(size_t)elf_getu16(swap, elfhdr.e_phentsize),
fsize, &flags) == -1)
case ET_EXEC:
case ET_DYN:
if (dophn_exec(ms, clazz, swap, fd,
- (off_t)elf_getu(swap, elfhdr.e_phoff),
+ (php_off_t)elf_getu(swap, elfhdr.e_phoff),
elf_getu16(swap, elfhdr.e_phnum),
(size_t)elf_getu16(swap, elfhdr.e_phentsize),
fsize, &flags, elf_getu16(swap, elfhdr.e_shnum))
/*FALLTHROUGH*/
case ET_REL:
if (doshn(ms, clazz, swap, fd,
- (off_t)elf_getu(swap, elfhdr.e_shoff),
+ (php_off_t)elf_getu(swap, elfhdr.e_shoff),
elf_getu16(swap, elfhdr.e_shnum),
(size_t)elf_getu16(swap, elfhdr.e_shentsize),
fsize, &flags, elf_getu16(swap, elfhdr.e_machine),
}
protected int
-file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb, php_stream *stream)
+file_fsmagic(struct magic_set *ms, const char *fn, php_stat_t *sb, php_stream *stream)
{
int ret, did = 0;
int mime = ms->flags & MAGIC_MIME;
#include "magic.h"
#ifdef ELFCORE
-private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t,
- off_t, int *);
+private int dophn_core(struct magic_set *, int, int, int, php_off_t, int, size_t,
+ php_off_t, int *);
#endif
private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,
- off_t, int *, int);
+ php_off_t, int *, int);
private int doshn(struct magic_set *, int, int, int, off_t, int, size_t,
- off_t, int *, int);
+ php_off_t, int *, int);
private size_t donote(struct magic_set *, unsigned char *, size_t, size_t, int,
int, size_t, int *);
#define xsh_size (size_t)(clazz == ELFCLASS32 \
? elf_getu32(swap, sh32.sh_size) \
: elf_getu64(swap, sh64.sh_size))
-#define xsh_offset (off_t)(clazz == ELFCLASS32 \
+#define xsh_offset (php_off_t)(clazz == ELFCLASS32 \
? elf_getu32(swap, sh32.sh_offset) \
: elf_getu64(swap, sh64.sh_offset))
#define xsh_type (clazz == ELFCLASS32 \
#define xph_type (clazz == ELFCLASS32 \
? elf_getu32(swap, ph32.p_type) \
: elf_getu32(swap, ph64.p_type))
-#define xph_offset (off_t)(clazz == ELFCLASS32 \
+#define xph_offset (php_off_t)(clazz == ELFCLASS32 \
? elf_getu32(swap, ph32.p_offset) \
: elf_getu64(swap, ph64.p_offset))
#define xph_align (size_t)((clazz == ELFCLASS32 \
- ? (off_t) (ph32.p_align ? \
+ ? (php_off_t) (ph32.p_align ? \
elf_getu32(swap, ph32.p_align) : 4) \
- : (off_t) (ph64.p_align ? \
+ : (php_off_t) (ph64.p_align ? \
elf_getu64(swap, ph64.p_align) : 4)))
#define xph_filesz (size_t)((clazz == ELFCLASS32 \
? elf_getu32(swap, ph32.p_filesz) \
#define FLAGS_IS_CORE 0x10
private int
-dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
- int num, size_t size, off_t fsize, int *flags)
+dophn_core(struct magic_set *ms, int clazz, int swap, int fd, php_off_t off,
+ int num, size_t size, php_off_t fsize, int *flags)
{
Elf32_Phdr ph32;
Elf64_Phdr ph64;
* Loop through all the program headers.
*/
for ( ; num; num--) {
- if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (off_t)-1) {
+ if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (php_off_t)-1) {
file_badseek(ms);
return -1;
}
* This is a PT_NOTE section; loop through all the notes
* in the section.
*/
- if (FINFO_LSEEK_FUNC(fd, xph_offset, SEEK_SET) == (off_t)-1) {
+ if (FINFO_LSEEK_FUNC(fd, xph_offset, SEEK_SET) == (php_off_t)-1) {
file_badseek(ms);
return -1;
}
Elf64_Shdr sh64;
int stripped = 1;
void *nbuf;
- off_t noff, coff, name_off;
+ php_off_t noff, coff, name_off;
uint64_t cap_hw1 = 0; /* SunOS 5.x hardware capabilites */
uint64_t cap_sf1 = 0; /* SunOS 5.x software capabilites */
char name[50];
}
for ( ; num; num--) {
- if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (off_t)-1) {
+ if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (php_off_t)-1) {
file_badseek(ms);
return -1;
}
switch (xsh_type) {
case SHT_NOTE:
nbuf = emalloc((size_t)xsh_size);
- if ((noff = FINFO_LSEEK_FUNC(fd, (off_t)xsh_offset, SEEK_SET)) ==
- (off_t)-1) {
+ if ((noff = FINFO_LSEEK_FUNC(fd, (php_off_t)xsh_offset, SEEK_SET)) ==
+ (php_off_t)-1) {
file_badread(ms);
efree(nbuf);
return -1;
noff = 0;
for (;;) {
- if (noff >= (off_t)xsh_size)
+ if (noff >= (php_off_t)xsh_size)
break;
noff = donote(ms, nbuf, (size_t)noff,
(size_t)xsh_size, clazz, swap, 4,
efree(nbuf);
break;
case SHT_SUNW_cap:
- if (FINFO_LSEEK_FUNC(fd, (off_t)xsh_offset, SEEK_SET) ==
- (off_t)-1) {
+ if (FINFO_LSEEK_FUNC(fd, (php_off_t)xsh_offset, SEEK_SET) ==
+ (php_off_t)-1) {
file_badseek(ms);
return -1;
}
Elf64_Cap cap64;
char cbuf[/*CONSTCOND*/
MAX(sizeof cap32, sizeof cap64)];
- if ((coff += xcap_sizeof) > (off_t)xsh_size)
+ if ((coff += xcap_sizeof) > (php_off_t)xsh_size)
break;
if (FINFO_READ_FUNC(fd, cbuf, (size_t)xcap_sizeof) !=
(ssize_t)xcap_sizeof) {
* otherwise it's statically linked.
*/
private int
-dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
- int num, size_t size, off_t fsize, int *flags, int sh_num)
+dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, php_off_t off,
+ int num, size_t size, php_off_t fsize, int *flags, int sh_num)
{
Elf32_Phdr ph32;
Elf64_Phdr ph64;
}
for ( ; num; num--) {
- if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (off_t)-1) {
+ if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (php_off_t)-1) {
file_badseek(ms);
return -1;
}
* This is a PT_NOTE section; loop through all the notes
* in the section.
*/
- if (FINFO_LSEEK_FUNC(fd, xph_offset, SEEK_SET) == (off_t)-1) {
+ if (FINFO_LSEEK_FUNC(fd, xph_offset, SEEK_SET) == (php_off_t)-1) {
file_badseek(ms);
return -1;
}
int clazz;
int swap;
struct stat st;
- off_t fsize;
+ php_off_t fsize;
int flags = 0;
Elf32_Ehdr elf32hdr;
Elf64_Ehdr elf64hdr;
/*
* If we cannot seek, it must be a pipe, socket or fifo.
*/
- if((FINFO_LSEEK_FUNC(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
+ if((FINFO_LSEEK_FUNC(fd, (php_off_t)0, SEEK_SET) == (php_off_t)-1) && (errno == ESPIPE))
fd = file_pipe2file(ms, fd, buf, nbytes);
if (fstat(fd, &st) == -1) {