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

Go to the source code of this file.

Functions

ZIP_EXTERN zip_int64_t zip_name_locate (zip_t *za, const char *fname, zip_flags_t flags)
 
zip_int64_t _zip_name_locate (zip_t *za, const char *fname, zip_flags_t flags, zip_error_t *error)
 

Function Documentation

◆ _zip_name_locate()

zip_int64_t _zip_name_locate ( zip_t za,
const char *  fname,
zip_flags_t  flags,
zip_error_t error 
)

Definition at line 50 of file zip_name_locate.c.

50  {
51  int (*cmp)(const char *, const char *);
53  const char *fn, *p;
55 
56  if (za == NULL)
57  return -1;
58 
59  if (fname == NULL) {
61  return -1;
62  }
63 
64  if ((flags & (ZIP_FL_ENC_UTF_8 | ZIP_FL_ENC_RAW)) == 0 && fname[0] != '\0') {
65  if ((str = _zip_string_new((const zip_uint8_t *)fname, strlen(fname), flags, error)) == NULL) {
66  return -1;
67  }
68  if ((fname = (const char *)_zip_string_get(str, NULL, 0, error)) == NULL) {
70  return -1;
71  }
72  }
73 
75  /* can't use hash table */
76  cmp = (flags & ZIP_FL_NOCASE) ? strcasecmp : strcmp;
77 
78  for (i = 0; i < za->nentry; i++) {
80 
81  /* newly added (partially filled) entry or error */
82  if (fn == NULL)
83  continue;
84 
85  if (flags & ZIP_FL_NODIR) {
86  p = strrchr(fn, '/');
87  if (p)
88  fn = p + 1;
89  }
90 
91  if (cmp(fname, fn) == 0) {
94  return (zip_int64_t)i;
95  }
96  }
97 
100  return -1;
101  }
102  else {
105  return ret;
106  }
107 }
lzma_index ** i
Definition: index.h:629
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:942
#define NULL
Definition: cris-opc.c:27
void * p
Definition: libc.cpp:67
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
Definition: zip_error.c:126
#define ZIP_FL_NODIR
Definition: zip.h:77
#define ZIP_ER_NOENT
Definition: zip.h:114
#define ZIP_FL_ENC_STRICT
Definition: zip.h:84
#define ZIP_ER_INVAL
Definition: zip.h:123
#define ZIP_FL_ENC_RAW
Definition: zip.h:83
#define ZIP_FL_ENC_UTF_8
Definition: zip.h:88
#define ZIP_FL_NOCASE
Definition: zip.h:76
static const char struct stat static buf struct stat static buf static idle const char static path static fd const char static len const void static prot const char struct module static image struct kernel_sym static table unsigned char static buf static fsuid unsigned struct dirent unsigned static count const struct iovec static count static pid const void static len static flags const struct sched_param static p static pid static policy struct timespec static tp static suid unsigned fn
Definition: sflib.h:186
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
static int
Definition: sfsocketcall.h:114
zip_uint64_t nentry
Definition: zipint.h:292
zip_hash_t * names
Definition: zipint.h:300
void error(const char *msg)
Definition: untgz.c:593
void _zip_error_clear(zip_error_t *err)
Definition: zip_error.c:92
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
zip_int64_t _zip_hash_lookup(zip_hash_t *hash, const zip_uint8_t *name, zip_flags_t flags, zip_error_t *error)
Definition: zip_hash.c:312
zip_string_t * _zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags, zip_error_t *error)
Definition: zip_string.c:121
void _zip_string_free(zip_string_t *s)
Definition: zip_string.c:69
const zip_uint8_t * _zip_string_get(zip_string_t *string, zip_uint32_t *lenp, zip_flags_t flags, zip_error_t *error)
Definition: zip_string.c:80
uint64_t zip_uint64_t
Definition: zipconf.h:39
uint8_t zip_uint8_t
Definition: zipconf.h:33
int64_t zip_int64_t
Definition: zipconf.h:38
zip_t * za
Definition: ziptool.c:79

References _zip_error_clear(), _zip_get_name(), _zip_hash_lookup(), _zip_string_free(), _zip_string_get(), _zip_string_new(), cmp(), error(), flags, fn, create_tags_rz::fname, i, int, zip::names, zip::nentry, NULL, p, cmd_descs_generate::str, za, ZIP_ER_INVAL, ZIP_ER_NOENT, zip_error_set(), ZIP_FL_ENC_RAW, ZIP_FL_ENC_STRICT, ZIP_FL_ENC_UTF_8, ZIP_FL_NOCASE, and ZIP_FL_NODIR.

Referenced by _zip_file_replace(), _zip_set_name(), _zip_unchange(), and zip_name_locate().

◆ zip_name_locate()

ZIP_EXTERN zip_int64_t zip_name_locate ( zip_t za,
const char *  fname,
zip_flags_t  flags 
)

Definition at line 44 of file zip_name_locate.c.

44  {
45  return _zip_name_locate(za, fname, flags, &za->error);
46 }
zip_error_t error
Definition: zipint.h:281
zip_int64_t _zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags, zip_error_t *error)

References _zip_name_locate(), zip::error, flags, create_tags_rz::fname, and za.

Referenced by main(), merge_zip(), name_locate(), rz_io_zip_flush_file(), zip_fopen(), zip_fopen_encrypted(), and zip_stat().