3
* Guido Draheim <guidod@gmx.de>
4
* Tomi Ollila <Tomi.Ollila@iki.fi>
6
* Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim
8
* use under the restrictions of the
9
* Lesser GNU General Public License
10
* or alternatively the restrictions
11
* of the Mozilla Public License 1.1
14
#include <zzip/lib.h> /* exported... */
20
#include <zzip/file.h>
22
static struct errlistentry { int code; const char* mesg; }
25
{ ZZIP_NO_ERROR, "No error" },
27
"could not get temporary memory for internal structures" },
28
{ ZZIP_DIR_OPEN, "Failed to open zip-file %s" },
29
{ ZZIP_DIR_STAT, "Failed to fstat zip-file %s" },
30
{ ZZIP_DIR_SEEK, "Failed to lseek zip-file %s" },
31
{ ZZIP_DIR_READ, "Failed to read zip-file %s"},
32
{ ZZIP_DIR_TOO_SHORT, "zip-file %s too short" },
33
{ ZZIP_DIR_EDH_MISSING, "zip-file central directory not found" },
34
{ ZZIP_DIRSIZE, "Directory size too big..." },
35
{ ZZIP_ENOENT, "No such file found in zip-file %s" },
36
{ ZZIP_UNSUPP_COMPR, "Unsupported compression format" },
37
{ ZZIP_CORRUPTED, "Zipfile corrupted" },
38
{ ZZIP_UNDEF, "Some undefined error occurred" },
39
{ ZZIP_DIR_LARGEFILE, "Directory is largefile variant" },
43
#define errlistSIZE (sizeof(errlist)/sizeof(*errlist))
46
* returns the static string for the given error code. The
47
* error code can be either a normal system error (a
48
* positive error code will flag this), it can be => libz
49
* error code (a small negative error code will flag this)
50
* or it can be an error code from => libzzip, which is an
51
* negative value lower than => ZZIP_ERROR
54
zzip_strerror(int errcode)
56
if (errcode < ZZIP_ERROR && errcode > ZZIP_ERROR-32)
58
struct errlistentry* err = errlist;
59
for (; err->mesg ; err++)
61
if (err->code == errcode)
70
return strerror(errcode);
72
return zError(errcode);
75
return strerror (errcode);
79
* This function fetches the errorcode from the => DIR-handle and
80
* runs it through => zzip_strerror to obtain the static string
81
* describing the error.
84
zzip_strerror_of(ZZIP_DIR* dir)
86
if (! dir) return strerror (errno);
87
return zzip_strerror(dir->errcode);
90
static struct errnolistentry { int code; int e_no; }
93
{ Z_STREAM_ERROR, EPIPE },
94
{ Z_DATA_ERROR, ESPIPE },
95
{ Z_MEM_ERROR, ENOMEM },
96
{ Z_BUF_ERROR, EMFILE },
97
{ Z_VERSION_ERROR, ENOEXEC },
99
{ ZZIP_DIR_OPEN, ENOTDIR },
100
{ ZZIP_DIR_STAT, EREMOTE },
101
{ ZZIP_DIR_SEEK, ESPIPE },
103
{ ZZIP_DIR_READ, ESTRPIPE},
105
{ ZZIP_DIR_READ, EPIPE},
107
{ ZZIP_DIR_TOO_SHORT, ENOEXEC },
109
{ ZZIP_DIR_EDH_MISSING, ENOMEDIUM },
111
{ ZZIP_DIR_EDH_MISSING, EIO },
113
{ ZZIP_DIRSIZE, EFBIG },
114
{ ZZIP_OUTOFMEM, ENOMEM },
115
{ ZZIP_ENOENT, ENOENT },
117
{ ZZIP_UNSUPP_COMPR, EPFNOSUPPORT },
119
{ ZZIP_UNSUPP_COMPR, EACCES },
122
{ ZZIP_CORRUPTED, EILSEQ },
124
{ ZZIP_CORRUPTED, ELOOP },
126
{ ZZIP_UNDEF, EINVAL },
131
* map the error code to a system error code. This is used
132
* for the drop-in replacement functions to return a value
133
* that can be interpreted correctly by code sections that
134
* are unaware of the fact they their => open(2) call had been
135
* diverted to a file inside a zip-archive.
138
zzip_errno(int errcode)
140
if (errcode >= -1) return errno;
142
{ struct errnolistentry* err = errnolist;
143
for (; err->code ; err++)
145
if (err->code == errcode)
154
* c-file-style: "stroustrup"