1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/*
* Author:
* Guido Draheim <guidod@gmx.de>
* Tomi Ollila <Tomi.Ollila@iki.fi>
*
* Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim
* All rights reserved,
* use under the restrictions of the
* Lesser GNU General Public License
* or alternatively the restrictions
* of the Mozilla Public License 1.1
*/
#include <zzip/lib.h> /* exported... */
#include <zlib.h>
#include <string.h>
#include <errno.h>
#include <zzip/file.h>
/* *INDENT-OFF* */
static struct errlistentry { int code; const char* mesg; }
errlist[] =
{
{ ZZIP_NO_ERROR, "No error" },
{ ZZIP_OUTOFMEM,
"could not get temporary memory for internal structures" },
{ ZZIP_DIR_OPEN, "Failed to open zip-file %s" },
{ ZZIP_DIR_STAT, "Failed to fstat zip-file %s" },
{ ZZIP_DIR_SEEK, "Failed to lseek zip-file %s" },
{ ZZIP_DIR_READ, "Failed to read zip-file %s"},
{ ZZIP_DIR_TOO_SHORT, "zip-file %s too short" },
{ ZZIP_DIR_EDH_MISSING, "zip-file central directory not found" },
{ ZZIP_DIRSIZE, "Directory size too big..." },
{ ZZIP_ENOENT, "No such file found in zip-file %s" },
{ ZZIP_UNSUPP_COMPR, "Unsupported compression format" },
{ ZZIP_CORRUPTED, "Zipfile corrupted" },
{ ZZIP_UNDEF, "Some undefined error occurred" },
{ ZZIP_DIR_LARGEFILE, "Directory is largefile variant" },
{ 0, 0 },
};
/* *INDENT-ON* */
#define errlistSIZE (sizeof(errlist)/sizeof(*errlist))
/**
* returns the static string for the given error code. The
* error code can be either a normal system error (a
* positive error code will flag this), it can be => libz
* error code (a small negative error code will flag this)
* or it can be an error code from => libzzip, which is an
* negative value lower than => ZZIP_ERROR
*/
zzip_char_t *
zzip_strerror(int errcode)
{
if (errcode < ZZIP_ERROR && errcode > ZZIP_ERROR - 32)
{
struct errlistentry *err = errlist;
for (; err->mesg; err++)
{
if (err->code == errcode)
return err->mesg;
}
errcode = EINVAL;
}
if (errcode < 0)
{
if (errcode == -1)
return strerror(errcode);
else
return zError(errcode);
}
return strerror(errcode);
}
/** => zzip_strerror
* This function fetches the errorcode from the => DIR-handle and
* runs it through => zzip_strerror to obtain the static string
* describing the error.
*/
zzip_char_t *
zzip_strerror_of(ZZIP_DIR * dir)
{
if (! dir)
return strerror(errno);
return zzip_strerror(dir->errcode);
}
/* *INDENT-OFF* */
static struct errnolistentry { int code; int e_no; }
errnolist[] =
{
{ Z_STREAM_ERROR, EPIPE },
{ Z_DATA_ERROR, ESPIPE },
{ Z_MEM_ERROR, ENOMEM },
{ Z_BUF_ERROR, EMFILE },
{ Z_VERSION_ERROR, ENOEXEC },
{ ZZIP_DIR_OPEN, ENOTDIR },
{ ZZIP_DIR_STAT, EREMOTE },
{ ZZIP_DIR_SEEK, ESPIPE },
# ifdef ESTRPIPE
{ ZZIP_DIR_READ, ESTRPIPE},
# else
{ ZZIP_DIR_READ, EPIPE},
# endif
{ ZZIP_DIR_TOO_SHORT, ENOEXEC },
# ifdef ENOMEDIUM
{ ZZIP_DIR_EDH_MISSING, ENOMEDIUM },
# else
{ ZZIP_DIR_EDH_MISSING, EIO },
# endif
{ ZZIP_DIRSIZE, EFBIG },
{ ZZIP_OUTOFMEM, ENOMEM },
{ ZZIP_ENOENT, ENOENT },
# ifdef EPFNOSUPPORT
{ ZZIP_UNSUPP_COMPR, EPFNOSUPPORT },
# else
{ ZZIP_UNSUPP_COMPR, EACCES },
# endif
# ifdef EILSEQ
{ ZZIP_CORRUPTED, EILSEQ },
# else
{ ZZIP_CORRUPTED, ELOOP },
# endif
{ ZZIP_UNDEF, EINVAL },
{ 0, 0 },
};
/* *INDENT-ON* */
/**
* map the error code to a system error code. This is used
* for the drop-in replacement functions to return a value
* that can be interpreted correctly by code sections that
* are unaware of the fact they their => open(2) call had been
* diverted to a file inside a zip-archive.
*/
int
zzip_errno(int errcode)
{
if (errcode >= -1)
{
return errno;
} else
{
struct errnolistentry *err = errnolist;
for (; err->code; err++)
{
if (err->code == errcode)
return err->e_no;
}
return EINVAL;
}
}
/*
* Local variables:
* c-file-style: "stroustrup"
* End:
*/
|