![]() |
![]() |
![]() |
ntdisp reference manual | ![]() |
---|---|---|---|---|
Top | Description |
#define NTD_SYSTEM_ERROR #define ntd_log_pileup (err) #define ntd_return_on_pileup (err) #define ntd_return_val_on_pileup (err, val) #define ntd_empty (string) enum NtdSystemError; GQuark ntd_system_error_quark (void
); NtdSystemError ntd_system_get_error (void
); gchar * ntd_system_get_error_message (NtdSystemError error_code
); gboolean ntd_system_set_error (GError **error
,const gchar *format
,...
); gboolean ntd_system_set_errorv (GError **error
,const gchar *format
,va_list args
); void ntd_system_set_error_with_code (GError **error
,NtdSystemError error_code
,const gchar *format
,...
); void ntd_system_set_errorv_with_code (GError **error
,NtdSystemError error_code
,const gchar *format
,va_list args
); void ntd_system_clear_error (void
); void ntd_set_verbose_mode (gboolean new_status
); gchar * ntd_escape (gconstpointer buffer
,gsize nbytes
); gulong ntd_checksum (gconstpointer data
,gsize nbytes
); gchar * ntd_find_file (const gchar *file
,...
); void ntd_string_free (GString *string
,gpointer *p_buffer
,gsize *p_len
); void ntd_free_and_nullify (gpointer *mem
); gchar * ntd_uuencode (gconstpointer data
,gsize nbytes
); gboolean ntd_uudecode (const gchar *encoded
,gpointer *p_data
,gsize *p_nbytes
);
#define ntd_empty(string)
Checks wheter string
is empty, that is if string
is NULL
or if its first char is '\0'.
typedef enum { /* NtdSystemError specific */ NTD_SYSTEM_ERROR_NONE, NTD_SYSTEM_ERROR_FAILED, /* Derived from errno values on POSIX.1 (2001 edition) */ NTD_SYSTEM_ERROR_2BIG, NTD_SYSTEM_ERROR_ACCES, NTD_SYSTEM_ERROR_ADDRINUSE, NTD_SYSTEM_ERROR_ADDRNOTAVAIL, NTD_SYSTEM_ERROR_AFNOSUPPORT, NTD_SYSTEM_ERROR_AGAIN, NTD_SYSTEM_ERROR_ALREADY, NTD_SYSTEM_ERROR_BADF, NTD_SYSTEM_ERROR_BADMSG, NTD_SYSTEM_ERROR_BUSY, NTD_SYSTEM_ERROR_CANCELED, NTD_SYSTEM_ERROR_CHILD, NTD_SYSTEM_ERROR_CONNABORTED, NTD_SYSTEM_ERROR_CONNREFUSED, NTD_SYSTEM_ERROR_CONNRESET, NTD_SYSTEM_ERROR_DEADLK, NTD_SYSTEM_ERROR_DESTADDRREQ, NTD_SYSTEM_ERROR_DOM, NTD_SYSTEM_ERROR_EXIST, NTD_SYSTEM_ERROR_FAULT, NTD_SYSTEM_ERROR_FBIG, NTD_SYSTEM_ERROR_HOSTUNREACH, NTD_SYSTEM_ERROR_IDRM, NTD_SYSTEM_ERROR_ILSEQ, NTD_SYSTEM_ERROR_INPROGRESS, NTD_SYSTEM_ERROR_INTR, NTD_SYSTEM_ERROR_INVAL, NTD_SYSTEM_ERROR_IO, NTD_SYSTEM_ERROR_ISCONN, NTD_SYSTEM_ERROR_ISDIR, NTD_SYSTEM_ERROR_LOOP, NTD_SYSTEM_ERROR_MFILE, NTD_SYSTEM_ERROR_MLINK, NTD_SYSTEM_ERROR_MSGSIZE, NTD_SYSTEM_ERROR_NAMETOOLONG, NTD_SYSTEM_ERROR_NETDOWN, NTD_SYSTEM_ERROR_NETRESET, NTD_SYSTEM_ERROR_NETUNREACH, NTD_SYSTEM_ERROR_NFILE, NTD_SYSTEM_ERROR_NOBUFS, NTD_SYSTEM_ERROR_NODATA, NTD_SYSTEM_ERROR_NODEV, NTD_SYSTEM_ERROR_NOENT, NTD_SYSTEM_ERROR_NOEXEC, NTD_SYSTEM_ERROR_NOLCK, NTD_SYSTEM_ERROR_NOMEM, NTD_SYSTEM_ERROR_NOMSG, NTD_SYSTEM_ERROR_NOPROTOOPT, NTD_SYSTEM_ERROR_NOSPC, NTD_SYSTEM_ERROR_NOSR, NTD_SYSTEM_ERROR_NOSTR, NTD_SYSTEM_ERROR_NOSYS, NTD_SYSTEM_ERROR_NOTCONN, NTD_SYSTEM_ERROR_NOTDIR, NTD_SYSTEM_ERROR_NOTEMPTY, NTD_SYSTEM_ERROR_NOTSOCK, NTD_SYSTEM_ERROR_NOTSUP, NTD_SYSTEM_ERROR_NOTTY, NTD_SYSTEM_ERROR_NXIO, NTD_SYSTEM_ERROR_OPNOTSUPP, NTD_SYSTEM_ERROR_OVERFLOW, NTD_SYSTEM_ERROR_PERM, NTD_SYSTEM_ERROR_PIPE, NTD_SYSTEM_ERROR_PROTO, NTD_SYSTEM_ERROR_PROTONOSUPPORT, NTD_SYSTEM_ERROR_PROTOTYPE, NTD_SYSTEM_ERROR_RANGE, NTD_SYSTEM_ERROR_ROFS, NTD_SYSTEM_ERROR_SPIPE, NTD_SYSTEM_ERROR_SRCH, NTD_SYSTEM_ERROR_TIME, NTD_SYSTEM_ERROR_TIMEDOUT, NTD_SYSTEM_ERROR_TXTBSY, NTD_SYSTEM_ERROR_XDEV } NtdSystemError;
Abstraction of the platform dependent error codes. This implementation should be in-line with POSIX.1-2001.
No error present | |
Generic failure | |
Argument list too long | |
Permission denied | |
Address already in use | |
Cannot assign requested address | |
Address family not supported by protocol | |
Try again | |
Operation already in progress | |
Bad file number | |
Not a data message | |
Device or resource busy | |
Operation Canceled | |
No child processes | |
Software caused connection abort | |
Connection refused | |
Connection reset by peer | |
Resource deadlock would occur | |
Destination address required | |
Math argument out of domain of func | |
File exists | |
Bad address | |
File too large | |
No route to host | |
Identifier removed
NTD_SYSTEM_ERROR_DEADLOCK EDEADLK
|
|
Illegal byte sequence | |
Operation now in progress | |
Interrupted system call | |
Invalid argument | |
I/O error | |
Transport endpoint is already connected | |
Is a directory | |
Too many symbolic links encountered | |
Too many open files | |
Too many links | |
Message too long | |
File name too long | |
Network is down | |
Network dropped connection because of reset | |
Network is unreachable | |
File table overflow | |
No buffer space available | |
No data available | |
No such device | |
No such file or directory | |
Exec format error | |
No record locks available | |
Out of memory | |
No message of desired type | |
Protocol not available | |
No space left on device | |
Out of streams resources | |
Device not a stream | |
Function not implemented | |
Transport endpoint is not connected | |
Not a directory | |
Directory not empty | |
Socket operation on non-socket | |
Operation not supported on transport endpoint | |
Not a typewriter | |
No such device or address | |
Operation not supported on transport endpoint | |
Value too large for defined data type | |
Operation not permitted | |
Broken pipe | |
Protocol error | |
Protocol not supported | |
Protocol wrong type for socket | |
Math result not representable | |
Read-only file system | |
Illegal seek | |
No such process | |
Timer expired | |
Connection timed out | |
Text file busy | |
Cross-device link |
NtdSystemError ntd_system_get_error (void
);
Gets the current NtdSystemError error code from the system.
Returns : |
the NtdSystemError of the current system error,
or NTD_SYSTEM_ERROR_NONE if there are no system errors. |
gchar * ntd_system_get_error_message (NtdSystemError error_code
);
Gets the description of the specified system error.
If the error_code
has no meaning for the operating system, this
function returns NULL
.
|
the error code to convert. |
Returns : |
a newly allocated string containig the error message. This string must be freed when no longer used. TODO: Implement a reentrant version. |
gboolean ntd_system_set_error (GError **error
,const gchar *format
,...
);
Sets error
to the properly system error, if there is
one active. The optional format string is appended
to the standard system error message.
If there are no system errors, this function does
nothing and return FALSE
.
After the error is set, a ntd_system_clear_error()
call
is performed to clear the system error.
gboolean ntd_system_set_errorv (GError **error
,const gchar *format
,va_list args
);
Wrapper to ntd_system_set_error()
with va_list argument.
void ntd_system_set_error_with_code (GError **error
,NtdSystemError error_code
,const gchar *format
,...
);
Sets error
to the specified system error, exactly
in the same way the ntd_system_set_error()
function does.
Of course, in this case the error_code
is not system
dependent, so no ntd_system_clear_error()
call is performed
and nothing is returned.
Calling this function with NTD_SYSTEM_ERROR_NONE as the
error_code
it is equivalent to call g_clear_error()
on error
.
|
a pointer to the destination GError*. |
|
the specific system error code to set. |
|
printf-style format string. |
|
parameters for format string. |
void ntd_system_set_errorv_with_code (GError **error
,NtdSystemError error_code
,const gchar *format
,va_list args
);
Wrapper to ntd_system_set_error_with_code()
with va_list argument.
|
a pointer to the destination GError*. |
|
the specific system error code to set. |
|
printf-style format string. |
|
parameters for format string. |
void ntd_system_clear_error (void
);
Resets the system for any pending error.
void ntd_set_verbose_mode (gboolean new_status
);
Enables (if new_status
is TRUE
) or disables (if new_status
is FALSE
) the verbosity mode. In verbose mode, data sent to
or received from the device is output to stdout.
|
new verbosity status |
gchar * ntd_escape (gconstpointer buffer
,gsize nbytes
);
Generates a printable representation of the first nbytes
bytes of buffer
. This is done by escaping all non-printable
chars.
The buffer is split on the '\0' delimiters. Every segment in
the resulting list of strings is then escaped with
g_strescape()
. The final list is then joined with the "\\000"
string (octal representation of '\0'): at the end, all non-printable
characters (NUL bytes included) are properly escaped.
|
a buffer |
|
size of the buffer |
Returns : |
a newly allocated string: free with g_free()
when no longer needed. |
gulong ntd_checksum (gconstpointer data
,gsize nbytes
);
Sums the first nbytes
bytes of data
and returns the result.
No checks against arithmetic overflows are performed.
|
binary buffer |
|
size (in bytes) of the data |
Returns : |
the computed checksum |
gchar * ntd_find_file (const gchar *file
,...
);
Searches file
in the provided paths and returns the full
path to the first existing match. The check is performed
using g_file_test()
with the G_FILE_TEST_EXISTS test.
|
the file to search |
|
a NULL terminated list of paths where to look for file existence. |
Returns : |
a newly allocated string containing the path
or NULL on errors. Free it with g_free() when
no longer needed. |
void ntd_string_free (GString *string
,gpointer *p_buffer
,gsize *p_len
);
A g_string_free()
version that returns either the buffer in
whatever p_buffer
and its length in p_len
. Both of them
can be NULL
, in which case the data is not returned (but
it is freed anyway).
Furthermore, the case where string
is NULL
is handled
gracefully: p_buffer
and p_len
are set to NULL
and 0
respectively (if possible).
void ntd_free_and_nullify (gpointer *mem
);
Convenient function to free mem
with g_free()
and set
it to NULL
.
|
pointer to the pointer to free. |
gchar * ntd_uuencode (gconstpointer data
,gsize nbytes
);
Converts nbytes
bytes from data
to their uu-encoded version.