Lely core libraries  2.3.4
errnum.h File Reference

This header file is part of the utilities library; it contains the native and platform-independent error number declarations. More...

#include <lely/features.h>
#include <errno.h>
#include <stddef.h>
#include <netdb.h>
Include dependency graph for errnum.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef enum errnum errnum_t
 The platform-independent error number type.
 

Enumerations

enum  errnum {
  ERRNUM_2BIG = 0 , ERRNUM_ACCES , ERRNUM_ADDRINUSE , ERRNUM_ADDRNOTAVAIL ,
  ERRNUM_AFNOSUPPORT , ERRNUM_AGAIN , ERRNUM_ALREADY , ERRNUM_BADF ,
  ERRNUM_BADMSG , ERRNUM_BUSY , ERRNUM_CANCELED , ERRNUM_CHILD ,
  ERRNUM_CONNABORTED , ERRNUM_CONNREFUSED , ERRNUM_CONNRESET , ERRNUM_DEADLK ,
  ERRNUM_DESTADDRREQ , ERRNUM_DOM , ERRNUM_EXIST , ERRNUM_FAULT ,
  ERRNUM_FBIG , ERRNUM_HOSTUNREACH , ERRNUM_IDRM , ERRNUM_ILSEQ ,
  ERRNUM_INPROGRESS , ERRNUM_INTR , ERRNUM_INVAL , ERRNUM_IO ,
  ERRNUM_ISCONN , ERRNUM_ISDIR , ERRNUM_LOOP , ERRNUM_MFILE ,
  ERRNUM_MLINK , ERRNUM_MSGSIZE , ERRNUM_NAMETOOLONG , ERRNUM_NETDOWN ,
  ERRNUM_NETRESET , ERRNUM_NETUNREACH , ERRNUM_NFILE , ERRNUM_NOBUFS ,
  ERRNUM_NODATA , ERRNUM_NODEV , ERRNUM_NOENT , ERRNUM_NOEXEC ,
  ERRNUM_NOLCK , ERRNUM_NOMEM , ERRNUM_NOMSG , ERRNUM_NOPROTOOPT ,
  ERRNUM_NOSPC , ERRNUM_NOSR , ERRNUM_NOSTR , ERRNUM_NOSYS ,
  ERRNUM_NOTCONN , ERRNUM_NOTDIR , ERRNUM_NOTEMPTY , ERRNUM_NOTRECOVERABLE ,
  ERRNUM_NOTSOCK , ERRNUM_NOTSUP , ERRNUM_NOTTY , ERRNUM_NXIO ,
  ERRNUM_OPNOTSUPP , ERRNUM_OVERFLOW , ERRNUM_OWNERDEAD , ERRNUM_PERM ,
  ERRNUM_PIPE , ERRNUM_PROTO , ERRNUM_PROTONOSUPPORT , ERRNUM_PROTOTYPE ,
  ERRNUM_RANGE , ERRNUM_ROFS , ERRNUM_SPIPE , ERRNUM_SRCH ,
  ERRNUM_TIME , ERRNUM_TIMEDOUT , ERRNUM_TXTBSY , ERRNUM_WOULDBLOCK ,
  ERRNUM_XDEV , ERRNUM_AI_AGAIN , ERRNUM_AI_BADFLAGS , ERRNUM_AI_FAIL ,
  ERRNUM_AI_FAMILY , ERRNUM_AI_MEMORY , ERRNUM_AI_NONAME , ERRNUM_AI_OVERFLOW ,
  ERRNUM_AI_SERVICE , ERRNUM_AI_SOCKTYPE
}
 The platform-independent error numbers. More...
 

Functions

int errno2c (int errnum)
 Transforms a standard C error number to a native error code. More...
 
errnum_t errno2num (int errnum)
 Transforms a standard C error number to a platform-independent error number. More...
 
int errc2no (int errc)
 Transforms a native error code to a standard C error number. More...
 
errnum_t errc2num (int errc)
 Transforms a native error code to a platform-independent error number. More...
 
int errnum2no (errnum_t errnum)
 Transforms a platform-independent error number to a standard C error number. More...
 
int errnum2c (errnum_t errnum)
 Transforms a platform-independent error number to a native error code. More...
 
int get_errc (void)
 Returns the last (thread-specific) native error code set by a system call or library function. More...
 
