beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / zzip / err.c
blob1ba869bd9afc45f80358051f218dd32e6999766f
2 /*
3 * Author:
4 * Guido Draheim <guidod@gmx.de>
5 * Tomi Ollila <Tomi.Ollila@iki.fi>
7 * Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim
8 * All rights reserved,
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... */
16 #include <zlib.h>
18 #include <string.h>
19 #include <errno.h>
21 #include <zzip/file.h>
23 /* *INDENT-OFF* */
24 static struct errlistentry { int code; const char* mesg; }
25 errlist[] =
27 { ZZIP_NO_ERROR, "No error" },
28 { ZZIP_OUTOFMEM,
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" },
42 { 0, 0 },
44 /* *INDENT-ON* */
47 #define errlistSIZE (sizeof(errlist)/sizeof(*errlist))
49 /**
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
57 zzip_char_t *
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)
67 return err->mesg;
69 errcode = EINVAL;
72 if (errcode < 0)
74 if (errcode == -1)
75 return strerror(errcode);
76 else
77 return zError(errcode);
80 return strerror(errcode);
83 /** => zzip_strerror
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.
88 zzip_char_t *
89 zzip_strerror_of(ZZIP_DIR * dir)
91 if (! dir)
92 return strerror(errno);
93 return zzip_strerror(dir->errcode);
96 /* *INDENT-OFF* */
97 static struct errnolistentry { int code; int e_no; }
98 errnolist[] =
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 },
109 # ifdef ESTRPIPE
110 { ZZIP_DIR_READ, ESTRPIPE},
111 # else
112 { ZZIP_DIR_READ, EPIPE},
113 # endif
114 { ZZIP_DIR_TOO_SHORT, ENOEXEC },
115 # ifdef ENOMEDIUM
116 { ZZIP_DIR_EDH_MISSING, ENOMEDIUM },
117 # else
118 { ZZIP_DIR_EDH_MISSING, EIO },
119 # endif
120 { ZZIP_DIRSIZE, EFBIG },
121 { ZZIP_OUTOFMEM, ENOMEM },
122 { ZZIP_ENOENT, ENOENT },
123 # ifdef EPFNOSUPPORT
124 { ZZIP_UNSUPP_COMPR, EPFNOSUPPORT },
125 # else
126 { ZZIP_UNSUPP_COMPR, EACCES },
127 # endif
128 # ifdef EILSEQ
129 { ZZIP_CORRUPTED, EILSEQ },
130 # else
131 { ZZIP_CORRUPTED, ELOOP },
132 # endif
133 { ZZIP_UNDEF, EINVAL },
134 { 0, 0 },
136 /* *INDENT-ON* */
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)
148 if (errcode >= -1)
150 return errno;
151 } else
153 struct errnolistentry *err = errnolist;
155 for (; err->code; err++)
157 if (err->code == errcode)
158 return err->e_no;
160 return EINVAL;
165 * Local variables:
166 * c-file-style: "stroustrup"
167 * End: