Rizin
unix-like reverse engineering framework and cli tools
zip_stat_index.c
Go to the documentation of this file.
1 /*
2  zip_stat_index.c -- get information about file by index
3  Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner
4 
5  This file is part of libzip, a library to manipulate ZIP archives.
6  The authors can be contacted at <info@libzip.org>
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions
10  are met:
11  1. Redistributions of source code must retain the above copyright
12  notice, this list of conditions and the following disclaimer.
13  2. Redistributions in binary form must reproduce the above copyright
14  notice, this list of conditions and the following disclaimer in
15  the documentation and/or other materials provided with the
16  distribution.
17  3. The names of the authors may not be used to endorse or promote
18  products derived from this software without specific prior
19  written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
22  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
25  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
31  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
34 
35 #include "zipint.h"
36 
37 
38 ZIP_EXTERN int
40  const char *name;
41  zip_dirent_t *de;
42 
43  if ((de = _zip_get_dirent(za, index, flags, NULL)) == NULL)
44  return -1;
45 
46  if ((name = zip_get_name(za, index, flags)) == NULL)
47  return -1;
48 
49 
50  if ((flags & ZIP_FL_UNCHANGED) == 0 && ZIP_ENTRY_DATA_CHANGED(za->entry + index)) {
51  zip_entry_t *entry = za->entry + index;
52 
53  if (zip_source_stat(entry->source, st) < 0) {
55  return -1;
56  }
57 
58  if (entry->changes != NULL && entry->changes->changed & ZIP_DIRENT_LAST_MOD) {
59  st->mtime = de->last_mod;
60  st->valid |= ZIP_STAT_MTIME;
61  }
62  }
63  else {
64  zip_stat_init(st);
65 
66  st->crc = de->crc;
67  st->size = de->uncomp_size;
68  st->mtime = de->last_mod;
69  st->comp_size = de->comp_size;
73  }
74 
75  st->index = index;
76  st->name = name;
78 
79  return 0;
80 }
#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_STAT_NAME
Definition: zip.h:290
#define ZIP_ER_CHANGED
Definition: zip.h:120
#define ZIP_STAT_SIZE
Definition: zip.h:292
#define ZIP_STAT_COMP_METHOD
Definition: zip.h:296
ZIP_EXTERN void zip_stat_init(zip_stat_t *_Nonnull)
Definition: zip_stat_init.c:40
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_EXTERN
Definition: zip.h:54
ZIP_EXTERN int zip_source_stat(zip_source_t *_Nonnull, zip_stat_t *_Nonnull)
#define ZIP_STAT_ENCRYPTION_METHOD
Definition: zip.h:297
#define ZIP_STAT_COMP_SIZE
Definition: zip.h:293
#define ZIP_STAT_MTIME
Definition: zip.h:294
#define ZIP_STAT_INDEX
Definition: zip.h:291
zip_uint32_t zip_flags_t
Definition: zip.h:347
#define ZIP_FL_UNCHANGED
Definition: zip.h:79
#define ZIP_STAT_CRC
Definition: zip.h:295
const char * name
Definition: op.c:541
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
Definition: zipcmp.c:77
Definition: z80asm.h:102
time_t last_mod
Definition: zipint.h:337
zip_uint64_t uncomp_size
Definition: zipint.h:340
zip_uint32_t crc
Definition: zipint.h:338
zip_int32_t comp_method
Definition: zipint.h:336
zip_uint64_t comp_size
Definition: zipint.h:339
zip_uint16_t encryption_method
Definition: zipint.h:350
bool crc_valid
Definition: zipint.h:331
Definition: zipint.h:408
Definition: zip.h:300
time_t mtime
Definition: zip.h:306
zip_uint16_t encryption_method
Definition: zip.h:309
zip_uint64_t index
Definition: zip.h:303
const char *_Nullable name
Definition: zip.h:302
zip_uint64_t valid
Definition: zip.h:301
zip_uint16_t comp_method
Definition: zip.h:308
zip_uint64_t comp_size
Definition: zip.h:305
zip_uint32_t crc
Definition: zip.h:307
zip_uint64_t size
Definition: zip.h:304
Definition: zipint.h:278
zip_error_t error
Definition: zipint.h:281
zip_entry_t * entry
Definition: zipint.h:294
zip_dirent_t * _zip_get_dirent(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *error)
Definition: zip_dirent.c:1064
ZIP_EXTERN int zip_stat_index(zip_t *za, zip_uint64_t index, zip_flags_t flags, zip_stat_t *st)
uint64_t zip_uint64_t
Definition: zipconf.h:39
uint16_t zip_uint16_t
Definition: zipconf.h:35
#define ZIP_ENTRY_DATA_CHANGED(x)
Definition: zipint.h:476
#define ZIP_DIRENT_LAST_MOD
Definition: zipint.h:321
zip_t * za
Definition: ziptool.c:79