]> git.sesse.net Git - vlc/blob - src/darwin/error.c
darwin: implement vlc_strerror and vlc_strerror_c
[vlc] / src / darwin / error.c
1 /*****************************************************************************
2  * error.c: Darwin error messages handling
3  *****************************************************************************
4  * Copyright © 2006-2013 Rémi Denis-Courmont
5  *           © 2013 Felix Paul Kühne
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation; either version 2.1 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20  *****************************************************************************/
21
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
25
26 #include <stdlib.h>
27 #include <errno.h>
28
29 #include <vlc_common.h>
30
31 typedef struct
32 {
33     int code;
34     const char *msg;
35 } darwinerrmsg_t;
36
37 static const darwinerrmsg_t darwinerrmsg[] =
38 {
39     { EPERM, "Operation not permitted" },
40     { ENOENT, "No such file or directory" },
41     { ESRCH, "No such process" },
42     { EINTR, "Interrupted system call" },
43     { EIO, "Input/output error" },
44     { ENXIO, "Device not configured" },
45     { E2BIG, "Argument list too long" },
46     { ENOEXEC, "Exec format error" },
47     { EBADF, "Bad file descriptor" },
48     { ECHILD, "No child processes" },
49     { EDEADLK, "Resource deadlock avoided" },
50     { ENOMEM, "Cannot allocate memory" },
51     { EACCES, "Permission denied" },
52     { EFAULT, "Bad address" },
53     { ENOTBLK, "Block device required" },
54     { EBUSY, "Device / Resource busy" },
55     { EEXIST, "File exists" },
56     { EXDEV, "Cross-device link" },
57     { ENODEV, "Operation not supported by device" },
58     { ENOTDIR, "Not a directory" },
59     { EISDIR, "Is a directory" },
60     { EINVAL, "Invalid argument" },
61     { ENFILE, "Too many open files in system" },
62     { EMFILE, "Too many open files" },
63     { ENOTTY, "Inappropriate ioctl for device" },
64     { ETXTBSY, "Text file busy" },
65     { EFBIG, "File too large" },
66     { ENOSPC, "No space left on device" },
67     { ESPIPE, "Illegal seek" },
68     { EROFS, "Read-only file system" },
69     { EMLINK, "Too many links" },
70     { EPIPE, "Broken pipe" },
71     { EDOM, "Numerical argument out of domain" },
72     { ERANGE, "Result too large" },
73     { EAGAIN, "Resource temporarily unavailable" },
74     { EWOULDBLOCK, "Operation would block" },
75     { EINPROGRESS, "Operation now in progress" },
76     { EALREADY, "Operation already in progress" },
77     { ENOTSOCK, "Socket operation on non-socket" },
78     { EDESTADDRREQ, "Destination address required" },
79     { EMSGSIZE, "Message too long" },
80     { EPROTOTYPE, "Protocol wrong type for socket" },
81     { ENOPROTOOPT, "Protocol not available" },
82     { EPROTONOSUPPORT, "Protocol not supported" },
83     { ESOCKTNOSUPPORT, "Socket type not supported" },
84     { ENOTSUP, "Operation not supported" },
85     { EOPNOTSUPP, "Operation not supported on socket" },
86     { EPFNOSUPPORT, "Protocol family not supported" },
87     { EAFNOSUPPORT, "Address family not supported by protocol family" },
88     { EADDRINUSE, "Address already in use" },
89     { EADDRNOTAVAIL, "Can't assign requested address" },
90     { ENETDOWN, "Network is down" },
91     { ENETUNREACH, "Network is unreachable" },
92     { ENETRESET, "Network dropped connection on reset" },
93     { ECONNABORTED, "Software caused connection abort" },
94     { ECONNRESET, "Connection reset by peer" },
95     { ENOBUFS, "No buffer space available" },
96     { EISCONN, "Socket is already connected" },
97     { ENOTCONN, "Socket is not connected" },
98     { ESHUTDOWN, "Can't send after socket shutdown" },
99     { ETOOMANYREFS, "Too many references: can't splice" },
100     { ETIMEDOUT, "Operation timed out" },
101     { ECONNREFUSED, "Connection refused" },
102     { ELOOP, "Too many levels of symbolic links" },
103     { ENAMETOOLONG, "File name too long" },
104     { EHOSTDOWN, "Host is down" },
105     { EHOSTUNREACH, "No route to host" },
106     { ENOTEMPTY, "Directory not empty" },
107     { EPROCLIM, "Too many processes" },
108     { EUSERS, "Too many users" },
109     { EDQUOT, "Disc quota exceeded" },
110     { ESTALE, "Stale NFS file handle" },
111     { EREMOTE, "Too many levels of remote in path" },
112     { EBADRPC, "RPC struct is bad" },
113     { ERPCMISMATCH, "RPC version wrong" },
114     { EPROGUNAVAIL, "RPC prog. not avail" },
115     { EPROGMISMATCH, "Program version wrong" },
116     { EPROCUNAVAIL, "Bad procedure for program" },
117     { ENOLCK, "No locks available" },
118     { ENOSYS, "Function not implemented" },
119     { EFTYPE, "Inappropriate file type or format" },
120     { EAUTH, "Authentication error" },
121     { ENEEDAUTH, "Need authenticator" },
122     { EPWROFF, "Device power is off" },
123     { EDEVERR, "Device error, e.g. paper out" },
124     { EOVERFLOW, "Value too large to be stored in data type" },
125     { EBADEXEC, "Bad executable" },
126     { EBADARCH, "Bad CPU type in executable" },
127     { ESHLIBVERS, "Shared library version mismatch" },
128     { EBADMACHO, "Malformed Macho file" },
129     { ECANCELED, "Operation canceled" },
130     { EIDRM, "Identifier removed" },
131     { ENOMSG, "No message of desired type" },
132     { EILSEQ, "Illegal byte sequence" },
133     { ENOATTR, "Attribute not found" },
134     { EBADMSG, "Bad message" },
135     { EMULTIHOP, "Reserved" },
136     { ENODATA, "No message available on STREAM" },
137     { ENOLINK, "Reserved" },
138     { ENOSR, "No STREAM resources" },
139     { ENOSTR, "Not a STREAM" },
140     { EPROTO, "Protocol error" },
141     { ETIME, "STREAM ioctl timeout" },
142     { ENOPOLICY, "No such policy registered" },
143     { ENOTRECOVERABLE, "State not recoverable" },
144     { EOWNERDEAD, "Previous owner died" },
145     { EQFULL, "Interface output queue is full" },
146     { 0, NULL }
147 };
148
149 const char *vlc_strerror_c(int errnum)
150 {
151     /* C run-time errors */
152     if ((unsigned)errnum < (unsigned)sys_nerr)
153         return sys_errlist[errnum];
154
155     /* Darwin socket errors */
156     for (const darwinerrmsg_t *e = darwinerrmsg; e->msg != NULL; e++)
157         if (e->code == errnum)
158             return e->msg;
159
160     return "Unknown error";
161 }
162
163 const char *vlc_strerror(int errnum)
164 {
165     return /*vlc_gettext*/(vlc_strerror_c(errnum));
166 }