void set_errc (int errc)
 Sets the current (thread-specific) native error code to errc. More...
 
errnum_t get_errnum (void)
 Returns the last (thread-specific) platform-independent error number set by a system call or library function. More...
 
void set_errnum (errnum_t errnum)
 Sets the current (thread-specific) platform-independent error number to errnum. More...
 
const char * errno2str (int errnum)
 Returns a string describing a standard C error number. More...
 
const char * errno2str_r (int errnum, char *strerrbuf, size_t buflen)
 Returns a string describing a standard C error number. More...
 
const char * errc2str (int errc)
 Returns a string describing a native error code. More...
 
const char * errc2str_r (int errc, char *strerrbuf, size_t buflen)
 Returns a string describing a native error code. More...
 
const char * errnum2str (errnum_t errnum)
 Returns a string describing a platform-independent error number. More...
 
const char * errnum2str_r (errnum_t errnum, char *strerrbuf, size_t buflen)
 Returns a string describing a platform-independent error number. More...
 

Detailed Description

This header file is part of the utilities library; it contains the native and platform-independent error number declarations.

The C standard defines the (thread-local) errno variable plus a small number of error numbers (which are guaranteed to be positive). POSIX platforms extend the list of pre-defined error numbers to cover all platform-specific errors. Windows defines a separate (thread-local) variable, accessible by GetLastError()/SetLastError(), for all system errors. A subset of these, accessible by WSAGetLastError()/WSASetLastError(), is used for Windows Sockets errors. On top of this, both POSIX and Windows maintain a list of error codes returned by the getaddrinfo() and getnameinfo() functions. On Windows these error codes have the same values as their corresponding system errors, while on Linux they all have negative values, allowing them to be distinguished from valid errno values. Unfortunately on Cygwin their values are positive and overlap with errno error numbers.

In order to minimize information loss, we would like to keep track of platform-dependent error numbers when storing or propagating errors, but do so in a platform-independent way. get_errc() and set_errc() provide access to the current (thread-local) error code. These functions are equivalent to GetLastError() and SetLastError() on Windows and map to errno on other platforms. Negative errno values are used to store the error codes returned by getaddrinfo() and getnameinfo(), even if the original error codes are positive (e.g., on Cygwin). Since Windows also uses errno (for standard C functions), set_errc(errno2c(errno)) can be used to portably translate errno to a native error code (this is a no-op on POSIX platforms).

When responding to errors it is desirable to have a list of platform-independent error numbers. The errnum_t data type provides the ERRNUM_* error values. These values are guaranteed to be positive, unique and to have the same value across all platforms. There is an ERRNUM_* value for each of the (non-reserved) POSIX error numbers as well as the error codes returned by getaddrinfo() and getnameinfo(). Translating between native and platform-independent error numbers can be done with errc2num() and errnum2c().

Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file errnum.h.

Enumeration Type Documentation

◆ errnum

enum errnum

The platform-independent error numbers.

Enumerator
ERRNUM_2BIG 

Argument list too long.

ERRNUM_ACCES 

Permission denied.

ERRNUM_ADDRINUSE 

Address in use.

ERRNUM_ADDRNOTAVAIL 

Address not available.

ERRNUM_AFNOSUPPORT 

Address family not supported.

ERRNUM_AGAIN 

Resource unavailable, try again.

ERRNUM_ALREADY 

Connection already in progress.

ERRNUM_BADF 

Bad file descriptor.

ERRNUM_BADMSG 

Bad message.

ERRNUM_BUSY 

Device or resource busy.

ERRNUM_CANCELED 

Operation canceled.

ERRNUM_CHILD 

No child process.

ERRNUM_CONNABORTED 

Connection aborted.

ERRNUM_CONNREFUSED 

Connection refused.

ERRNUM_CONNRESET 

Connection reset.

ERRNUM_DEADLK 

Resource deadlock would occur.

ERRNUM_DESTADDRREQ 

Destination address required.

ERRNUM_DOM 

Mathematics argument out of domain of function.

ERRNUM_EXIST 

File exists.

ERRNUM_FAULT 

Bad address.

ERRNUM_FBIG 

File too large.

ERRNUM_HOSTUNREACH 

Host is unreachable.

ERRNUM_IDRM 

Identifier removed.

ERRNUM_ILSEQ 

