]> granicus.if.org Git - php/commitdiff
- MFH: locateName should not change the state/error, can be used to test
authorPierre Joye <pajoye@php.net>
Sun, 13 Aug 2006 23:43:11 +0000 (23:43 +0000)
committerPierre Joye <pajoye@php.net>
Sun, 13 Aug 2006 23:43:11 +0000 (23:43 +0000)
  an entry

ext/zip/php_zip.c
ext/zip/tests/oo_namelocate.phpt

index 27f0bb2dd756595d18d6b42c5a057c826abe61ee..0e46345f7a70f8d440c96fda5f9da8950920ccf0 100644 (file)
@@ -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);
+       }
 }
 /* }}} */
 
index ccfa3a9d8dcdfb8d85608f04f6389c7013adeb5b..e7a844817fafe75497ff7d5e328b0bd85b4e5569 100644 (file)
@@ -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)