Rizin
unix-like reverse engineering framework and cli tools
zip_delete.c File Reference
#include "zipint.h"

Go to the source code of this file.

Functions

ZIP_EXTERN int zip_delete (zip_t *za, zip_uint64_t idx)
 

Function Documentation

◆ zip_delete()

ZIP_EXTERN int zip_delete ( zip_t za,
zip_uint64_t  idx 
)

Definition at line 39 of file zip_delete.c.

39  {
40  const char *name;
41 
42  if (idx >= za->nentry) {
44  return -1;
45  }
46 
47  if (ZIP_IS_RDONLY(za)) {
49  return -1;
50  }
51 
52  if ((name = _zip_get_name(za, idx, 0, &za->error)) == NULL) {
53  return -1;
54  }
55 
56  if (!_zip_hash_delete(za->names, (const zip_uint8_t *)name, &za->error)) {
57  return -1;
58  }
59 
60  /* allow duplicate file names, because the file will
61  * be removed directly afterwards */
62  if (_zip_unchange(za, idx, 1) != 0)
63  return -1;
64 
65  za->entry[idx].deleted = 1;
66 
67  return 0;
68 }
#define NULL
Definition: cris-opc.c:27
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
Definition: zip_error.c:126
#define ZIP_ER_RDONLY
Definition: zip.h:130
#define ZIP_ER_INVAL
Definition: zip.h:123
int idx
Definition: setup.py:197
const char * name
Definition: op.c:541
Definition: z80asm.h:102
bool deleted
Definition: zipint.h:412
zip_error_t error
Definition: zipint.h:281
zip_entry_t * entry
Definition: zipint.h:294
zip_uint64_t nentry
Definition: zipint.h:292
zip_hash_t * names
Definition: zipint.h:300
const char * _zip_get_name(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error)
Definition: zip_get_name.c:47
bool _zip_hash_delete(zip_hash_t *hash, const zip_uint8_t *name, zip_error_t *error)
Definition: zip_hash.c:264
int _zip_unchange(zip_t *za, zip_uint64_t idx, int allow_duplicates)
Definition: zip_unchange.c:47
uint8_t zip_uint8_t
Definition: zipconf.h:33
#define ZIP_IS_RDONLY(za)
Definition: zipint.h:479
zip_t * za
Definition: ziptool.c:79

References _zip_get_name(), _zip_hash_delete(), _zip_unchange(), zip_entry::deleted, zip::entry, zip::error, setup::idx, name, zip::names, zip::nentry, NULL, za, ZIP_ER_INVAL, ZIP_ER_RDONLY, zip_error_set(), and ZIP_IS_RDONLY.

Referenced by delete(), main(), and zip_dir_add().