]> granicus.if.org Git - php/commitdiff
ported ext/zip
authorAnatol Belski <ab@php.net>
Tue, 19 Aug 2014 09:47:21 +0000 (11:47 +0200)
committerAnatol Belski <ab@php.net>
Tue, 19 Aug 2014 09:47:21 +0000 (11:47 +0200)
ext/zip/php_zip.c

index 2fb20a5df38d4730a0baaa00758da0537bf5996e..9fd3e8ce4a7c77ac3b1daf41ce055d91ce1b1923 100644 (file)
@@ -311,11 +311,11 @@ static int php_zip_add_file(struct zip *za, const char *filename, size_t filenam
 }
 /* }}} */
 
-static int php_zip_parse_options(zval *options, long *remove_all_path, char **remove_path, int *remove_path_len, char **add_path, int *add_path_len TSRMLS_DC) /* {{{ */
+static int php_zip_parse_options(zval *options, php_int_t *remove_all_path, char **remove_path, int *remove_path_len, char **add_path, int *add_path_len TSRMLS_DC) /* {{{ */
 {
        zval *option;
        if ((option = zend_hash_str_find(HASH_OF(options), "remove_all_path", sizeof("remove_all_path") - 1)) != NULL) {
-               long opt;
+               php_int_t opt;
                if (Z_TYPE_P(option) != IS_INT) {
                        zval tmp;
                        ZVAL_DUP(&tmp, option);
@@ -481,7 +481,7 @@ static char * php_zipobj_get_zip_comment(struct zip *za, int *len TSRMLS_DC) /*
 
 #endif /* }}} */
 
-int php_zip_glob(char *pattern, int pattern_len, long flags, zval *return_value TSRMLS_DC) /* {{{ */
+int php_zip_glob(char *pattern, int pattern_len, php_int_t flags, zval *return_value TSRMLS_DC) /* {{{ */
 {
 #ifdef HAVE_GLOB
        char cwd[MAXPATHLEN];
@@ -565,7 +565,7 @@ int php_zip_glob(char *pattern, int pattern_len, long flags, zval *return_value
                 * able to filter directories out.
                 */
                if (flags & GLOB_ONLYDIR) {
-                       struct stat s;
+                       zend_stat_t s;
 
                        if (0 != VCWD_STAT(globbuf.gl_pathv[n], &s)) {
                                continue;
@@ -637,7 +637,7 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val
 
                /* only the files, directories are ignored */
                for (i = 0; i < files_cnt; i++) {
-                       struct stat s;
+                       zend_stat_t s;
                        char   fullpath[MAXPATHLEN];
                        int    ovector[3];
                        int    matches;
@@ -1244,12 +1244,12 @@ static PHP_NAMED_FUNCTION(zif_zip_entry_close)
 static PHP_NAMED_FUNCTION(zif_zip_entry_read)
 {
        zval * zip_entry;
-       long len = 0;
+       php_int_t len = 0;
        zip_read_rsrc * zr_rsrc;
        zend_string *buffer;
        int n = 0;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zip_entry, &len) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|i", &zip_entry, &len) == FAILURE) {
                return;
        }
 
@@ -1296,10 +1296,10 @@ static void php_zip_entry_get_info(INTERNAL_FUNCTION_PARAMETERS, int opt) /* {{{
                        RETURN_STRING((char *)zr_rsrc->sb.name);
                        break;
                case 1:
-                       RETURN_INT((long) (zr_rsrc->sb.comp_size));
+                       RETURN_INT((php_int_t) (zr_rsrc->sb.comp_size));
                        break;
                case 2:
-                       RETURN_INT((long) (zr_rsrc->sb.size));
+                       RETURN_INT((php_int_t) (zr_rsrc->sb.size));
                        break;
                case 3:
                        switch (zr_rsrc->sb.comp_method) {
@@ -1333,7 +1333,7 @@ static void php_zip_entry_get_info(INTERNAL_FUNCTION_PARAMETERS, int opt) /* {{{
                                default:
                                        RETURN_FALSE;
                        }
-                       RETURN_INT((long) (zr_rsrc->sb.comp_method));
+                       RETURN_INT((php_int_t) (zr_rsrc->sb.comp_method));
                        break;
        }
 
@@ -1378,13 +1378,13 @@ static ZIPARCHIVE_METHOD(open)
 {
        struct zip *intern;
        int err = 0;
-       long flags = 0;
+       php_int_t flags = 0;
        char *resolved_path;
        zend_string *filename;
        zval *self = getThis();
        ze_zip_object *ze_obj = NULL;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "P|l", &filename, &flags) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "P|i", &filename, &flags) == FAILURE) {
                return;
        }
 
@@ -1423,7 +1423,7 @@ static ZIPARCHIVE_METHOD(open)
        intern = zip_open(resolved_path, flags, &err);
        if (!intern || err) {
                efree(resolved_path);
-               RETURN_INT((long)err);
+               RETURN_INT((php_int_t)err);
        }
        ze_obj->filename = resolved_path;
        ze_obj->filename_len = strlen(resolved_path);
@@ -1576,8 +1576,8 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
        char *remove_path = NULL;
        char *add_path = NULL;
        int  add_path_len, remove_path_len = 0, path_len = 0;
-       long remove_all_path = 0;
-       long flags = 0;
+       php_int_t remove_all_path = 0;
+       php_int_t flags = 0;
        zval *options = NULL;
        int found;
        zend_string *pattern;
@@ -1589,7 +1589,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
        ZIP_FROM_OBJECT(intern, self);
        /* 1 == glob, 2 == pcre */
        if (type == 1) {
-               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "P|la",
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "P|ia",
                                        &pattern, &flags, &options) == FAILURE) {
                        return;
                }
@@ -1645,7 +1645,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
 
                                if (add_path) {
                                        if ((add_path_len + file_stripped_len) > MAXPATHLEN) {
-                                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Entry name too long (max: %d, %ld given)",
+                                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Entry name too long (max: %d, %pd given)",
                                                MAXPATHLEN - 1, (add_path_len + file_stripped_len));
                                                zval_ptr_dtor(return_value);
                                                RETURN_FALSE;
@@ -1697,7 +1697,7 @@ static ZIPARCHIVE_METHOD(addFile)
        zval *self = getThis();
        char *entry_name = NULL;
        int entry_name_len = 0;
-       long offset_start = 0, offset_len = 0;
+       php_int_t offset_start = 0, offset_len = 0;
        zend_string *filename;
 
        if (!self) {
@@ -1706,7 +1706,7 @@ static ZIPARCHIVE_METHOD(addFile)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "P|sll",
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "P|sii",
                        &filename, &entry_name, &entry_name_len, &offset_start, &offset_len) == FAILURE) {
                return;
        }
@@ -1735,8 +1735,9 @@ static ZIPARCHIVE_METHOD(addFromString)
 {
        struct zip *intern;
        zval *self = getThis();
-       char *buffer, *name;
-       int buffer_len, name_len;
+       zend_string *buffer;
+       char *name;
+       int name_len;
        ze_zip_object *ze_obj;
        struct zip_source *zs;
        int pos = 0;
@@ -1748,8 +1749,8 @@ static ZIPARCHIVE_METHOD(addFromString)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
-                       &name, &name_len, &buffer, &buffer_len) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sS",
+                       &name, &name_len, &buffer) == FAILURE) {
                return;
        }
 
@@ -1762,10 +1763,10 @@ static ZIPARCHIVE_METHOD(addFromString)
                ze_obj->buffers_cnt++;
                pos = 0;
        }
-       ze_obj->buffers[pos] = (char *)emalloc(buffer_len + 1);
-       memcpy(ze_obj->buffers[pos], buffer, buffer_len + 1);
+       ze_obj->buffers[pos] = (char *)emalloc(buffer->len + 1);
+       memcpy(ze_obj->buffers[pos], buffer->val, buffer->len + 1);
 
-       zs = zip_source_buffer(intern, ze_obj->buffers[pos], buffer_len, 0);
+       zs = zip_source_buffer(intern, ze_obj->buffers[pos], buffer->len, 0);
 
        if (zs == NULL) {
                RETURN_FALSE;
@@ -1796,7 +1797,7 @@ static ZIPARCHIVE_METHOD(statName)
 {
        struct zip *intern;
        zval *self = getThis();
-       long flags = 0;
+       php_int_t flags = 0;
        struct zip_stat sb;
        zend_string *name;
 
@@ -1806,7 +1807,7 @@ static ZIPARCHIVE_METHOD(statName)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "P|l", &name, &flags) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "P|i", &name, &flags) == FAILURE) {
                return;
        }
 
@@ -1822,7 +1823,7 @@ static ZIPARCHIVE_METHOD(statIndex)
 {
        struct zip *intern;
        zval *self = getThis();
-       long index, flags = 0;
+       php_int_t index, flags = 0;
 
        struct zip_stat sb;
 
@@ -1832,7 +1833,7 @@ static ZIPARCHIVE_METHOD(statIndex)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l",
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i|i",
                        &index, &flags) == FAILURE) {
                return;
        }
@@ -1850,8 +1851,8 @@ static ZIPARCHIVE_METHOD(locateName)
 {
        struct zip *intern;
        zval *self = getThis();
-       long flags = 0;
-       long idx = -1;
+       php_int_t flags = 0;
+       php_int_t idx = -1;
        zend_string *name;
 
        if (!self) {
@@ -1860,7 +1861,7 @@ static ZIPARCHIVE_METHOD(locateName)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "P|l", &name, &flags) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "P|i", &name, &flags) == FAILURE) {
                return;
        }
 
