Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions ext/fileinfo/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,12 @@ if test "$PHP_FILEINFO" != "no"; then

AC_CHECK_HEADERS([sys/sysmacros.h])

AC_CHECK_FUNCS([strcasestr],,[
AC_MSG_NOTICE([using libmagic strcasestr implementation])
libmagic_sources="$libmagic_sources libmagic/strcasestr.c"
])

AX_GCC_FUNC_ATTRIBUTE([visibility])

PHP_NEW_EXTENSION([fileinfo],
[fileinfo.c php_libmagic.c $libmagic_sources],
[$ext_shared],,
[-I@ext_srcdir@/libmagic])
[-I@ext_srcdir@/libmagic -DHAVE_STRCASESTR=1])
PHP_ADD_BUILD_DIR([$ext_builddir/libmagic])
PHP_ADD_EXTENSION_DEP(fileinfo, pcre)

Expand Down
48 changes: 24 additions & 24 deletions ext/fileinfo/fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static void finfo_objects_free(zend_object *object)
{
finfo_object *intern = php_finfo_fetch_object(object);

magic_close(intern->magic);
php_magic_close(intern->magic);
zend_object_std_dtor(&intern->zo);
}
/* }}} */
Expand Down Expand Up @@ -118,7 +118,7 @@ PHP_MINFO_FUNCTION(fileinfo)
{
char magic_ver[15];

int raw_version = magic_version();
int raw_version = php_magic_version();
(void)snprintf(magic_ver, sizeof(magic_ver), "%d.%d", raw_version / 100, raw_version % 100);

php_info_print_table_start();
Expand All @@ -145,7 +145,7 @@ PHP_FUNCTION(finfo_open)
if (object) {
zend_replace_error_handling(EH_THROW, NULL, &zeh);

magic_close(Z_FINFO_P(object)->magic);
php_magic_close(Z_FINFO_P(object)->magic);
Z_FINFO_P(object)->magic = NULL;
}

Expand All @@ -162,16 +162,16 @@ PHP_FUNCTION(finfo_open)
file = resolved_path;
}

struct magic_set *magic = magic_open(options);
struct magic_set *magic = php_magic_open(options);

if (magic == NULL) {
php_error_docref(NULL, E_WARNING, "Invalid mode '" ZEND_LONG_FMT "'.", options);
goto err;
}

if (magic_load(magic, file) == -1) {
if (php_magic_load(magic, file) == -1) {
php_error_docref(NULL, E_WARNING, "Failed to load magic database at \"%s\"", file);
magic_close(magic);
php_magic_close(magic);
goto err;
}

Expand Down Expand Up @@ -228,7 +228,7 @@ PHP_FUNCTION(finfo_set_flags)

/* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME
* and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */
magic_setflags(Z_FINFO_P(self)->magic, options);
php_magic_setflags(Z_FINFO_P(self)->magic, options);

RETURN_TRUE;
}
Expand Down Expand Up @@ -271,9 +271,9 @@ static const char* php_fileinfo_from_path(struct magic_set *magic, const zend_st
}
}
if (!ret_val) {
ret_val = magic_stream(magic, stream);
ret_val = php_magic_stream(magic, stream);
if (UNEXPECTED(ret_val == NULL)) {
php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic));
php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", php_magic_errno(magic), php_magic_error(magic));
}
}

Expand Down Expand Up @@ -311,18 +311,18 @@ PHP_FUNCTION(finfo_file)
}

/* Set options for the current file/buffer. */
int old_options = magic_getflags(magic);
int old_options = php_magic_getflags(magic);
if (options) {
/* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME
* and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */
magic_setflags(magic, options);
php_magic_setflags(magic, options);
}

const char *ret_val = php_fileinfo_from_path(magic, path, context);

/* Restore options */
if (options) {
magic_setflags(magic, old_options);
php_magic_setflags(magic, old_options);
}

if (UNEXPECTED(ret_val == NULL)) {
Expand Down Expand Up @@ -359,22 +359,22 @@ PHP_FUNCTION(finfo_buffer)
struct magic_set *magic = Z_FINFO_P(self)->magic;

/* Set options for the current file/buffer. */
int old_options = magic_getflags(magic);
int old_options = php_magic_getflags(magic);
if (options) {
/* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME
* and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */
magic_setflags(magic, options);
php_magic_setflags(magic, options);
}

const char *ret_val = magic_buffer(magic, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
const char *ret_val = php_magic_buffer(magic, ZSTR_VAL(buffer), ZSTR_LEN(buffer));

/* Restore options */
if (options) {
magic_setflags(magic, old_options);
php_magic_setflags(magic, old_options);
}

if (UNEXPECTED(ret_val == NULL)) {
php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic));
php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", php_magic_errno(magic), php_magic_error(magic));
RETURN_FALSE;
} else {
RETURN_STRING(ret_val);
Expand Down Expand Up @@ -415,15 +415,15 @@ PHP_FUNCTION(mime_content_type)
RETURN_THROWS();
}

magic = magic_open(MAGIC_MIME_TYPE);
magic = php_magic_open(MAGIC_MIME_TYPE);
if (UNEXPECTED(magic == NULL)) {
php_error_docref(NULL, E_WARNING, "Failed to load magic database");
RETURN_FALSE;
}

if (UNEXPECTED(magic_load(magic, NULL) == -1)) {
php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic));
magic_close(magic);
if (UNEXPECTED(php_magic_load(magic, NULL) == -1)) {
php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", php_magic_errno(magic), php_magic_error(magic));
php_magic_close(magic);
RETURN_FALSE;
}

Expand All @@ -436,9 +436,9 @@ PHP_FUNCTION(mime_content_type)
zend_off_t current_stream_pos = php_stream_tell(stream);
php_stream_seek(stream, 0, SEEK_SET);

ret_val = magic_stream(magic, stream);
ret_val = php_magic_stream(magic, stream);
if (UNEXPECTED(ret_val == NULL)) {
php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic));
php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", php_magic_errno(magic), php_magic_error(magic));
}

php_stream_seek(stream, current_stream_pos, SEEK_SET);
Expand All @@ -449,5 +449,5 @@ PHP_FUNCTION(mime_content_type)
} else {
RETVAL_STRING(ret_val);
}
magic_close(magic);
php_magic_close(magic);
}
Loading
Loading