/* * The Npic library * * Copyright (C) 2003 Edouard Thiel * * This library is free software under the terms of the * GNU Lesser General Public License (LGPL) version 2.1. */ /* * errors.c - 09/01/2003 * * Error messages */ #include /*--------------------- P U B L I C - I N T E R F A C E ----------------------*/ /* * Return error message from error-code err. */ const char *NpicStrErr (int err) { switch (err) { case NPIC_SUCCESS : return "success"; case NPIC_ERROR : return "error"; case NPIC_ERR_NULL_PTR : return "null pointer error"; case NPIC_ERR_NOT_INIT : return "struct not initialized"; case NPIC_ERR_UNEX_NPIC : return "unexpected Npic_image type"; case NPIC_ERR_UNEX_TYPE : return "unexpected data type"; case NPIC_ERR_NOT_OK : return "object not ok"; case NPIC_ERR_EMPTY_STR : return "empty string"; case NPIC_ERR_NOT_FOUND : return "not found"; case NPIC_ERR_BAD_SIZE : return "bad size error"; case NPIC_ERR_INCOMPAT : return "datas are incompatible"; case NPIC_ERR_BAD_CONV : return "unsuported conversion"; case NPIC_ERR_BAD_SRC : return "bad source object"; case NPIC_ERR_BAD_EXT : return "bad extension"; case NPIC_ERR_UNAV_FORMAT : return "unavailable format"; case NPIC_ERR_UNAV_DIST : return "unavailable distance"; case NPIC_ERR_MALLOC : return "malloc error"; case NPIC_ERR_REALLOC : return "realloc error"; case NPIC_ERR_STRDUP : return "strdup error"; case NPIC_ERR_MAGIC : return "bad magic value"; case NPIC_ERR_VERSION : return "bad version"; case NPIC_ERR_HEADER : return "bad header"; case NPIC_ERR_ENDIAN : return "bad endianness"; case NPIC_ERR_FLOAT : return "bad float format"; case NPIC_ERR_OPEN : return "file open error"; case NPIC_ERR_READ : return "read error"; case NPIC_ERR_WRITE : return "write error"; case NPIC_ERR_BAD_FD : return "bad fd error"; case NPIC_ERR_DUP_FD : return "dup fd error"; case NPIC_ERR_GETPOS : return "getpos or ftell error"; case NPIC_ERR_SETPOS : return "setpos or lseek error"; case NPIC_ERR_FDOPEN : return "fdopen error"; case NPIC_ERR_PIPE : return "pipe creation error"; case NPIC_ERR_FORK : return "fork error"; case NPIC_ERR_EXEC : return "exec error"; case NPIC_ERR_CHILD : return "child failed"; case NPIC_ERR_SLICE_RG : return "slice out of range"; case NPIC_ERR_BAND_NB : return "bad band number"; default : return "error with bad code"; } } /* * Return err and, if err != NPIC_SUCCESS, print error message on stderr: * - the string "libNpic", then * - the name of the function (funcname) if non empty, then * - the string message corresponding to err, then * - the formatted message, if non empty (same usage as printf), then * - a newline. * * USAGE: * err = myfunc(); * if (err != NPIC_SUCCESS) return NpicError ("myfunc", err, ""); * * err = loadfile (filename); * if (err != NPIC_SUCCESS) return NpicError ("loadfile", err, " in \"%s\"", filename); */ int NpicError (const char *funcname, int err, const char *format, ...) { if (err != NPIC_SUCCESS) { fprintf (stderr, "### libNpic: "); if (funcname && funcname[0]) fprintf (stderr, "%s(): ", funcname); fprintf (stderr, "%s", NpicStrErr (err)); if (format && format[0]) { va_list ap; va_start (ap, format); vfprintf (stderr, format, ap); va_end (ap); } fprintf (stderr, "\n"); } return err; }