Man page of lid_strerror(3) and lid_errno

Index


NAME

lid_strerror - return a string describing an error number

SYNOPSIS

C/C++ #include <lid.h>

 extern int lid_errno;

 const char * lid_strerror(int lid_errno);

DESCRIPTION

lid utilizes a concept similar to the traditional errno(3) in order to assist programmers to easily detect, classify and report errors. This way, error recovery can be done in a convenient and common way.

lid.h defines the global integer variable lid_errno. Whenever an error occurs, it is set to a value indicating the kind of error.

lid_strerror() is used to translate the error number lid_errno, that has to be passed as an argument, into a natural language string.

RETURN VALUE

lid_strerror() returns a pointer to a read-only string describing the error with the number lid_errno.

ERRORS

lid uses the following error definitions:

LID_ENOERR

"No error"

LID_ENOMEM

Memory allocation failed: "Out of memory"

LID_EFOPEN

Error opening an input file: "Failed to open file"

LID_EFCLOSE

Error closing an input file: "Failed to close file"

LID_EFIO

File IO error: "File input/output error"

LID_EMATH

Internal calculation failed: "Math error"

LID_ESHORT

Input too short: "Insufficient input length"

LID_EUDEC

"UTF decoding failed"

LID_EUENC

"UTF encoding failed"

LID_EUINV

"Invalid Unicode sequence"

LID_EWCCONV

"Wide character conversion error"

LID_EBINARY

"Binary input data"

LID_EARG

"Invalid argument"

LID_EUNDEF

"Undefined error"

EXAMPLES

The following example application, lid_example, which is included in the distribution, takes a set of filenames as commandline arguments and uses lid_ffile() to determine their language and encoding. Error checks are done, the results are printed and the memory used by the results data structures is freed using lid_free(3).

C/C++ #include <stdio.h>
 #include <lid.h>

 int main (int argc, char *argv[])
 {
     lid_t *res = NULL;
     int    i   = 0;

     for (i = 1; i < argc; i++)
     {
        res = lid_ffile(argv[i]);

        if (res == NULL)
        {
            fprintf(stderr, "%s: %s\n",
                argv[i], lid_strerror(lid_errno));
            return 1;
        }

        printf("%s: lang=%s, enc=%s, iso=%s\n",
            argv[i], res->language, res->encoding, res->isocode);

        lid_free(res);
    }

    return 0;
 }

Here's the output of an example execution of the application:

 $ ./lid_example /tmp/english.txt /tmp/german.txt  /dev/null
 /tmp/english.txt: lang=English, enc=ASCII, iso=eng
 /tmp/german.txt: lang=German, enc=UTF-8, iso=deu
 /dev/null: Insufficient input length.

NOTES

lid_errno is reset to LID_ENOERR whenever one of the following functions is called: lid_ffile(), lid_fstr(), lid_fwstr() or lid_fnstr().

SEE ALSO

lid_ffile(3), lid_fstr(3), lid_fwstr(3), lid_fnstr(3)