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

Go to the source code of this file.

Functions

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

Variables

const char * teststr = "This is a test.\n"
 
const char * file = "teststring.txt"
 

Function Documentation

◆ main()

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

Definition at line 45 of file fopen_unchanged.c.

45  {
46  const char *archive;
47  zip_t *za;
48  zip_source_t *zs;
49  int err;
50 
51  if (argc != 2) {
52  fprintf(stderr, "usage: %s archive\n", argv[0]);
53  return 1;
54  }
55 
56  archive = argv[1];
57 
58  if ((za = zip_open(archive, ZIP_CREATE, &err)) == NULL) {
61  fprintf(stderr, "can't open zip archive '%s': %s\n", archive, zip_error_strerror(&error));
63  return 1;
64  }
65 
66  if ((zs = zip_source_buffer(za, teststr, strlen(teststr), 0)) == NULL) {
67  fprintf(stderr, "can't create zip_source from buffer: %s\n", zip_strerror(za));
68  exit(1);
69  }
70 
71  if (zip_add(za, file, zs) == -1) {
72  fprintf(stderr, "can't add file '%s': %s\n", file, zip_strerror(za));
73  (void)zip_source_free(zs);
74  (void)zip_close(za);
75  return 1;
76  }
77 
79  fprintf(stderr, "can't zip_fopen file '%s': %s\n", file, zip_strerror(za));
80  (void)zip_discard(za);
81  return 1;
82  }
83 
84  if (zip_close(za) == -1) {
85  fprintf(stderr, "can't close zip archive '%s': %s\n", archive, zip_strerror(za));
86  return 1;
87  }
88 
89  return 0;
90 }
static bool err
Definition: armass.c:435
#define NULL
Definition: cris-opc.c:27
const char * teststr
ZIP_EXTERN void zip_error_init_with_code(zip_error_t *_Nonnull, int)
Definition: zip_error.c:66
ZIP_EXTERN zip_file_t *_Nullable zip_fopen(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t)
Definition: zip_fopen.c:39
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 void zip_discard(zip_t *_Nonnull)
Definition: zip_discard.c:45
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)
#define ZIP_FL_UNCHANGED
Definition: zip.h:79
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer(zip_t *_Nonnull, const void *_Nullable, zip_uint64_t, int)
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
Definition: zipcmp.c:60
Definition: gzappend.c:170
Definition: zip.h:284
Definition: zipint.h:278
void error(const char *msg)
Definition: untgz.c:593
zip_t * za
Definition: ziptool.c:79

References argv, err, error(), test-lz4-list::exit, NULL, teststr, za, zip_add(), zip_close(), ZIP_CREATE, zip_discard(), zip_error_fini(), zip_error_init_with_code(), zip_error_strerror(), ZIP_FL_UNCHANGED, zip_fopen(), zip_open(), zip_source_buffer(), zip_source_free(), and zip_strerror().

Variable Documentation

◆ file

const char* file = "teststring.txt"

Definition at line 42 of file fopen_unchanged.c.

◆ teststr

const char* teststr = "This is a test.\n"

Definition at line 41 of file fopen_unchanged.c.

Referenced by main().