@@ -1868,7 +1869,7 @@ static ZIPARCHIVE_METHOD(locateName)
                RETURN_FALSE;
        }
 
-       idx = (long)zip_name_locate(intern, (const char *)name->val, flags);
+       idx = (php_int_t)zip_name_locate(intern, (const char *)name->val, flags);
 
        if (idx >= 0) {
                RETURN_INT(idx);
@@ -1885,7 +1886,7 @@ static ZIPARCHIVE_METHOD(getNameIndex)
        struct zip *intern;
        zval *self = getThis();
        const char *name;
-       long flags = 0, index = 0;
+       php_int_t flags = 0, index = 0;
 
        if (!self) {
                RETURN_FALSE;
@@ -1893,7 +1894,7 @@ static ZIPARCHIVE_METHOD(getNameIndex)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l",
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i|i",
                        &index, &flags) == FAILURE) {
                return;
        }
@@ -1940,7 +1941,7 @@ static ZIPARCHIVE_METHOD(getArchiveComment)
 {
        struct zip *intern;
        zval *self = getThis();
-       long flags = 0;
+       php_int_t flags = 0;
        const char * comment;
        int comment_len = 0;
 
@@ -1950,7 +1951,7 @@ static ZIPARCHIVE_METHOD(getArchiveComment)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|i", &flags) == FAILURE) {
                return;
        }
 