Illegal byte sequence.

ERRNUM_INPROGRESS 

Operation in progress.

ERRNUM_INTR 

Interrupted function.

ERRNUM_INVAL 

Invalid argument.

ERRNUM_IO 

I/O error.

ERRNUM_ISCONN 

Socket is connected.

ERRNUM_ISDIR 

Is a directory.

ERRNUM_LOOP 

Too many levels of symbolic links.

ERRNUM_MFILE 

File descriptor value too large.

ERRNUM_MLINK 

Too many links.

ERRNUM_MSGSIZE 

Message too large.

ERRNUM_NAMETOOLONG 

Filename too long.

ERRNUM_NETDOWN 

Network is down.

ERRNUM_NETRESET 

Connection aborted by network.

ERRNUM_NETUNREACH 

Network unreachable.

ERRNUM_NFILE 

Too many files open in system.

ERRNUM_NOBUFS 

No buffer space available.

ERRNUM_NODATA 

No message is available on the STREAM head read queue.

ERRNUM_NODEV 

No such device.

ERRNUM_NOENT 

No such file or directory.

ERRNUM_NOEXEC 

Executable file format error.

ERRNUM_NOLCK 

No locks available.

ERRNUM_NOMEM 

Not enough space.

ERRNUM_NOMSG 

No message of the desired type.

ERRNUM_NOPROTOOPT 

Protocol not available.

ERRNUM_NOSPC 

No space left on device.

ERRNUM_NOSR 

No STREAM resources.

ERRNUM_NOSTR 

Not a STREAM.

ERRNUM_NOSYS 

Function not supported.

ERRNUM_NOTCONN 

The socket is not connected.

ERRNUM_NOTDIR 

Not a directory or a symbolic link to a directory.

ERRNUM_NOTEMPTY 

Directory not empty.

ERRNUM_NOTRECOVERABLE 

State not recoverable.

ERRNUM_NOTSOCK 

Not a socket.

ERRNUM_NOTSUP 

Not supported.

ERRNUM_NOTTY 

Inappropriate I/O control operation.

ERRNUM_NXIO 

No such device or address.

ERRNUM_OPNOTSUPP 

Operation not supported on socket.

ERRNUM_OVERFLOW 

Value too large to be stored in data type.

ERRNUM_OWNERDEAD 

Previous owner died.

ERRNUM_PERM 

Operation not permitted.

ERRNUM_PIPE 

Broken pipe.

ERRNUM_PROTO 

Protocol error.

ERRNUM_PROTONOSUPPORT 

Protocol not supported.

ERRNUM_PROTOTYPE 

Protocol wrong type for socket.

ERRNUM_RANGE 

Result too large.

ERRNUM_ROFS 

Read-only file system.

ERRNUM_SPIPE 

Invalid seek.

ERRNUM_SRCH 

No such process.

ERRNUM_TIME 

Stream ioctl() timeout.

ERRNUM_TIMEDOUT 

Connection timed out.

ERRNUM_TXTBSY 

Text file busy.

ERRNUM_WOULDBLOCK 

Operation would block.

ERRNUM_XDEV 

Cross-device link.

ERRNUM_AI_AGAIN 

The name could not be resolved at this time.

Future attempts may succeed.

ERRNUM_AI_BADFLAGS 

The flags had an invalid value.

ERRNUM_AI_FAIL 

A non-recoverable error occurred.

ERRNUM_AI_FAMILY 

The address family was not recognized or the address length was invalid for the specified family.

ERRNUM_AI_MEMORY 

There was a memory allocation failure.

ERRNUM_AI_NONAME 

The name does not resolve for the supplied parameters.

ERRNUM_AI_OVERFLOW 

An argument buffer overflowed.

ERRNUM_AI_SERVICE 

The service passed was not recognized for the specified socket type.

ERRNUM_AI_SOCKTYPE 

The intended socket type was not recognized.

Definition at line 77 of file errnum.h.

Function Documentation

◆ errno2c()

int errno2c ( int  errnum)

Transforms a standard C error number to a native error code.

This is equivalent to errnum2c(errno2num(errnum)) on Windows, or errnum on other platforms.

See also
errc2no()

Definition at line 46 of file errnum.c.

◆ errno2num()

errnum_t errno2num ( int  errnum)

Transforms a standard C error number to a platform-independent error number.

