Rizin
unix-like reverse engineering framework and cli tools
tryopen.c File Reference
#include "config.h"
#include <errno.h>
#include <stdio.h>
#include "getopt.h"
#include "zip.h"

Go to the source code of this file.

Macros

#define TRYOPEN_USAGE
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ TRYOPEN_USAGE

#define TRYOPEN_USAGE
Value:
"usage: %s [-cent] file\n\n" \
"\t-c\tcheck consistency\n" \
"\t-e\texclusively open archive\n" \
"\t-n\tcreate new file\n" \
"\t-t\ttruncate file to size 0\n"

Definition at line 44 of file tryopen.c.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 53 of file tryopen.c.

53  {
54  const char *fname;
55  zip_t *z;
56  int c, flags, ze;
58  int error;
59 
60  flags = 0;
61 
62  while ((c = getopt(argc, argv, "cent")) != -1) {
63  switch (c) {
64  case 'c':
66  break;
67  case 'e':
68  flags |= ZIP_EXCL;
69  break;
70  case 'n':
71  flags |= ZIP_CREATE;
72  break;
73  case 't':
75  break;
76 
77  default:
78  fprintf(stderr, TRYOPEN_USAGE, argv[0]);
79  return 1;
80  }
81  }
82 
83  error = 0;
84  for (; optind < argc; optind++) {
85  fname = argv[optind];
86  errno = 0;
87 
88  if ((z = zip_open(fname, flags, &ze)) != NULL) {
89  count = zip_get_num_entries(z, 0);
90  printf("opening '%s' succeeded, %" PRIu64 " entries\n", fname, count);
91  zip_close(z);
92  continue;
93  }
94 
95  printf("opening '%s' returned error %d", fname, ze);
96  switch (zip_error_get_sys_type(ze)) {
97  case ZIP_ET_SYS:
98  case ZIP_ET_LIBZIP:
99  printf("/%d", errno);
100  break;
101 
102  default:
103  break;
104  }
105  printf("\n");
106  error++;
107  }
108 
109  if (error > 0)
110  fprintf(stderr, "%d errors\n", error);
111 
112  return error ? 1 : 0;
113 }
int getopt(int nargc, char *const nargv[], const char *ostr)
Definition: getopt.h:20
int optind
Definition: getopt.h:6
#define NULL
Definition: cris-opc.c:27
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
#define PRIu64
Definition: macros.h:18
ZIP_EXTERN int zip_error_get_sys_type(int)
#define ZIP_EXCL
Definition: zip.h:68
#define ZIP_CHECKCONS
Definition: zip.h:69
#define ZIP_CREATE
Definition: zip.h:67
#define ZIP_ET_LIBZIP
Definition: zip.h:144
ZIP_EXTERN int zip_close(zip_t *_Nonnull)
Definition: zip_close.c:52
#define ZIP_ET_SYS
Definition: zip.h:142
#define ZIP_TRUNCATE
Definition: zip.h:70
ZIP_EXTERN zip_t *_Nullable zip_open(const char *_Nonnull, int, int *_Nullable)
Definition: zip_open.c:54
ZIP_EXTERN zip_int64_t zip_get_num_entries(zip_t *_Nonnull, zip_flags_t)
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
#define c(i)
Definition: sha256.c:43
Definition: zipint.h:278
#define TRYOPEN_USAGE
Definition: tryopen.c:44
void error(const char *msg)
Definition: untgz.c:593
int64_t zip_int64_t
Definition: zipconf.h:38

References argv, c, count, error(), flags, create_tags_rz::fname, getopt(), NULL, optind, printf(), PRIu64, TRYOPEN_USAGE, ZIP_CHECKCONS, zip_close(), ZIP_CREATE, zip_error_get_sys_type(), ZIP_ET_LIBZIP, ZIP_ET_SYS, ZIP_EXCL, zip_get_num_entries(), zip_open(), and ZIP_TRUNCATE.