@@ -1958,7 +1959,7 @@ static ZIPARCHIVE_METHOD(getArchiveComment)
        if(comment==NULL) {
                RETURN_FALSE;
        }
-       RETURN_STRINGL((char *)comment, (long)comment_len);
+       RETURN_STRINGL((char *)comment, (php_int_t)comment_len);
 }
 /* }}} */
 
@@ -2001,7 +2002,7 @@ static ZIPARCHIVE_METHOD(setCommentIndex)
 {
        struct zip *intern;
        zval *self = getThis();
-       long index;
+       php_int_t index;
        int comment_len;
        char * comment;
        struct zip_stat sb;
@@ -2012,7 +2013,7 @@ static ZIPARCHIVE_METHOD(setCommentIndex)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls",
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "is",
                        &index, &comment, &comment_len) == FAILURE) {
                return;
        }
@@ -2033,7 +2034,7 @@ static ZIPARCHIVE_METHOD(setExternalAttributesName)
        zval *self = getThis();
        int name_len;
        char *name;
-       long flags=0, opsys, attr;
+       php_int_t flags=0, opsys, attr;
        zip_int64_t idx;
 
        if (!self) {
@@ -2042,7 +2043,7 @@ static ZIPARCHIVE_METHOD(setExternalAttributesName)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll|l",
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sii|i",
                        &name, &name_len, &opsys, &attr, &flags) == FAILURE) {
                return;
        }
@@ -2069,7 +2070,7 @@ static ZIPARCHIVE_METHOD(setExternalAttributesIndex)
 {
        struct zip *intern;
        zval *self = getThis();
-       long index, flags=0, opsys, attr;
+       php_int_t index, flags=0, opsys, attr;
        struct zip_stat sb;
 
        if (!self) {
@@ -2078,7 +2079,7 @@ static ZIPARCHIVE_METHOD(setExternalAttributesIndex)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll|l",
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "iii|i",
                        &index, &opsys, &attr, &flags) == FAILURE) {
                return;
        }
@@ -2100,7 +2101,7 @@ static ZIPARCHIVE_METHOD(getExternalAttributesName)
        zval *self = getThis(), *z_opsys, *z_attr;
        int name_len;
        char *name;
-       long flags=0;
+       php_int_t flags=0;
        zip_uint8_t opsys;
        zip_uint32_t attr;
        zip_int64_t idx;
@@ -2111,7 +2112,7 @@ static ZIPARCHIVE_METHOD(getExternalAttributesName)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/z/|l",
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/z/|i",
                        &name, &name_len, &z_opsys, &z_attr, &flags) == FAILURE) {
                return;
        }
