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

Go to the source code of this file.

Functions

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

Variables

static const char * prg
 

Function Documentation

◆ main()

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

Definition at line 44 of file add_from_filep.c.

44  {
45  const char *archive;
46  const char *file;
47  const char *name;
48  zip_t *za;
49  zip_source_t *zs;
50  int err;
51  FILE *fp;
52 
53  prg = argv[0];
54 
55  if (argc != 3) {
56  fprintf(stderr, "usage: %s archive file\n", prg);
57  return 1;
58  }
59 
60  archive = argv[1];
61  file = argv[2];
62 
63  if ((za = zip_open(archive, ZIP_CREATE, &err)) == NULL) {
66  fprintf(stderr, "%s: can't open zip archive '%s': %s\n", prg, archive, zip_error_strerror(&error));
68  return 1;
69  }
70 
71  if ((fp = fopen(file, "rb")) == NULL) {
72  fprintf(stderr, "%s: can't open input file '%s': %s\n", prg, file, strerror(errno));
73  return 1;
74  }
75 
76  if ((zs = zip_source_filep(za, fp, 0, -1)) == NULL) {
77  fprintf(stderr, "%s: error creating file source for '%s': %s\n", prg, file, zip_strerror(za));
78  return 1;
79  }
80 
81  if ((name = strrchr(file, '/')) == NULL)
82  name = file;
83 
84  if (zip_add(za, name, zs) == -1) {
85  zip_source_free(zs);
86  fprintf(stderr, "%s: can't add file '%s': %s\n", prg, file, zip_strerror(za));
87  return 1;
88  }
89 
90  if (zip_close(za) == -1) {
91  fprintf(stderr, "%s: can't close zip archive '%s': %s\n", prg, archive, zip_strerror(za));
92  return 1;
93  }
94 
95  return 0;
96 }
static const char * prg
static bool err
Definition: armass.c:435
#define NULL
Definition: cris-opc.c:27
ZIP_EXTERN void zip_error_init_with_code(zip_error_t *_Nonnull, int)
Definition: zip_error.c:66
ZIP_EXTERN zip_source_t *_Nullable zip_source_filep(zip_t *_Nonnull, FILE *_Nonnull, zip_uint64_t, zip_int64_t)
ZIP_EXTERN zip_int64_t zip_add(zip_t *_Nonnull, const char *_Nonnull, zip_source_t *_Nonnull)
Definition: zip_add.c:47
#define ZIP_CREATE
Definition: zip.h:67
ZIP_EXTERN int zip_close(zip_t *_Nonnull)
Definition: zip_close.c:52
ZIP_EXTERN void zip_error_fini(zip_error_t *_Nonnull)
Definition: zip_error.c:52
ZIP_EXTERN void zip_source_free(zip_source_t *_Nullable)
ZIP_EXTERN zip_t *_Nullable zip_open(const char *_Nonnull, int, int *_Nullable)
Definition: zip_open.c:54
ZIP_EXTERN const char *_Nonnull zip_error_strerror(zip_error_t *_Nonnull)
ZIP_EXTERN const char *_Nonnull zip_strerror(zip_t *_Nonnull)
Definition: zip_strerror.c:39
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
string FILE
Definition: benchmark.py:21
const char * name
Definition: op.c:541
Definition: zipcmp.c:60
Definition: gzappend.c:170
Definition: z80asm.h:102
Definition: zip.h:284
Definition: zipint.h:278
void error(const char *msg)
Definition: untgz.c:593
static int file
Definition: z80asm.c:58
zip_t * za
Definition: ziptool.c:79

References argv, err, error(), file, benchmark::FILE, name, NULL, prg, za, zip_add(), zip_close(), ZIP_CREATE, zip_error_fini(), zip_error_init_with_code(), zip_error_strerror(), zip_open(), zip_source_filep(), zip_source_free(), and zip_strerror().

Variable Documentation

◆ prg

const char* prg
static

Definition at line 41 of file add_from_filep.c.

Referenced by main().