~ubuntu-branches/ubuntu/wily/luatex/wily

« back to all changes in this revision

Viewing changes to source/texk/web2c/luatexdir/zziplib/zzip/err.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2010-04-29 00:47:19 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100429004719-o42etkqe90n97b9e
Tags: 0.60.1-1
* new upstream release, adapt build-script patch
* disable patch: upstream-epstopdf_cc_no_xpdf_patching, included upstream
* disable patch: libpoppler-0.12, not needed anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Author: 
3
 
 *      Guido Draheim <guidod@gmx.de>
4
 
 *      Tomi Ollila <Tomi.Ollila@iki.fi>
5
 
 *
6
 
 *      Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim
7
 
 *          All rights reserved,
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
12
 
 */
13
 
 
14
 
#include <zzip/lib.h>                                    /* exported... */
15
 
#include <zlib.h>
16
 
 
17
 
#include <string.h>
18
 
#include <errno.h>
19
 
 
20
 
#include <zzip/file.h>
21
 
 
22
 
static struct errlistentry { int code; const char* mesg; } 
23
 
errlist[] = 
24
 
{
25
 
    { ZZIP_NO_ERROR,        "No error" },
26
 
    { ZZIP_OUTOFMEM,        
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" },
40
 
    { 0, 0 },
41
 
};
42
 
 
43
 
#define errlistSIZE (sizeof(errlist)/sizeof(*errlist))
44
 
 
45
 
/**
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
52
 
 */
53
 
zzip_char_t* 
54
 
zzip_strerror(int errcode)
55
 
{
56
 
  if (errcode < ZZIP_ERROR && errcode > ZZIP_ERROR-32)
57
 
  {
58
 
      struct errlistentry* err = errlist;
59
 
      for (; err->mesg ; err++)
60
 
      {
61
 
          if (err->code == errcode) 
62
 
              return err->mesg; 
63
 
      }
64
 
      errcode = EINVAL;
65
 
  }
66
 
 
67
 
  if (errcode < 0)
68
 
  {
69
 
      if (errcode == -1)
70
 
          return strerror(errcode);
71
 
      else
72
 
          return zError(errcode);
73
 
  }
74
 
  
75
 
  return strerror (errcode);
76
 
}
77
 
 
78
 
/** => zzip_strerror
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.
82
 
 */
83
 
zzip_char_t* 
84
 
zzip_strerror_of(ZZIP_DIR* dir)
85
 
{
86
 
    if (! dir) return strerror (errno);
87
 
    return zzip_strerror(dir->errcode);
88
 
}
89
 
 
90
 
static struct errnolistentry { int code; int e_no; } 
91
 
errnolist[] =
92
 
{
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 },
98
 
      
99
 
    { ZZIP_DIR_OPEN, ENOTDIR },
100
 
    { ZZIP_DIR_STAT, EREMOTE },
101
 
    { ZZIP_DIR_SEEK, ESPIPE },
102
 
#  ifdef ESTRPIPE
103
 
    { ZZIP_DIR_READ, ESTRPIPE},  
104
 
#  else
105
 
    { ZZIP_DIR_READ, EPIPE},  
106
 
#  endif
107
 
    { ZZIP_DIR_TOO_SHORT, ENOEXEC },
108
 
#  ifdef ENOMEDIUM
109
 
    { ZZIP_DIR_EDH_MISSING, ENOMEDIUM },
110
 
#  else
111
 
    { ZZIP_DIR_EDH_MISSING, EIO },
112
 
#  endif
113
 
    { ZZIP_DIRSIZE, EFBIG },
114
 
    { ZZIP_OUTOFMEM, ENOMEM },
115
 
    { ZZIP_ENOENT, ENOENT },
116
 
#  ifdef EPFNOSUPPORT
117
 
    { ZZIP_UNSUPP_COMPR, EPFNOSUPPORT },
118
 
#  else
119
 
    { ZZIP_UNSUPP_COMPR, EACCES },
120
 
#  endif 
121
 
# ifdef EILSEQ
122
 
    { ZZIP_CORRUPTED, EILSEQ }, 
123
 
# else
124
 
    { ZZIP_CORRUPTED, ELOOP }, 
125
 
# endif
126
 
    { ZZIP_UNDEF, EINVAL },
127
 
    { 0, 0 },
128
 
};    
129
 
 
130
 
/**
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.
136
 
 */
137
 
int
138
 
zzip_errno(int errcode)
139
 
{
140
 
    if (errcode >= -1) return errno;
141
 
    
142
 
    {   struct errnolistentry* err = errnolist;
143
 
        for (; err->code ; err++)
144
 
        {
145
 
            if (err->code == errcode) 
146
 
                return err->e_no; 
147
 
        }
148
 
    }
149
 
    return EINVAL;
150
 
}
151
 
 
152
 
/* 
153
 
 * Local variables:
154
 
 * c-file-style: "stroustrup"
155
 
 * End:
156
 
 */