From e31855d7e670438402e7a05f1ef8067476bf563b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rainer=20M=C3=BCller?= <raimue@codingfarm.de>
Date: Wed, 20 Feb 2013 20:14:29 +0100
Subject: [PATCH 4/4] 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.
---
configure.ac | 2 ++
include/c.h | 21 +++++++++++++++++++++
lib/fileutils.c | 7 ++++++-
3 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 08f59e3..6e0883b 100644
a
|
b
|
dnl else |
137 | 137 | 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" |
138 | 138 | dnl fi |
139 | 139 | |
| 140 | AC_CHECK_HEADERS(error.h, [], [], AC_INCLUDES_DEFAULT) |
| 141 | |
140 | 142 | AC_CHECK_HEADERS(stdio_ext.h, [], [], AC_INCLUDES_DEFAULT) |
141 | 143 | |
142 | 144 | AC_MSG_CHECKING(whether program_invocation_name is defined) |
diff --git a/include/c.h b/include/c.h
index 737630b..6bcdf5f 100644
a
|
b
|
|
16 | 16 | #include <stdlib.h> |
17 | 17 | #include <string.h> |
18 | 18 | #include <errno.h> |
| 19 | #ifdef HAVE_ERROR_H |
19 | 20 | #include <error.h> |
| 21 | #else |
| 22 | #include <stdarg.h> |
| 23 | #endif |
20 | 24 | |
21 | 25 | /* |
22 | 26 | * Compiler specific stuff |
… |
… |
static inline char *prog_inv_sh_nm_from_file(char *f, char stripext) |
103 | 107 | /* |
104 | 108 | * Error printing. |
105 | 109 | */ |
| 110 | #ifndef HAVE_ERROR_H |
| 111 | /* Emulate the error() function from glibc */ |
| 112 | __attribute__((__format__(__printf__, 3, 4))) |
| 113 | static void error(int status, int errnum, const char *format, ...) |
| 114 | { |
| 115 | va_list argp; |
| 116 | fprintf(stderr, "%s: ", program_invocation_short_name); |
| 117 | va_start(argp, format); |
| 118 | vfprintf(stderr, format, argp); |
| 119 | va_end(argp); |
| 120 | if (errnum != 0) |
| 121 | fprintf(stderr, ": error code %d", errnum); |
| 122 | fprintf(stderr, "\n"); |
| 123 | if (status != 0) |
| 124 | exit(status); |
| 125 | } |
| 126 | #endif |
106 | 127 | #define xwarn(...) error(0, errno, __VA_ARGS__) |
107 | 128 | #define xwarnx(...) error(0, 0, __VA_ARGS__) |
108 | 129 | #define xerr(STATUS, ...) error(STATUS, errno, __VA_ARGS__) |
diff --git a/lib/fileutils.c b/lib/fileutils.c
index c50d6aa..a9ef2ff 100644
a
|
b
|
|
1 | 1 | #include <errno.h> |
2 | | #include <error.h> |
| 2 | #ifdef HAVE_ERROR_H |
| 3 | # include <error.h> |
| 4 | #endif |
3 | 5 | #ifdef HAVE_STDIO_EXT_H |
4 | 6 | # include <stdio_ext.h> |
5 | 7 | #else |
… |
… |
|
12 | 14 | |
13 | 15 | #include "nls.h" |
14 | 16 | #include "fileutils.h" |
| 17 | #ifndef HAVE_ERROR_H |
| 18 | # include "c.h" /* for error() emulation */ |
| 19 | #endif |
15 | 20 | |
16 | 21 | int close_stream(FILE * stream) |
17 | 22 | { |