@@ -2142,7 +2143,7 @@ static ZIPARCHIVE_METHOD(getExternalAttributesIndex)
 {
        struct zip *intern;
        zval *self = getThis(), *z_opsys, *z_attr;
-       long index, flags=0;
+       php_int_t index, flags=0;
        zip_uint8_t opsys;
        zip_uint32_t attr;
        struct zip_stat sb;
@@ -2153,7 +2154,7 @@ static ZIPARCHIVE_METHOD(getExternalAttributesIndex)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz/z/|l",
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "iz/z/|i",
                        &index, &z_opsys, &z_attr, &flags) == FAILURE) {
                return;
        }
@@ -2179,7 +2180,7 @@ static ZIPARCHIVE_METHOD(getCommentName)
        struct zip *intern;
        zval *self = getThis();
        int name_len, idx;
-       long flags = 0;
+       php_int_t flags = 0;
        int comment_len = 0;
        const char * comment;
        char *name;
@@ -2190,7 +2191,7 @@ static ZIPARCHIVE_METHOD(getCommentName)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l",
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|i",
                        &name, &name_len, &flags) == FAILURE) {
                return;
        }
@@ -2205,7 +2206,7 @@ static ZIPARCHIVE_METHOD(getCommentName)
        }
 
        comment = zip_get_file_comment(intern, idx, &comment_len, (int)flags);
-       RETURN_STRINGL((char *)comment, (long)comment_len);
+       RETURN_STRINGL((char *)comment, (php_int_t)comment_len);
 }
 /* }}} */
 
@@ -2215,7 +2216,7 @@ static ZIPARCHIVE_METHOD(getCommentIndex)
 {
        struct zip *intern;
        zval *self = getThis();
-       long index, flags = 0;
+       php_int_t index, flags = 0;
        const char * comment;
        int comment_len = 0;
        struct zip_stat sb;
@@ -2226,14 +2227,14 @@ static ZIPARCHIVE_METHOD(getCommentIndex)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l",
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i|i",
                                &index, &flags) == FAILURE) {
                return;
        }
 
        PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
        comment = zip_get_file_comment(intern, index, &comment_len, (int)flags);
-       RETURN_STRINGL((char *)comment, (long)comment_len);
+       RETURN_STRINGL((char *)comment, (php_int_t)comment_len);
 }
 /* }}} */
 
@@ -2243,7 +2244,7 @@ static ZIPARCHIVE_METHOD(deleteIndex)
 {
        struct zip *intern;
        zval *self = getThis();
-       long index;
+       php_int_t index;
 
        if (!self) {
                RETURN_FALSE;
@@ -2251,7 +2252,7 @@ static ZIPARCHIVE_METHOD(deleteIndex)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i", &index) == FAILURE) {
                return;
        }
 
@@ -2307,7 +2308,7 @@ static ZIPARCHIVE_METHOD(renameIndex)
 
        char *new_name;
        int new_name_len;
-       long index;
+       php_int_t index;
 
        if (!self) {
                RETURN_FALSE;
@@ -2315,7 +2316,7 @@ static ZIPARCHIVE_METHOD(renameIndex)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &index, &new_name, &new_name_len) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "is", &index, &new_name, &new_name_len) == FAILURE) {
                return;
        }
 
@@ -2374,7 +2375,7 @@ static ZIPARCHIVE_METHOD(unchangeIndex)
 {
        struct zip *intern;
        zval *self = getThis();
-       long index;
+       php_int_t index;
 
        if (!self) {
                RETURN_FALSE;
@@ -2382,7 +2383,7 @@ static ZIPARCHIVE_METHOD(unchangeIndex)
 
        ZIP_FROM_OBJECT(intern, self);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i", &index) == FAILURE) {
                return;
        }
 
@@ -2574,9 +2575,9 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
        struct zip_stat sb;
        struct zip_file *zf;
 
-       long index = -1;
-       long flags = 0;
-       long len = 0;
+       php_int_t index = -1;
+       php_int_t flags = 0;
+       php_int_t len = 0;
 
        zend_string *filename;
        zend_string *buffer;
@@ -2590,12 +2591,12 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
        ZIP_FROM_OBJECT(intern, self);
 
        if (type == 1) {
-               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "P|ll", &filename, &len, &flags) == FAILURE) {
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "P|ii", &filename, &len, &flags) == FAILURE) {
                        return;
                }
                PHP_ZIP_STAT_PATH(intern, filename->val, filename->len, flags, sb);
        } else {
-               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|ll", &index, &len, &flags) == FAILURE) {
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i|ii", &index, &len, &flags) == FAILURE) {
                        return;
                }
                PHP_ZIP_STAT_INDEX(intern, index, 0, sb);