configure: Check for error.h

For portability, check for error.h during configure and define
HAVE_ERROR_H accordingly.

If this header is not available, emulate the functionality of error()
from glibc with an inline wrapper in include/c.h.
This commit is contained in:
Rainer Müller 2013-02-20 20:14:29 +01:00
parent 6df4fc403d
commit 838e5d8941
3 changed files with 29 additions and 1 deletions

View File

@ -137,6 +137,8 @@ dnl else
dnl ALL_LINGUAS="af am ar as be bg bn_IN bn ca cs cy da de el en_GB es et eu_ES fa fi fr gl gu he hi hr hu hy id is it ja ka kn ko ku lo lt lv mk ml mr ms my nb nl nn no nso or pa pl pt_BR pt ro ru si sk sl sq sr@Latn sr sv ta te th tr uk ur vi zh_CN zh_TW zu"
dnl fi
AC_CHECK_HEADERS(error.h, [], [], AC_INCLUDES_DEFAULT)
AC_CHECK_HEADERS(stdio_ext.h, [], [], AC_INCLUDES_DEFAULT)
AC_MSG_CHECKING(whether program_invocation_name is defined)

View File

@ -16,7 +16,11 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_ERROR_H
#include <error.h>
#else
#include <stdarg.h>
#endif
/*
* Compiler specific stuff
@ -103,6 +107,23 @@ static inline char *prog_inv_sh_nm_from_file(char *f, char stripext)
/*
* Error printing.
*/
#ifndef HAVE_ERROR_H
/* Emulate the error() function from glibc */
__attribute__((__format__(__printf__, 3, 4)))
static void error(int status, int errnum, const char *format, ...)
{
va_list argp;
fprintf(stderr, "%s: ", program_invocation_short_name);
va_start(argp, format);
vfprintf(stderr, format, argp);
va_end(argp);
if (errnum != 0)
fprintf(stderr, ": error code %d", errnum);
fprintf(stderr, "\n");
if (status != 0)
exit(status);
}
#endif
#define xwarn(...) error(0, errno, __VA_ARGS__)
#define xwarnx(...) error(0, 0, __VA_ARGS__)
#define xerr(STATUS, ...) error(STATUS, errno, __VA_ARGS__)

View File

@ -1,5 +1,7 @@
#include <errno.h>
#include <error.h>
#ifdef HAVE_ERROR_H
# include <error.h>
#endif
#ifdef HAVE_STDIO_EXT_H
# include <stdio_ext.h>
#else
@ -12,6 +14,9 @@
#include "nls.h"
#include "fileutils.h"
#ifndef HAVE_ERROR_H
# include "c.h" /* for error() emulation */
#endif
int close_stream(FILE * stream)
{