diff options
author | Pierre Joye <pajoye@php.net> | 2006-08-13 23:43:11 +0000 |
---|---|---|
committer | Pierre Joye <pajoye@php.net> | 2006-08-13 23:43:11 +0000 |
commit | 284ce40c4a50f42b66ac0dff58786b74e76493b7 (patch) | |
tree | fb8cd18bc5fc175db867234b8b2411edb73a874a | |
parent | 8d07735332892b44880d701ffe6f8e119181dd8d (diff) | |
download | php-git-284ce40c4a50f42b66ac0dff58786b74e76493b7.tar.gz |
- MFH: locateName should not change the state/error, can be used to test
an entry
-rw-r--r-- | ext/zip/php_zip.c | 14 | ||||
-rw-r--r-- | ext/zip/tests/oo_namelocate.phpt | 17 |
2 files changed, 22 insertions, 9 deletions
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 27f0bb2dd7..0e46345f7a 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -1153,6 +1153,7 @@ ZIPARCHIVE_METHOD(locateName) char *name; int name_len; long flags = 0; + long idx = -1; if (!this) { RETURN_FALSE; @@ -1169,7 +1170,18 @@ ZIPARCHIVE_METHOD(locateName) RETURN_FALSE; } - RETURN_LONG((long)zip_name_locate(intern, (const char *)name, flags)) + idx = (long)zip_name_locate(intern, (const char *)name, flags); + + if (idx<0) { + /* reset the error */ + if (intern->error.str) { + _zip_error_fini(&intern->error); + } + _zip_error_init(&intern->error); + RETURN_FALSE; + } else { + RETURN_LONG(idx); + } } /* }}} */ diff --git a/ext/zip/tests/oo_namelocate.phpt b/ext/zip/tests/oo_namelocate.phpt index ccfa3a9d8d..e7a844817f 100644 --- a/ext/zip/tests/oo_namelocate.phpt +++ b/ext/zip/tests/oo_namelocate.phpt @@ -31,15 +31,16 @@ if (!$zip->open($file)) { exit('failed'); } -echo $zip->locateName('entry1.txt') . "\n"; -echo $zip->locateName('eNtry2.txt') . "\n"; -echo $zip->locateName('eNtry2.txt', ZIPARCHIVE::FL_NOCASE) . "\n"; -echo $zip->locateName('enTRy2d.txt', ZIPARCHIVE::FL_NOCASE|ZIPARCHIVE::FL_NODIR) . "\n"; + +var_dump($zip->locateName('entry1.txt')); +var_dump($zip->locateName('eNtry2.txt')); +var_dump($zip->locateName('eNtry2.txt', ZIPARCHIVE::FL_NOCASE)); +var_dump($zip->locateName('enTRy2d.txt', ZIPARCHIVE::FL_NOCASE|ZIPARCHIVE::FL_NODIR)); $zip->close(); ?> --EXPECTF-- -0 --1 -1 -2 +int(0) +bool(false) +int(1) +int(2) |