Synopsis

#define             NTD_SYSTEM_ERROR
enum                NtdSystemError;
gulong              ntd_checksum                        (gconstpointer data,
                                                         gsize nbytes);
void                ntd_debug                           (const gchar *format,
                                                         ...);
#define             ntd_empty                           (string)
void                ntd_enable_debug                    (gboolean new_state);
gchar *             ntd_find_file                       (const gchar *file,
                                                         ...);
void                ntd_free_and_nullify                (gpointer *mem);
#define             ntd_log_pileup                      (err)
#define             ntd_return_on_pileup                (err)
#define             ntd_return_val_on_pileup            (err,
                                                         val)
void                ntd_system_clear_error              (void);
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,
                                                         ...);
void                ntd_system_set_error_with_code      (GError **error,
                                                         NtdSystemError error_code,
                                                         const gchar *format,
                                                         ...);
gboolean            ntd_system_set_errorv               (GError **error,
                                                         const gchar *format,
                                                         va_list args);
void                ntd_system_set_errorv_with_code     (GError **error,
                                                         NtdSystemError error_code,
                                                         const gchar *format,
                                                         va_list args);
gboolean            ntd_uudecode                        (const gchar *encoded,
                                                         gpointer *p_data,
                                                         gsize *p_nbytes);
const gchar *       ntd_uuencode                        (gconstpointer data,
                                                         gsize nbytes);

Description

Collection of macros and functions that do not fit inside any other topic.

Details

NTD_SYSTEM_ERROR

#define NTD_SYSTEM_ERROR        ntd_system_error_quark()

enum NtdSystemError

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_NOTCON,
    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;

ntd_checksum ()

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.

data :

binary buffer

nbytes :

size (in bytes) of the data

Returns :

the computed checksum

ntd_debug ()

void                ntd_debug                           (const gchar *format,
                                                         ...);

Outputs to stdout the passed in string if the debug flag has been set with ntd_enable_debug().

format :

a printf-like format string

... :

optional additional arguments

ntd_empty()

#define             ntd_empty(string)

Checks wheter string is empty, that is if string is NULL or if its first char is '\0'.

string :

char pointer

Returns :

TRUE is string is NULL or if string[0] is '\0', FALSE otherwise.

ntd_enable_debug ()

void                ntd_enable_debug                    (gboolean new_state);

Enables (TRUE) or disables (FALSE) the internal debug flag of the ntd-isp library.

new_state :

new state of the debug flag

ntd_find_file ()

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.

file :

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.

ntd_free_and_nullify ()

void                ntd_free_and_nullify                (gpointer *mem);

Convenient function to free mem with g_free() and set it to NULL.

mem :

pointer to the pointer to free.

ntd_log_pileup()

#define             ntd_log_pileup(err)

ntd_return_on_pileup()

#define             ntd_return_on_pileup(err)

ntd_return_val_on_pileup()

#define             ntd_return_val_on_pileup(err,val)

ntd_system_clear_error ()

void                ntd_system_clear_error              (void);

Resets the system for any pending error.


ntd_system_error_quark ()

GQuark              ntd_system_error_quark              (void);

ntd_system_get_error ()

NtdSystemError      ntd_system_get_error                (void);

Gets the current NtdSystemError error code from the system.

Returns :

the NtdIOError of the current system error, or NTD_SYSTEM_ERROR_NONE if there are no system errors.

ntd_system_get_error_message ()

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.

error_code :

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.

ntd_system_set_error ()

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.

error :

a pointer to the destination GError*.

format :

printf-style format string.

... :

parameters for format string.

Returns :

TRUE if there is a system error, FALSE otherwise.

ntd_system_set_error_with_code ()

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.

error :

a pointer to the destination GError*.

error_code :

the specific system error code to set.

format :

printf-style format string.

... :

parameters for format string.

ntd_system_set_errorv ()

gboolean            ntd_system_set_errorv               (GError **error,
                                                         const gchar *format,
                                                         va_list args);

Wrapper to ntd_system_set_error() with va_list argument.

error :

a pointer to the destination GError*.

format :

printf-style format string.

args :

parameters for format string.

Returns :

TRUE if there is a system error, FALSE otherwise.

ntd_system_set_errorv_with_code ()

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.

error :

a pointer to the destination GError*.

error_code :

the specific system error code to set.

format :

printf-style format string.

args :

parameters for format string.

ntd_uudecode ()

gboolean            ntd_uudecode                        (const gchar *encoded,
                                                         gpointer *p_data,
                                                         gsize *p_nbytes);

Decodes the encoded string and returns the decoded result in p_nbytes and p_data. Either p_nbytes and p_data can be NULL, in which case the respective result will not be returned.

encoded :

'\0' terminated buffer of UU-encoded data

p_data :

pointer to the destination buffer to allocate

p_nbytes :

pointer to the destination size (in bytes) of the data

Returns :

TRUE on success, FALSE on error.

ntd_uuencode ()

const gchar *       ntd_uuencode                        (gconstpointer data,
                                                         gsize nbytes);

Converts nbytes bytes from data to their uu-encoded version. The returned string is owned by the library and must not be modified or freed.

data :

original binary buffer

nbytes :

size (in bytes) of the data

Returns :

an uu-encoded '\0' termined string or NULL on errors.