Lely core libraries  2.3.4
errnum.h
Go to the documentation of this file.
1 
56 #ifndef LELY_UTIL_ERRNUM_H_
57 #define LELY_UTIL_ERRNUM_H_
58 
59 #include <lely/features.h>
60 
61 #if !LELY_NO_ERRNO
62 #include <errno.h>
63 #endif
64 #include <stddef.h>
65 
66 #if _WIN32
67 #include <winerror.h>
68 #elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
69 #include <netdb.h>
70 #endif
71 
72 #ifndef LELY_UTIL_ERRNUM_INLINE
73 #define LELY_UTIL_ERRNUM_INLINE static inline
74 #endif
75 
77 enum errnum {
114  // Reserved by POSIX: EDQUOT
147  // Reserved by POSIX: EMULTIHOP
170  // Reserved by POSIX: ENOLINK
225  // Reserved by POSIX: ESTALE
260 };
261 
263 #ifdef __cplusplus
264 typedef int errnum_t;
265 #else
266 typedef enum errnum errnum_t;
267 #endif
268 
269 #ifdef __cplusplus
270 extern "C" {
271 #endif
272 
280 int errno2c(int errnum);
281 
288 
296 int errc2no(int errc);
297 
303 errnum_t errc2num(int errc);
304 
311 
318 
328 int get_errc(void);
329 
337 void set_errc(int errc);
338 
346 LELY_UTIL_ERRNUM_INLINE errnum_t get_errnum(void);
347 
354 LELY_UTIL_ERRNUM_INLINE void set_errnum(errnum_t errnum);
355 
363 LELY_UTIL_ERRNUM_INLINE const char *errno2str(int errnum);
364 
379 const char *errno2str_r(int errnum, char *strerrbuf, size_t buflen);
380 
382 LELY_UTIL_ERRNUM_INLINE const char *errc2str(int errc);
383 
398 const char *errc2str_r(int errc, char *strerrbuf, size_t buflen);
399 
406 LELY_UTIL_ERRNUM_INLINE const char *errnum2str(errnum_t errnum);
407 
414 LELY_UTIL_ERRNUM_INLINE const char *errnum2str_r(
415  errnum_t errnum, char *strerrbuf, size_t buflen);
416 
417 LELY_UTIL_ERRNUM_INLINE errnum_t
419 {
420  return errc2num(get_errc());
421 }
422 
423 LELY_UTIL_ERRNUM_INLINE void
425 {
427 }
428 
429 LELY_UTIL_ERRNUM_INLINE const char *
431 {
432  return errno2str_r(errnum, NULL, 0);
433 }
434 
435 LELY_UTIL_ERRNUM_INLINE const char *
436 errc2str(int errc)
437 {
438  return errc2str_r(errc, NULL, 0);
439 }
440 
441 LELY_UTIL_ERRNUM_INLINE const char *
443 {
444  return errc2str(errnum2c(errnum));
445 }
446 
447 LELY_UTIL_ERRNUM_INLINE const char *
448 errnum2str_r(errnum_t errnum, char *strerrbuf, size_t buflen)
449 {
450  return errc2str_r(errnum2c(errnum), strerrbuf, buflen);
451 }
452 
453 #ifdef __cplusplus
454 }
455 #endif
456 
457 #endif // !LELY_UTIL_ERRNUM_H_
errnum_t errno2num(int errnum)
Transforms a standard C error number to a platform-independent error number.
Definition: errnum.c:56
errnum_t errc2num(int errc)
Transforms a native error code to a platform-independent error number.
Definition: errnum.c:309
const char * errc2str_r(int errc, char *strerrbuf, size_t buflen)
Returns a string describing a native error code.
Definition: errnum.c:988
int errnum2c(errnum_t errnum)
Transforms a platform-independent error number to a native error code.
Definition: errnum.c:810
const char * errnum2str(errnum_t errnum)
Returns a string describing a platform-independent error number.
Definition: errnum.h:442
const char * errno2str_r(int errnum, char *strerrbuf, size_t buflen)
Returns a string describing a standard C error number.
Definition: errnum.c:956
errnum
The platform-independent error numbers.
Definition: errnum.h:77
@ ERRNUM_NOSPC
No space left on device.
Definition: errnum.h:178
@ ERRNUM_AI_MEMORY
There was a memory allocation failure.
Definition: errnum.h:251
@ ERRNUM_NOSYS
Function not supported.
Definition: errnum.h:184
@ ERRNUM_WOULDBLOCK
Operation would block.
Definition: errnum.h:233
@ ERRNUM_OWNERDEAD
Previous owner died.
Definition: errnum.h:206
@ ERRNUM_PROTO
Protocol error.
Definition: errnum.h:212
@ ERRNUM_BADMSG
Bad message.
Definition: errnum.h:95
@ ERRNUM_AFNOSUPPORT
Address family not supported.
Definition: errnum.h:87
@ ERRNUM_NOTCONN
The socket is not connected.
Definition: errnum.h:186
@ ERRNUM_NXIO
No such device or address.
Definition: errnum.h:200
@ ERRNUM_IDRM
Identifier removed.
Definition: errnum.h:124
@ ERRNUM_AI_BADFLAGS
The flags had an invalid value.
Definition: errnum.h:242
@ ERRNUM_RANGE
Result too large.
Definition: errnum.h:218
@ ERRNUM_MSGSIZE
Message too large.
Definition: errnum.h:146
@ ERRNUM_INTR
Interrupted function.
Definition: errnum.h:130
@ ERRNUM_SPIPE
Invalid seek.
Definition: errnum.h:222
@ ERRNUM_ALREADY
Connection already in progress.
Definition: errnum.h:91
@ ERRNUM_NOPROTOOPT
Protocol not available.
Definition: errnum.h:176
@ ERRNUM_BUSY
Device or resource busy.
Definition: errnum.h:97
@ ERRNUM_ISCONN
Socket is connected.
Definition: errnum.h:136
@ ERRNUM_NETDOWN
Network is down.
Definition: errnum.h:151
@ ERRNUM_SRCH
No such process.
Definition: errnum.h:224
@ ERRNUM_MLINK
Too many links.
Definition: errnum.h:144
@ ERRNUM_IO
I/O error.
Definition: errnum.h:134
@ ERRNUM_TIMEDOUT
Connection timed out.
Definition: errnum.h:229
@ ERRNUM_NOENT
No such file or directory.
Definition: errnum.h:165
@ ERRNUM_NFILE
Too many files open in system.
Definition: errnum.h:157
@ ERRNUM_AI_SOCKTYPE
The intended socket type was not recognized.
Definition: errnum.h:259
@ ERRNUM_BADF
Bad file descriptor.
Definition: errnum.h:93
@ ERRNUM_OPNOTSUPP
Operation not supported on socket.
Definition: errnum.h:202
@ ERRNUM_NOTTY
Inappropriate I/O control operation.
Definition: errnum.h:198
@ ERRNUM_PERM
Operation not permitted.
Definition: errnum.h:208
@ ERRNUM_PROTONOSUPPORT
Protocol not supported.
Definition: errnum.h:214
@ ERRNUM_NOMEM
Not enough space.
Definition: errnum.h:172
@ ERRNUM_TIME
Stream ioctl() timeout.
Definition: errnum.h:227
@ ERRNUM_FBIG
File too large.
Definition: errnum.h:120
@ ERRNUM_2BIG
Argument list too long.
Definition: errnum.h:79
@ ERRNUM_NOEXEC
Executable file format error.
Definition: errnum.h:167
@ ERRNUM_NOTSUP
Not supported.
Definition: errnum.h:196
@ ERRNUM_CHILD
No child process.
Definition: errnum.h:101
@ ERRNUM_NOTSOCK
Not a socket.
Definition: errnum.h:194
@ ERRNUM_NOTDIR
Not a directory or a symbolic link to a directory.
Definition: errnum.h:188
@ ERRNUM_MFILE
File descriptor value too large.
Definition: errnum.h:142
@ ERRNUM_ACCES
Permission denied.
Definition: errnum.h:81
@ ERRNUM_ADDRNOTAVAIL
Address not available.
Definition: errnum.h:85
@ ERRNUM_INVAL
Invalid argument.
Definition: errnum.h:132
@ ERRNUM_AI_AGAIN
The name could not be resolved at this time.
Definition: errnum.h:240
@ ERRNUM_CONNABORTED
Connection aborted.
Definition: errnum.h:103
@ ERRNUM_NOTEMPTY
Directory not empty.
Definition: errnum.h:190
@ ERRNUM_AI_FAIL
A non-recoverable error occurred.
Definition: errnum.h:244
@ ERRNUM_PROTOTYPE
Protocol wrong type for socket.
Definition: errnum.h:216
@ ERRNUM_ADDRINUSE
Address in use.
Definition: errnum.h:83
@ ERRNUM_NOMSG
No message of the desired type.
Definition: errnum.h:174
@ ERRNUM_AGAIN
Resource unavailable, try again.
Definition: errnum.h:89
@ ERRNUM_ROFS
Read-only file system.
Definition: errnum.h:220
@ ERRNUM_NOBUFS
No buffer space available.
Definition: errnum.h:159
@ ERRNUM_CONNREFUSED
Connection refused.
Definition: errnum.h:105
@ ERRNUM_DOM
Mathematics argument out of domain of function.
Definition: errnum.h:113
@ ERRNUM_NETRESET
Connection aborted by network.
Definition: errnum.h:153
@ ERRNUM_HOSTUNREACH
Host is unreachable.
Definition: errnum.h:122
@ ERRNUM_DEADLK
Resource deadlock would occur.
Definition: errnum.h:109
@ ERRNUM_EXIST
File exists.
Definition: errnum.h:116
@ ERRNUM_NODATA
No message is available on the STREAM head read queue.
Definition: errnum.h:161
@ ERRNUM_ISDIR
Is a directory.
Definition: errnum.h:138
@ ERRNUM_OVERFLOW
Value too large to be stored in data type.
Definition: errnum.h:204
@ ERRNUM_AI_OVERFLOW
An argument buffer overflowed.
Definition: errnum.h:255
@ ERRNUM_PIPE
Broken pipe.
Definition: errnum.h:210
@ ERRNUM_TXTBSY
Text file busy.
Definition: errnum.h:231
@ ERRNUM_AI_FAMILY
The address family was not recognized or the address length was invalid for the specified family.
Definition: errnum.h:249
@ ERRNUM_NOSR
No STREAM resources.
Definition: errnum.h:180
@ ERRNUM_NOSTR
Not a STREAM.
Definition: errnum.h:182
@ ERRNUM_ILSEQ
Illegal byte sequence.
Definition: errnum.h:126
@ ERRNUM_CONNRESET
Connection reset.
Definition: errnum.h:107
@ ERRNUM_INPROGRESS
Operation in progress.
Definition: errnum.h:128
@ ERRNUM_AI_SERVICE
The service passed was not recognized for the specified socket type.
Definition: errnum.h:257
@ ERRNUM_NODEV
No such device.
Definition: errnum.h:163
@ ERRNUM_FAULT
Bad address.
Definition: errnum.h:118
@ ERRNUM_LOOP
Too many levels of symbolic links.
Definition: errnum.h:140
@ ERRNUM_NETUNREACH
Network unreachable.
Definition: errnum.h:155
@ ERRNUM_AI_NONAME
The name does not resolve for the supplied parameters.
Definition: errnum.h:253
@ ERRNUM_XDEV
Cross-device link.
Definition: errnum.h:235
@ ERRNUM_DESTADDRREQ
Destination address required.
Definition: errnum.h:111
@ ERRNUM_NAMETOOLONG
Filename too long.
Definition: errnum.h:149
@ ERRNUM_CANCELED
Operation canceled.
Definition: errnum.h:99
@ ERRNUM_NOTRECOVERABLE
State not recoverable.
Definition: errnum.h:192
@ ERRNUM_NOLCK
No locks available.
Definition: errnum.h:169
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
Definition: errnum.c:932
const char * errno2str(int errnum)
Returns a string describing a standard C error number.
Definition: errnum.h:430
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
Definition: errnum.c:944
int errc2no(int errc)
Transforms a native error code to a standard C error number.
Definition: errnum.c:299
const char * errc2str(int errc)
Returns a string describing a native error code.
Definition: errnum.h:436
enum errnum errnum_t
The platform-independent error number type.
Definition: errnum.h:266
int errnum2no(errnum_t errnum)
Transforms a platform-independent error number to a standard C error number.
Definition: errnum.c:567
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
Definition: errnum.c:46
errnum_t get_errnum(void)
Returns the last (thread-specific) platform-independent error number set by a system call or library ...
Definition: errnum.h:418
void set_errnum(errnum_t errnum)
Sets the current (thread-specific) platform-independent error number to errnum.
Definition: errnum.h:424
const char * errnum2str_r(errnum_t errnum, char *strerrbuf, size_t buflen)
Returns a string describing a platform-independent error number.
Definition: errnum.h:448
This header file is part of the Lely libraries; it contains the compiler feature definitions.
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....