Rizin
unix-like reverse engineering framework and cli tools
zip_error.c
Go to the documentation of this file.
1 /*
2  zip_error.c -- zip_error_t helper functions
3  Copyright (C) 1999-2021 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 #include <stdlib.h>
35 
36 #include "zipint.h"
37 
38 
39 ZIP_EXTERN int
41  return error->sys_err;
42 }
43 
44 
45 ZIP_EXTERN int
47  return error->zip_err;
48 }
49 
50 
51 ZIP_EXTERN void
53  free(err->str);
54  err->str = NULL;
55 }
56 
57 
58 ZIP_EXTERN void
60  err->zip_err = ZIP_ER_OK;
61  err->sys_err = 0;
62  err->str = NULL;
63 }
64 
65 ZIP_EXTERN void
68  error->zip_err = ze;
69  switch (zip_error_system_type(error)) {
70  case ZIP_ET_SYS:
71  case ZIP_ET_LIBZIP:
72  error->sys_err = errno;
73  break;
74 
75  default:
76  error->sys_err = 0;
77  break;
78  }
79 }
80 
81 
82 ZIP_EXTERN int
84  if (error->zip_err < 0 || error->zip_err >= _zip_err_str_count)
85  return ZIP_ET_NONE;
86 
87  return _zip_err_str[error->zip_err].type;
88 }
89 
90 
91 void
93  if (err == NULL)
94  return;
95 
96  err->zip_err = ZIP_ER_OK;
97  err->sys_err = 0;
98 }
99 
100 
101 void
103  if (dst == NULL) {
104  return;
105  }
106 
107  dst->zip_err = src->zip_err;
108  dst->sys_err = src->sys_err;
109 }
110 
111 
112 void
113 _zip_error_get(const zip_error_t *err, int *zep, int *sep) {
114  if (zep)
115  *zep = err->zip_err;
116  if (sep) {
118  *sep = err->sys_err;
119  else
120  *sep = 0;
121  }
122 }
123 
124 
125 void
126 zip_error_set(zip_error_t *err, int ze, int se) {
127  if (err) {
128  err->zip_err = ze;
129  err->sys_err = se;
130  }
131 }
132 
133 
134 void
137 }
138 
139 
142  int *e = (int *)data;
143 
144  if (length < sizeof(int) * 2) {
145  return -1;
146  }
147 
148  e[0] = zip_error_code_zip(error);
150  return sizeof(int) * 2;
151 }
#define e(frag)
lzma_index * src
Definition: index.h:567
static bool err
Definition: armass.c:435
#define NULL
Definition: cris-opc.c:27
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 static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define ZIP_EXTERN
Definition: zip.h:54
ZIP_EXTERN zip_error_t *_Nonnull zip_source_error(zip_source_t *_Nonnull)
#define ZIP_ET_NONE
Definition: zip.h:141
#define ZIP_ET_LIBZIP
Definition: zip.h:144
#define ZIP_ER_OK
Definition: zip.h:105
#define ZIP_ET_SYS
Definition: zip.h:142
char * dst
Definition: lz4.h:724
static int
Definition: sfsocketcall.h:114
Definition: zip.h:284
void error(const char *msg)
Definition: untgz.c:593
const struct _zip_err_info _zip_err_str[]
Definition: zip_err_str.c:15
const int _zip_err_str_count
Definition: zip_err_str.c:51
void _zip_error_set_from_source(zip_error_t *err, zip_source_t *src)
Definition: zip_error.c:135
ZIP_EXTERN int zip_error_system_type(const zip_error_t *error)
Definition: zip_error.c:83
ZIP_EXTERN int zip_error_code_zip(const zip_error_t *error)
Definition: zip_error.c:46
void _zip_error_get(const zip_error_t *err, int *zep, int *sep)
Definition: zip_error.c:113
void _zip_error_clear(zip_error_t *err)
Definition: zip_error.c:92
ZIP_EXTERN void zip_error_init(zip_error_t *err)
Definition: zip_error.c:59
ZIP_EXTERN void zip_error_init_with_code(zip_error_t *error, int ze)
Definition: zip_error.c:66
ZIP_EXTERN void zip_error_fini(zip_error_t *err)
Definition: zip_error.c:52
void _zip_error_copy(zip_error_t *dst, const zip_error_t *src)
Definition: zip_error.c:102
ZIP_EXTERN int zip_error_code_system(const zip_error_t *error)
Definition: zip_error.c:40
void zip_error_set(zip_error_t *err, int ze, int se)
Definition: zip_error.c:126
zip_int64_t zip_error_to_data(const zip_error_t *error, void *data, zip_uint64_t length)
Definition: zip_error.c:141
uint64_t zip_uint64_t
Definition: zipconf.h:39
int64_t zip_int64_t
Definition: zipconf.h:38