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