4 * Guido Draheim <guidod@gmx.de>
5 * Tomi Ollila <Tomi.Ollila@iki.fi>
7 * Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim
9 * use under the restrictions of the
10 * Lesser GNU General Public License
11 * or alternatively the restrictions
12 * of the Mozilla Public License 1.1
15 #include <zzip/lib.h> /* exported... */
21 #include <zzip/file.h>
24 static struct errlistentry
{ int code
; const char* mesg
; }
27 { ZZIP_NO_ERROR
, "No error" },
29 "could not get temporary memory for internal structures" },
30 { ZZIP_DIR_OPEN
, "Failed to open zip-file %s" },
31 { ZZIP_DIR_STAT
, "Failed to fstat zip-file %s" },
32 { ZZIP_DIR_SEEK
, "Failed to lseek zip-file %s" },
33 { ZZIP_DIR_READ
, "Failed to read zip-file %s"},
34 { ZZIP_DIR_TOO_SHORT
, "zip-file %s too short" },
35 { ZZIP_DIR_EDH_MISSING
, "zip-file central directory not found" },
36 { ZZIP_DIRSIZE
, "Directory size too big..." },
37 { ZZIP_ENOENT
, "No such file found in zip-file %s" },
38 { ZZIP_UNSUPP_COMPR
, "Unsupported compression format" },
39 { ZZIP_CORRUPTED
, "Zipfile corrupted" },
40 { ZZIP_UNDEF
, "Some undefined error occurred" },
41 { ZZIP_DIR_LARGEFILE
, "Directory is largefile variant" },
47 #define errlistSIZE (sizeof(errlist)/sizeof(*errlist))
50 * returns the static string for the given error code. The
51 * error code can be either a normal system error (a
52 * positive error code will flag this), it can be => libz
53 * error code (a small negative error code will flag this)
54 * or it can be an error code from => libzzip, which is an
55 * negative value lower than => ZZIP_ERROR
58 zzip_strerror(int errcode
)
60 if (errcode
< ZZIP_ERROR
&& errcode
> ZZIP_ERROR
- 32)
62 struct errlistentry
*err
= errlist
;
64 for (; err
->mesg
; err
++)
66 if (err
->code
== errcode
)
75 return strerror(errcode
);
77 return zError(errcode
);
80 return strerror(errcode
);
84 * This function fetches the errorcode from the => DIR-handle and
85 * runs it through => zzip_strerror to obtain the static string
86 * describing the error.
89 zzip_strerror_of(ZZIP_DIR
* dir
)
92 return strerror(errno
);
93 return zzip_strerror(dir
->errcode
);
97 static struct errnolistentry
{ int code
; int e_no
; }
100 { Z_STREAM_ERROR
, EPIPE
},
101 { Z_DATA_ERROR
, ESPIPE
},
102 { Z_MEM_ERROR
, ENOMEM
},
103 { Z_BUF_ERROR
, EMFILE
},
104 { Z_VERSION_ERROR
, ENOEXEC
},
106 { ZZIP_DIR_OPEN
, ENOTDIR
},
107 { ZZIP_DIR_STAT
, EREMOTE
},
108 { ZZIP_DIR_SEEK
, ESPIPE
},
110 { ZZIP_DIR_READ
, ESTRPIPE
},
112 { ZZIP_DIR_READ
, EPIPE
},
114 { ZZIP_DIR_TOO_SHORT
, ENOEXEC
},
116 { ZZIP_DIR_EDH_MISSING
, ENOMEDIUM
},
118 { ZZIP_DIR_EDH_MISSING
, EIO
},
120 { ZZIP_DIRSIZE
, EFBIG
},
121 { ZZIP_OUTOFMEM
, ENOMEM
},
122 { ZZIP_ENOENT
, ENOENT
},
124 { ZZIP_UNSUPP_COMPR
, EPFNOSUPPORT
},
126 { ZZIP_UNSUPP_COMPR
, EACCES
},
129 { ZZIP_CORRUPTED
, EILSEQ
},
131 { ZZIP_CORRUPTED
, ELOOP
},
133 { ZZIP_UNDEF
, EINVAL
},
139 * map the error code to a system error code. This is used
140 * for the drop-in replacement functions to return a value
141 * that can be interpreted correctly by code sections that
142 * are unaware of the fact they their => open(2) call had been
143 * diverted to a file inside a zip-archive.
146 zzip_errno(int errcode
)
153 struct errnolistentry
*err
= errnolist
;
155 for (; err
->code
; err
++)
157 if (err
->code
== errcode
)
166 * c-file-style: "stroustrup"