diff options
Diffstat (limited to 'ext/zip/lib/zip_rename.c')
-rw-r--r-- | ext/zip/lib/zip_rename.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/ext/zip/lib/zip_rename.c b/ext/zip/lib/zip_rename.c index 8141dc46a..e40ab2767 100644 --- a/ext/zip/lib/zip_rename.c +++ b/ext/zip/lib/zip_rename.c @@ -1,11 +1,9 @@ /* - $NiH: zip_rename.c,v 1.15 2004/11/30 22:19:38 wiz Exp $ - zip_rename.c -- rename file in zip archive - Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2009 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. - The authors can be contacted at <nih@giga.or.at> + The authors can be contacted at <libzip@nih.at> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -35,15 +33,30 @@ -#include "zip.h" +#include <string.h> + #include "zipint.h" -PHPZIPAPI int +ZIP_EXTERN(int) zip_rename(struct zip *za, int idx, const char *name) { - if (idx >= za->nentry || idx < 0) { + const char *old_name; + int old_is_dir, new_is_dir; + + if (idx >= za->nentry || idx < 0 || name[0] == '\0') { + _zip_error_set(&za->error, ZIP_ER_INVAL, 0); + return -1; + } + + if ((old_name=zip_get_name(za, idx, 0)) == NULL) + return -1; + + new_is_dir = (name[strlen(name)-1] == '/'); + old_is_dir = (old_name[strlen(old_name)-1] == '/'); + + if (new_is_dir != old_is_dir) { _zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; } |