Lely core libraries
2.2.5
|
This header file is part of the utilities library; it contains the native and platform-independent error number declarations. More...
Go to the source code of this file.
Typedefs | |
typedef enum errnum | errnum_t |
The platform-independent error number type. | |
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 * | errc2str (int errc) |
Returns a string describing a native error code. | |
const char * | errnum2str (errnum_t errnum) |
Returns a string describing a platform-independent error number. More... | |
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().
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.
enum errnum |
The platform-independent error numbers.
int errno2c | ( | int | errnum | ) |
errnum_t errno2num | ( | int | errnum | ) |
Transforms a standard C error number to a platform-independent error number.
int errc2no | ( | int | errc | ) |
errnum_t errc2num | ( | int | errc | ) |
Transforms a native error code to a platform-independent error number.
int errnum2no | ( | errnum_t | errnum | ) |
Transforms a platform-independent error number to a standard C error number.
int errnum2c | ( | errnum_t | errnum | ) |
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.
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.
|
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())
.
|
inline |
Sets the current (thread-specific) platform-independent error number to errnum.
This is equivalent to set_errc(errnum2c(errnum))
.
const char* errno2str | ( | int | errnum | ) |