57 #if defined( MBG_TGT_WIN32 ) 59 #if !defined( MBG_TGT_KERNEL ) 63 #define _MBG_TGT_HAS_POSIX_ERRNO 1 64 #define _MBG_TGT_HAS_WIN32_ERR_API 1 68 #define _MBG_TGT_OMIT_LAST_ERROR 1 69 #define _MBG_TGT_OMIT_ERR_MSG 1 // Not (yet) supported in Windows kernel mode 72 #elif defined( MBG_TGT_CVI ) 76 #elif defined( MBG_TGT_LINUX ) 78 #if !defined( MBG_TGT_KERNEL ) 84 #define _MBG_TGT_HAS_POSIX_ERRNO 1 85 #define _MBG_TGT_HAS_POSIX_H_ERRNO 1 87 #include <asm/errno.h> 89 #define _MBG_TGT_HAS_POSIX_ERRNO 1 90 #define _MBG_TGT_OMIT_LAST_ERROR 1 91 #define _MBG_TGT_OMIT_ERR_MSG 1 94 #elif defined( MBG_TGT_BSD ) 96 #if !defined( MBG_TGT_KERNEL ) 102 #define _MBG_TGT_HAS_POSIX_ERRNO 1 103 #define _MBG_TGT_HAS_POSIX_H_ERRNO 1 105 #include <sys/errno.h> 106 #if defined( MBG_TGT_FREEBSD ) 107 #include <sys/stddef.h> 108 #elif defined( MBG_TGT_NETBSD ) 109 #include <sys/null.h> 112 #define _MBG_TGT_HAS_POSIX_ERRNO 1 113 #define _MBG_TGT_OMIT_LAST_ERROR 1 114 #define _MBG_TGT_OMIT_ERR_MSG 1 117 #elif defined( MBG_TGT_QNX_NTO ) // QNX 6.x only, but not QNX 4.x 124 #define _MBG_TGT_HAS_POSIX_ERRNO 1 125 #define _MBG_TGT_HAS_POSIX_H_ERRNO 1 127 #elif defined( MBG_TGT_DOS ) 134 #define _MBG_TGT_HAS_POSIX_ERRNO 1 135 #define _MBG_TGT_OMIT_SOCKET_ERRORS 1 // No network socket support by OS 139 #if defined( USE_MBG_ZLIB ) 143 #if !defined( DEBUG ) 158 #if defined( _MBG_TGT_HAS_POSIX_ERRNO ) 212 #if defined( EOVERFLOW ) 215 #if defined( ENOTSOCK ) 218 #if defined( ECONNRESET ) 221 #if defined( ETIMEDOUT ) 228 #endif // defined( _MBG_TGT_HAS_POSIX_ERRNO ) 232 #if defined( _MBG_TGT_HAS_POSIX_H_ERRNO ) 246 #endif // defined( _MBG_TGT_HAS_POSIX_H_ERRNO ) 250 #if defined( MBG_TGT_CVI ) 307 #endif // defined( MBG_TGT_CVI ) 311 #if defined( MBG_TGT_WIN32 ) 313 #if defined( MBG_TGT_KERNEL ) 363 #if !_USE_WIN32_PRIVATE_STATUS_CODES 434 #endif // !_USE_WIN32_PRIVATE_STATUS_CODES 437 #else // Windows user space 468 { ERROR_OUTOFMEMORY, MBG_ERR_NO_MEM },
473 { ERROR_READ_FAULT, MBG_ERR_IO },
486 { ERROR_IO_DEVICE, MBG_ERR_IO },
584 #endif // Windows user space 586 #endif // defined( MBG_TGT_WIN32 ) 614 #if !_USE_WIN32_PRIVATE_STATUS_CODES 628 #if defined( MBG_TGT_KERNEL ) 630 #if defined( MBG_TGT_WIN32 ) 633 return STATUS_SUCCESS;
635 return lookup_tbl_errno( err_no, mbg_ioctl_to_ntstatus_table, STATUS_UNSUCCESSFUL );
637 #elif defined( MBG_TGT_LINUX ) 639 #elif defined( MBG_TGT_FREEBSD ) 641 #elif defined( MBG_TGT_NETBSD ) 645 #error this needs to be implemented 652 #if defined( MBG_TGT_WIN32 ) // FIXME TODO 654 return ( -err_no | 0xE0000000L );
656 #elif defined( MBG_TGT_BSD ) 673 #endif // _USE_WIN32_PRIVATE_STATUS_CODES 691 for ( p = tbl; p->
name; p++ )
693 if ( mbg_errno == p->
code )
697 return "Unknown error";
703 #if !defined( _MBG_TGT_OMIT_ERR_MSG ) 747 fprintf( stderr,
"This device does not %s.\n", info );
749 fprintf( stderr,
"** %s failed: %s (rc: %i)\n", what,
mbg_strerror( rc ), rc );
758 #endif // !defined( _MBG_TGT_OMIT_ERR_MSG ) 762 #if defined( MBG_TGT_CVI ) 779 fprintf( stderr,
"%s, CVI RS-232 rc: %i\n", info, cvi_rc );
792 #if defined( MBG_TGT_WIN32 ) 794 #if defined( MBG_TGT_KERNEL ) 819 #else // Windows user space 834 if ( win32_sys_rc == ERROR_SUCCESS )
837 if ( win32_sys_rc & STATUS_CUSTOM_FLAG_MASK )
844 rc = - (int) ( win32_sys_rc & 0xFFFF );
849 rc = (int) win32_sys_rc;
865 fprintf( stderr,
"%s, win32_sys_rc: 0x%08lX (%i) --> %i (%s)\n",
866 info, (
long) win32_sys_rc, (
int) win32_sys_rc,
891 fprintf( stderr,
"%s, wsa_err: %i\n", info, wsa_err );
902 #endif // Windows user space 904 #endif // defined( MBG_TGT_WIN32 ) 909 #if defined( _MBG_TGT_HAS_POSIX_ERRNO ) 922 #if DEBUG && !defined( MBG_TGT_KERNEL ) 924 fprintf( stderr,
"%s: %s (errno: %i)\n", info,
925 strerror( posix_errno ), posix_errno );
934 #endif // defined( _MBG_TGT_HAS_POSIX_ERRNO ) 938 #if defined( _MBG_TGT_HAS_POSIX_H_ERRNO ) 958 #if DEBUG && !defined( MBG_TGT_KERNEL ) 960 fprintf( stderr,
"%s: %s (h_errno: %i)\n", info,
961 hstrerror( posix_h_errno ), posix_h_errno );
970 #endif // defined( _MBG_TGT_HAS_POSIX_H_ERRNO ) 974 #if !defined( _MBG_TGT_OMIT_LAST_ERROR ) 995 #if defined( MBG_TGT_WIN32 ) 1004 #elif defined( MBG_TGT_POSIX ) 1020 #if !defined( _MBG_TGT_OMIT_SOCKET_ERRORS ) 1040 #if defined( MBG_TGT_CVI ) 1042 #warning This needs to be implemented for CVI 1045 #elif defined( MBG_TGT_WIN32 ) 1047 #if !defined( MBG_TGT_KERNEL ) 1058 #elif defined( MBG_TGT_POSIX ) 1065 #error This function is not supported for this target. 1092 #if defined( MBG_TGT_CVI ) 1094 #warning This needs to be implemented for CVI 1097 #elif defined( MBG_TGT_WIN32 ) 1099 #if !defined( MBG_TGT_KERNEL ) 1105 #elif defined( MBG_TGT_POSIX ) 1111 #error This function is not supported for this target. 1117 #endif // !defined( _MBG_TGT_OMIT_SOCKET_ERRORS ) 1119 #endif // !defined( _MBG_TGT_OMIT_LAST_ERROR ) 1123 #if 0 // not yet finished 1129 int mbg_gai_error(
int rc,
const char *info )
1131 #if defined( MBG_TGT_CVI ) 1133 #warning This needs to be implemented for CVI 1136 #elif defined( MBG_TGT_WIN32 ) 1140 #elif defined( MBG_TGT_POSIX ) 1156 #if defined( USE_MBG_ZLIB ) 1173 fprintf( stderr,
"%s: %s (zlib_error: %d)\n", info,
1177 switch ( zlib_error )
1191 #endif // defined( USE_MBG_ZLIB ) #define MBG_ERR_HOST_NOT_FOUND
host not found
int mbg_win32_ntstatus_to_mbg(NTSTATUS st, const char *info)
Translate a Windows NTSTATUS code to one of the MBG_ERROR_CODES.
#define MBG_ERR_BAD_ADDRESS
Bad Address (like POSIX EFAULT)
#define MBG_ERR_INTR
interrupted function call
#define MBG_ERR_NO_DEV
No such device, or attempted an inappropriate function.
#define MBG_ERR_UNKNOWN
Unknown error code from external API.
#define MBG_ERR_INV_PARM
Invalid parameter.
bool mbg_cond_err_msg(int rc, const char *what)
Check if a value is an error code and print an associated error message.
#define MBG_ERR_EXIST
File exists.
int mbg_get_gethostbyname_error(const char *info)
Retrieve and convert last error after gethostbyname()
A table entry which can be used to map codes to names.
static ERRNO_CNV_ENTRY posix_errno_table[]
Mappings between Meinberg error codes and POSIX error codes.
#define MBG_ERR_GENERIC
Generic error.
#define MBG_ERR_RANGE
input parameter was out of range
#define MBG_ERR_NOT_A_SOCKET
Socket descriptor is not a socket.
#define MBG_ERR_NOT_READY
Bus-level device is temp. unable to respond e.g. during init. after RESET.
#define MBG_ERR_TIMER
Timer expired (e.g. stream timeout on USB disconnect)
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.
#define MBG_ERR_BUFFER_TOO_SMALL
Buffer is too small.
int mbg_win32_wsa_err_to_mbg(int wsa_err, const char *info)
Translate a Windows socket API error code to one of the MBG_ERROR_CODES.
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.
#define MBG_ERR_IRQ_UNSAFE
Enabled IRQ of bus-level device is unsafe with this firmware/ASIC version.
#define MBG_ERR_INV_HANDLE
invalid file/device handle specified
#define MBG_ERR_TIMEOUT
Timeout accessing the device.
#define MBG_ERR_NO_ENTITY
no such file or directory
#define MBG_ERR_NO_SPACE
insufficient disk space left on the device
#define MBG_ERR_IO
Input/output error.
#define MBG_ERR_UNSPEC
Unspecified error.
#define MBG_ERR_CONN_RESET
connection reset by peer
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...
#define MBG_ERR_INV_DEV_REQUEST
IOCTL call not supported by driver.
#define MBG_ERR_NOT_FOUND
Specified item not found.
#define MBG_ERR_NO_MEM
Failed to allocate memory.
#define MBG_ERR_ACCESS
Access denied, e.g. when trying to access a file or device without sufficient permissions.
int mbg_zlib_error_to_mbg(int zlib_error, const char *info, const char *msg)
Retrieve and convert last zlib internal error code.
#define MBG_SUCCESS
Error codes used with Meinberg devices and drivers.
#define _mbgddmsg_2(_f, _lvl, _fmt, _p1, _p2)
int mbg_win32_sys_err_to_mbg(DWORD win32_sys_rc, const char *info)
Translate a Windows non-socket API return code to one of the MBG_RETURN_CODES.
#define MBG_ERR_BUSY
Device or resource busy, can't be used.
#define MBG_ERR_PIPE
pipe error
#define MBG_ERR_PERM
Operation not permitted, e.g. when trying to set the system time without sufficient permissions...
int mbg_errno_to_os(int err_no)
Convert one of the MBG_ERROR_CODES to an OS-specific format.
#define MBG_ERR_STR_TABLE_ENG
Strings associated with MBG_RETURN_CODES.
#define MBG_ERR_NOT_SUPP_BY_DEV
Command or feature not supported by device.
#define MBG_ERR_OVERFLOW
range or buffer overflow
int mbg_get_last_socket_error(const char *info)
Get and translate last error after socket function call.
#define mbg_rc_is_error(_rc)
const char * mbg_strerror(int mbg_errno)
Return an error string associated with the MBG_ERROR_CODES.
static int lookup_tbl_errno(int srch_errno, const ERRNO_CNV_ENTRY tbl[], int dflt_val)
Lookup some error code in a conversion table.
#define MBG_ERR_AGAIN
on a non-blocking socket.
int mbg_cvi_rs232_error_to_mbg(int cvi_rc, const char *info)
Translate an error code from the Labwindows/CVI RS-232 library to one of the MBG_ERROR_CODES.
static ERRNO_CNV_ENTRY posix_h_errno_table[]
int mbg_get_last_error(const char *info)
Get and translate last error after non-socket function call.
#define MBG_ERR_SOCK_INIT
Socket interface not initialized, or failed to initialize.