mbgtools-lx
4.2.8
|
#include <mbgerror.h>
#include <mbg_tgt.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <netdb.h>
Go to the source code of this file.
Data Structures | |
struct | ERRNO_CNV_ENTRY |
Macros | |
#define | _MBGERROR |
#define | _MBG_TGT_HAS_POSIX_ERRNO 1 |
#define | _MBG_TGT_HAS_POSIX_H_ERRNO 1 |
Functions | |
static int | lookup_tbl_errno (int srch_errno, const ERRNO_CNV_ENTRY tbl[], int dflt_val) |
Lookup some error code in a conversion table. More... | |
int | mbg_errno_to_os (int err_no) |
Convert one of the MBG_ERROR_CODES to an OS-specific format. More... | |
const char * | mbg_strerror (int mbg_errno) |
Return an error string associated with the MBG_ERROR_CODES. More... | |
bool | mbg_cond_err_msg (int rc, const char *what) |
Check if a value is an error code and print an associated error message. More... | |
bool | mbg_cond_err_msg_info (int rc, const char *what, const char *info) |
Check if a value is an general or a "not supported" error code and print an associated message. More... | |
int | mbg_posix_errno_to_mbg (int posix_errno, const char *info) |
Translate a POSIX errno error code to one of the MBG_ERROR_CODES. More... | |
int | mbg_posix_h_errno_to_mbg (int posix_h_errno, const char *info) |
Translate a POSIX h_errno error code to one of the MBG_ERROR_CODES. More... | |
int | mbg_get_last_error (const char *info) |
Get and translate last error after non-socket function call. More... | |
int | mbg_get_last_socket_error (const char *info) |
Get and translate last error after socket function call. More... | |
int | mbg_get_gethostbyname_error (const char *info) |
Retrieve and convert last error after gethostbyname() More... | |
Variables | |
static ERRNO_CNV_ENTRY | posix_errno_table [] |
Mappings between Meinberg error codes and POSIX error codes. More... | |
static ERRNO_CNV_ENTRY | posix_h_errno_table [] |
#define _MBG_TGT_HAS_POSIX_ERRNO 1 |
Definition at line 84 of file mbgerror.c.
#define _MBG_TGT_HAS_POSIX_H_ERRNO 1 |
Definition at line 85 of file mbgerror.c.
#define _MBGERROR |
Definition at line 51 of file mbgerror.c.
|
static |
Lookup some error code in a conversion table.
[in] | srch_errno | The error number to be looked up in the conversion table |
[in] | tbl | A conversion table |
[in] | dflt_val | The code to be returned if no table entry was found. |
dflt_val
if original code not found in table. Definition at line 601 of file mbgerror.c.
References ERRNO_CNV_ENTRY::mapped_errno, and ERRNO_CNV_ENTRY::srch_errno.
Referenced by mbg_cond_err_msg_info(), mbg_errno_to_os(), mbg_posix_errno_to_mbg(), and mbg_posix_h_errno_to_mbg().
bool mbg_cond_err_msg | ( | int | rc, |
const char * | what | ||
) |
Check if a value is an error code and print an associated error message.
[in] | rc | A positive number including MBG_SUCCESS, or one of the MBG_ERROR_CODES |
[in] | what | A string indicated what failed |
Definition at line 714 of file mbgerror.c.
References mbg_cond_err_msg_info().
bool mbg_cond_err_msg_info | ( | int | rc, |
const char * | what, | ||
const char * | info | ||
) |
Check if a value is an general or a "not supported" error code and print an associated message.
If rc contains an error code then an error message is printed, and true is returned.
If the optional parameter string info2 is not NULL then it should contain the name of a feature which has been tested before. In this case, if the error code is the specific error MBG_ERR_NOT_SUPP_BY_DEV then a "not supported" message is printed using info2.
If info2 is NULL, or the error code is not MBG_ERR_NOT_SUPP_BY_DEV then the standard error message is printed anyway.
[in] | rc | A positive number including MBG_SUCCESS, or one of the MBG_ERROR_CODES |
[in] | what | A string indicated what failed |
[in] | info | An optional informational string telling what is not supported (may be NULL). |
Definition at line 742 of file mbgerror.c.
References _mbgddmsg_2, lookup_tbl_errno(), mbg_cvi_rs232_error_to_mbg(), MBG_ERR_NOT_SUPP_BY_DEV, MBG_ERR_UNKNOWN, MBG_LOG_INFO, mbg_rc_is_error, mbg_strerror(), MBG_SUCCESS, mbg_win32_ntstatus_to_mbg(), mbg_win32_sys_err_to_mbg(), and mbg_win32_wsa_err_to_mbg().
int mbg_errno_to_os | ( | int | err_no | ) |
Convert one of the MBG_ERROR_CODES to an OS-specific format.
[in] | err_no | One of the MBG_ERROR_CODES. |
Definition at line 626 of file mbgerror.c.
References lookup_tbl_errno(), and MBG_SUCCESS.
int mbg_get_gethostbyname_error | ( | const char * | info | ) |
Retrieve and convert last error after gethostbyname()
This function is specific to retrieve and translate error codes returned by gethostbyname() and gethostbyaddr(). In case of error these functions don't set errno but h_errno on POSIX systems, but under Windows the error code can be retrieved by WSAGetLastError() as usual.
The functions gethostbyname() and gethostbyaddr() are obsolete, and getaddressinfo() should be used preferably.
[in] | info | An optional informational text string, or NULL |
Definition at line 1090 of file mbgerror.c.
References MBG_ERR_GENERIC, MBG_ERR_NO_MEM, MBG_ERR_UNKNOWN, mbg_get_last_error(), mbg_posix_h_errno_to_mbg(), mbg_win32_wsa_err_to_mbg(), and mbg_zlib_error_to_mbg().
int mbg_get_last_error | ( | const char * | info | ) |
Get and translate last error after non-socket function call.
Retrieve the "last error" code after a non-socket function has been called and translate to one of the MBG_ERROR_CODES.
On POSIX systems the "last error" code is always stored in errno, but e.g. under Windows the "last error" code after a socket function has to be retrieved by calling WSAGetLastError(), whereas the "last error" code from non-socket POSIX-like functions has to be retrieved by calling GetLastError().
[in] | info | An optional informational text string, or NULL |
Definition at line 993 of file mbgerror.c.
References mbg_posix_errno_to_mbg(), and mbg_win32_sys_err_to_mbg().
int mbg_get_last_socket_error | ( | const char * | info | ) |
Get and translate last error after socket function call.
Retrieve the "last error" code after a socket function has been called and translate to one of the MBG_ERROR_CODES.
On POSIX systems the "last error" code is always stored in errno, but e.g. under Windows the "last error" code after a socket function has to be retrieved by calling WSAGetLastError, whereas the "last error" code from non-socket POSIX-like functions is stored in errno as usual.
[in] | info | An optional informational text string, or NULL |
Definition at line 1038 of file mbgerror.c.
References MBG_ERR_GENERIC, MBG_ERR_UNKNOWN, mbg_posix_errno_to_mbg(), and mbg_win32_wsa_err_to_mbg().
int mbg_posix_errno_to_mbg | ( | int | posix_errno, |
const char * | info | ||
) |
Translate a POSIX errno error code to one of the MBG_ERROR_CODES.
[in] | posix_errno | A POSIX error code as usually defined in errno.h |
[in] | info | An optional informational text string, or NULL |
Definition at line 920 of file mbgerror.c.
References lookup_tbl_errno(), and MBG_ERR_UNKNOWN.
int mbg_posix_h_errno_to_mbg | ( | int | posix_h_errno, |
const char * | info | ||
) |
Translate a POSIX h_errno error code to one of the MBG_ERROR_CODES.
This function is specific to translate error codes returned by gethostbyname() and gethostbyaddr(). In case of error these functions don't set errno but h_errno to a specific value.
The functions gethostbyname() and gethostbyaddr() are obsolete, and getaddressinfo() should be used preferably.
[in] | posix_h_errno | An error code as usually defined in netdb.h |
[in] | info | An optional informational text string, or NULL |
Definition at line 956 of file mbgerror.c.
References lookup_tbl_errno(), and MBG_ERR_UNKNOWN.
const char* mbg_strerror | ( | int | mbg_errno | ) |
Return an error string associated with the MBG_ERROR_CODES.
[in] | mbg_errno | One of the MBG_ERROR_CODES |
Definition at line 685 of file mbgerror.c.
References MBG_CODE_NAME_TABLE_ENTRY::code, MBG_ERR_STR_TABLE_ENG, and MBG_CODE_NAME_TABLE_ENTRY::name.
|
static |
Mappings between Meinberg error codes and POSIX error codes.
Always refer to the symbolic names only. The numeric codes listed in the comments below are just for a quick reference, and may vary depending on the OS type and version.
Linux: /usr/include/asm-generic/errno.h
FreeBSD/NetBSD: /usr/include/sys/errno.h
Definition at line 173 of file mbgerror.c.
|
static |
Definition at line 234 of file mbgerror.c.