See also
errnum2no()

Definition at line 56 of file errnum.c.

◆ errc2no()

int errc2no ( int  errc)

Transforms a native error code to a standard C error number.

This is equivalent to errnum2no(errc2num(errc)) on Windows, or errc on other platforms (provided errc is positive).

See also
errc2no()

Definition at line 299 of file errnum.c.

◆ errc2num()

errnum_t errc2num ( int  errc)

Transforms a native error code to a platform-independent error number.

See also
errnum2c()

Definition at line 309 of file errnum.c.

◆ errnum2no()

int errnum2no ( errnum_t  errnum)

Transforms a platform-independent error number to a standard C error number.

See also
errno2num()

Definition at line 567 of file errnum.c.

◆ errnum2c()

int errnum2c ( errnum_t  errnum)

Transforms a platform-independent error number to a native error code.

See also
err2num()

Definition at line 810 of file errnum.c.

◆ get_errc()

int get_errc ( void  )

Returns the last (thread-specific) native error code set by a system call or library function.

This is equivalent to GetLastError()/WSAGetLastError() on Windows, or errno on other platforms.

This function returns the thread-specific error number.

See also
set_errc()

Definition at line 932 of file errnum.c.

◆ set_errc()

void set_errc ( int  errc)

Sets the current (thread-specific) native error code to errc.

This is equivalent to SetLastError(errc)/WSASetLastError(errc) on Windows, or errno = errc on other platforms.

See also
get_errc()

Definition at line 944 of file errnum.c.

◆ get_errnum()

errnum_t get_errnum ( void  )
inline

Returns the last (thread-specific) platform-independent error number set by a system call or library function.

This is equivalent to errc2num(get_errc()).

See also
set_errnum()

Definition at line 418 of file errnum.h.

◆ set_errnum()

void set_errnum ( errnum_t  errnum)
inline

Sets the current (thread-specific) platform-independent error number to errnum.

This is equivalent to set_errc(errnum2c(errnum)).

See also
get_errnum()

Definition at line 424 of file errnum.h.

◆ errno2str()

const char * errno2str ( int  errnum)
inline

Returns a string describing a standard C error number.

This is equivalent to strerror(errnum). The returned string MAY be invalidated by a subsequent call to errno2str(), errc2str() or errnum2str().

See also
errno2str_r()

Definition at line 430 of file errnum.h.

◆ errno2str_r()

const char* errno2str_r ( int  errnum,
char *  strerrbuf,
size_t  buflen 
)

Returns a string describing a standard C error number.

The string is copied to a buffer, if specified, as if by POSIX strerror_r().

Parameters
errnumthe standard C error number.
strerrbufa pointer to the string buffer. If not NULL, at most buflen bytes are copied to the buffer. The string is guaranteed to be null-terminated.
buflenthe number of bytes available at strerrbuf.
Returns
strerrbuf if not NULL, and errno2str(errnum) otherwise.
See also
errno2str()

Definition at line 956 of file errnum.c.

◆ errc2str()

const char * errc2str ( int  errc)
inline

Returns a string describing a native error code.

See also
errc2str_r()

Definition at line 436 of file errnum.h.

◆ errc2str_r()

const char* errc2str_r ( int  errc,
char *  strerrbuf,
size_t  buflen 
)

Returns a string describing a native error code.

The string is copied to a buffer, if specified..

Parameters
errcthe native error code.
strerrbufa pointer to the string buffer. If not NULL, at most buflen bytes are copied to the buffer. The string is guaranteed to be null-terminated.
buflenthe number of bytes available at strerrbuf.
Returns
strerrbuf if not NULL, and errno2str(errnum) otherwise.
See also
errc2str()

Definition at line 988 of file errnum.c.

◆ errnum2str()

const char * errnum2str ( errnum_t  errnum)
inline

Returns a string describing a platform-independent error number.

This is equivalent to errc2str(errnum2c(errnum)).

See also
errnum2str_r()

Definition at line 442 of file errnum.h.

◆ errnum2str_r()

const char * errnum2str_r ( errnum_t  errnum,
char *  strerrbuf,
size_t  buflen 
)
inline

Returns a string describing a platform-independent error number.

This is equivalent to errc2str_r(errnum2c(errnum)).

See also
errnum2str()

Definition at line 448 of file errnum.h.