Rizin
unix-like reverse engineering framework and cli tools
zip_file_rename.c File Reference
#include <string.h>
#include "zipint.h"

Go to the source code of this file.

Functions

ZIP_EXTERN int zip_file_rename (zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags)
 

Function Documentation

◆ zip_file_rename()

ZIP_EXTERN int zip_file_rename ( zip_t za,
zip_uint64_t  idx,
const char *  name,
zip_flags_t  flags 
)

Definition at line 41 of file zip_file_rename.c.

41  {
42  const char *old_name;
43  int old_is_dir, new_is_dir;
44 
45  if (idx >= za->nentry || (name != NULL && strlen(name) > ZIP_UINT16_MAX)) {
47  return -1;
48  }
49 
50  if (ZIP_IS_RDONLY(za)) {
52  return -1;
53  }
54 
55  if ((old_name = zip_get_name(za, idx, 0)) == NULL)
56  return -1;
57 
58  new_is_dir = (name != NULL && name[strlen(name) - 1] == '/');
59  old_is_dir = (old_name[strlen(old_name) - 1] == '/');
60 
61  if (new_is_dir != old_is_dir) {
63  return -1;
64  }
65 
66  return _zip_set_name(za, idx, name, flags);
67 }
#define NULL
Definition: cris-opc.c:27
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
Definition: zip_error.c:126
ZIP_EXTERN const char *_Nullable zip_get_name(zip_t *_Nonnull, zip_uint64_t, zip_flags_t)
Definition: zip_get_name.c:41
#define ZIP_ER_RDONLY
Definition: zip.h:130
#define ZIP_ER_INVAL
Definition: zip.h:123
int idx
Definition: setup.py:197
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
Definition: z80asm.h:102
zip_error_t error
Definition: zipint.h:281
zip_uint64_t nentry
Definition: zipint.h:292
int _zip_set_name(zip_t *za, zip_uint64_t idx, const char *name, zip_flags_t flags)
Definition: zip_set_name.c:42
#define ZIP_UINT16_MAX
Definition: zipconf.h:47
#define ZIP_IS_RDONLY(za)
Definition: zipint.h:479
zip_t * za
Definition: ziptool.c:79

References _zip_set_name(), zip::error, flags, setup::idx, zip::nentry, NULL, za, ZIP_ER_INVAL, ZIP_ER_RDONLY, zip_error_set(), zip_get_name(), ZIP_IS_RDONLY, and ZIP_UINT16_MAX.

Referenced by zip_rename().