libexplain  1.4.D001
Defines | Functions
libexplain/iconv_or_die.c File Reference
#include <libexplain/ac/errno.h>
#include <libexplain/ac/iconv.h>
#include <libexplain/iconv.h>
#include <libexplain/output.h>

Go to the source code of this file.

Defines

#define ICONV_FAIL   ((size_t)(-1))

Functions

size_t explain_iconv_or_die (iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
size_t explain_iconv_on_error (iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)

Define Documentation

#define ICONV_FAIL   ((size_t)(-1))

Definition at line 26 of file iconv_or_die.c.


Function Documentation

size_t explain_iconv_on_error ( iconv_t  cd,
char **  inbuf,
size_t *  inbytesleft,
char **  outbuf,
size_t *  outbytesleft 
)

The explain_iconv_on_error function is used to call the iconv(3) system call. On failure an explanation will be printed to stderr, obtained from the explain_iconv(3) function.

Parameters:
cdThe cd, exactly as to be passed to the iconv(3) system call.
inbufThe inbuf, exactly as to be passed to the iconv(3) system call.
inbytesleftThe inbytesleft, exactly as to be passed to the iconv(3) system call.
outbufThe outbuf, exactly as to be passed to the iconv(3) system call.
outbytesleftThe outbytesleft, exactly as to be passed to the iconv(3) system call.
Returns:
The value returned by the wrapped iconv(3) system call.
Example:
This function is intended to be used in a fashion similar to the following example:
 errno = 0;
 size_t result = explain_iconv_on_error(cd, inbuf, inbytesleft, outbuf,
     outbytesleft);
 if (result < 0 && errno != 0)
 {
     ...cope with error
     ...no need to print error message
 }

Definition at line 50 of file iconv_or_die.c.

size_t explain_iconv_or_die ( iconv_t  cd,
char **  inbuf,
size_t *  inbytesleft,
char **  outbuf,
size_t *  outbytesleft 
)

The explain_iconv_or_die function is used to call the iconv(3) system call. On failure an explanation will be printed to stderr, obtained from the explain_iconv(3) function, and then the process terminates by calling exit(EXIT_FAILURE).

Parameters:
cdThe cd, exactly as to be passed to the iconv(3) system call.
inbufThe inbuf, exactly as to be passed to the iconv(3) system call.
inbytesleftThe inbytesleft, exactly as to be passed to the iconv(3) system call.
outbufThe outbuf, exactly as to be passed to the iconv(3) system call.
outbytesleftThe outbytesleft, exactly as to be passed to the iconv(3) system call.
Returns:
This function only returns on success, see iconv(3) for more information. On failure, prints an explanation and exits, it does not return.
Example:
This function is intended to be used in a fashion similar to the following example:
 size_t result = explain_iconv_or_die(cd, inbuf, inbytesleft, outbuf,
     outbytesleft);

Definition at line 30 of file iconv_or_die.c.