build-sys: provide alternatives for err, errx, warn and warnx

Solaris lacks err, errx, warn and warnx.  This also means the err.h header
doesn't exist.  Removed err.h include from all files, and included err.h from
c.h instead if it exists, otherwise alternatives are provided.

Signed-off-by: Fabian Groffen <grobian@gentoo.org>
This commit is contained in:
Fabian Groffen 2011-01-25 22:44:52 +01:00 committed by Karel Zak
parent 4a01477b12
commit eb76ca98b0
52 changed files with 84 additions and 52 deletions

View File

@ -175,6 +175,8 @@ AC_CHECK_DECL([lseek64],
AC_CHECK_FUNCS(
[inet_aton \
err \
errx \
futimens \
fstat64 \
fsync \
@ -204,6 +206,8 @@ AC_CHECK_FUNCS(
posix_fadvise \
getmntinfo \
__secure_getenv \
warn \
warnx \
rpmatch])
AC_FUNC_FSEEKO

View File

@ -18,7 +18,6 @@
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <err.h>
#include <blkid.h>
#include <getopt.h>

View File

@ -6,6 +6,15 @@
#define UTIL_LINUX_C_H
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_ERR_H
# include <err.h>
#endif
/*
* Compiler specific stuff
@ -95,6 +104,44 @@
#endif
#ifndef HAVE_ERR_H
static inline void
errmsg(char doexit, int excode, char adderr, const char *fmt, ...)
{
fprintf(stderr, "%s: ", program_invocation_short_name);
if (fmt != NULL) {
va_list argp;
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
va_end(argp);
if (adderr)
fprintf(stderr, ": ");
}
if (adderr)
fprintf(stderr, "%s", strerror(errno));
fprintf(stderr, "\n");
if (doexit)
exit(excode);
}
#ifndef HAVE_ERR
# define err(E, FMT...) errmsg(1, E, 1, FMT)
#endif
#ifndef HAVE_ERRX
# define errx(E, FMT...) errmsg(1, E, 0, FMT)
#endif
#ifndef HAVE_WARN
# define warn(FMT...) errmsg(0, 0, 1, FMT)
#endif
#ifndef HAVE_WARNX
# define warnx(FMT...) errmsg(0, 0, 0, FMT)
#endif
#endif /* !HAVE_ERR_H */
static inline __attribute__((const)) int is_power_of_2(unsigned long num)
{
return (num != 0 && ((num & (num - 1)) == 0));

View File

@ -11,7 +11,6 @@
#define UTIL_LINUX_XALLOC_H
#include <stdlib.h>
#include <err.h>
#include <string.h>
#include "c.h"

View File

@ -9,6 +9,7 @@
#include <sys/stat.h>
#include "at.h"
#include "c.h"
int fstat_at(int dir, const char *dirname, const char *filename,
struct stat *st, int nofollow)
@ -56,7 +57,6 @@ FILE *fopen_at(int dir, const char *dirname, const char *filename, int flags,
}
#ifdef TEST_PROGRAM
#include <err.h>
#include <errno.h>
#include <sys/types.h>
#include <dirent.h>

View File

@ -22,6 +22,7 @@
#include "blkdev.h"
#include "linux_version.h"
#include "c.h"
static long
blkdev_valid_offset (int fd, off_t offset) {
@ -208,7 +209,6 @@ blkdev_get_sector_size(int fd, int *sector_size)
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <err.h>
int
main(int argc, char **argv)
{

View File

@ -20,6 +20,7 @@
#include <sys/syscall.h>
#include "cpuset.h"
#include "c.h"
static inline int val_to_char(int v)
{
@ -303,7 +304,6 @@ int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize)
#ifdef TEST_PROGRAM
#include <err.h>
#include <getopt.h>
int main(int argc, char *argv[])

View File

@ -11,6 +11,7 @@
#include <ctype.h>
#include "mangle.h"
#include "c.h"
#define isoctal(a) (((a) & ~7) == '0')
@ -103,7 +104,6 @@ char *unmangle(const char *s, char **end)
}
#ifdef TEST_PROGRAM
#include <err.h>
#include <errno.h>
int main(int argc, char *argv[])
{

View File

@ -8,10 +8,10 @@
#include <inttypes.h>
#include <ctype.h>
#include <errno.h>
#include <err.h>
#include <sys/stat.h>
#include <locale.h>
#include <string.h>
#include "c.h"
static int do_scale_by_power (uintmax_t *x, int base, int power)
{

View File

@ -709,7 +709,6 @@ int tt_parse_columns_list(const char *list, int cols[], int *ncols,
}
#ifdef TEST_PROGRAM
#include <err.h>
#include <errno.h>
enum { MYCOL_NAME, MYCOL_FOO, MYCOL_BAR, MYCOL_PATH };

View File

@ -30,7 +30,6 @@
#include <unistd.h>
#include <pwd.h>
#include <errno.h>
#include <err.h>
#include <ctype.h>
#include <getopt.h>
@ -44,6 +43,7 @@
#include "nls.h"
#include "env.h"
#include "xalloc.h"
#include "c.h"
#ifdef HAVE_LIBSELINUX
#include <selinux/selinux.h>

View File

@ -22,7 +22,6 @@
*
*
*/
#include <err.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>

View File

@ -29,7 +29,6 @@
/*
* last
*/
#include <err.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/file.h>
@ -51,6 +50,7 @@
#include "pathnames.h"
#include "nls.h"
#include "xalloc.h"
#include "c.h"
#define SECDAY (24*60*60) /* seconds in a day */
#define NO 0 /* false/no */

View File

@ -97,7 +97,6 @@
#include <sys/wait.h>
#include <signal.h>
#include <errno.h>
#include <err.h>
#include <grp.h>
#include <pwd.h>
#include <utmp.h>
@ -120,6 +119,7 @@
#include "strutils.h"
#include "nls.h"
#include "xalloc.h"
#include "c.h"
#ifdef HAVE_SECURITY_PAM_MISC_H
# include <security/pam_appl.h>

View File

@ -46,7 +46,6 @@
* - cleanups
*/
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@ -55,6 +54,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "nls.h"
#include "c.h"
/* exit codes */

View File

@ -14,7 +14,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <err.h>
#ifdef HAVE_CRYPT_H
#include <crypt.h>

View File

@ -60,13 +60,13 @@ static char version_string[] = "vipw 1.4";
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <err.h>
#include <paths.h>
#include <unistd.h>
#include "setpwnam.h"
#include "strutils.h"
#include "nls.h"
#include "c.h"
#ifdef HAVE_LIBSELINUX
#include <selinux/selinux.h>

View File

@ -47,7 +47,6 @@
#include <sys/time.h>
#include <sys/uio.h>
#include <err.h>
#include <errno.h>
#include <paths.h>
#include <ctype.h>
@ -65,6 +64,7 @@
#include "ttymsg.h"
#include "pathnames.h"
#include "carefulputc.h"
#include "c.h"
void makemsg __P((char *));

View File

@ -63,7 +63,6 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <err.h>
#include <errno.h>
#include "c.h"

View File

@ -8,11 +8,11 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <err.h>
#include <blkid.h>
#include "nls.h"
#include "c.h"
static void __attribute__((__noreturn__)) usage(int rc)
{

View File

@ -21,7 +21,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <err.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>

View File

@ -31,7 +31,6 @@
#include <dirent.h>
#include <fcntl.h>
#include <string.h>
#include <err.h>
#include <sys/ioctl.h>
#include <inttypes.h>
#include <stdarg.h>
@ -51,6 +50,7 @@
#include "tt.h"
#include "xalloc.h"
#include "strutils.h"
#include "c.h"
/* column IDs */
enum {

View File

@ -30,7 +30,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <err.h>
#include <pwd.h>
#include <grp.h>

View File

@ -26,9 +26,9 @@
#include <math.h>
#include <sys/select.h>
#include <unistd.h>
#include <err.h>
#include "nls.h"
#include "c.h"
#define SCRIPT_MIN_DELAY 0.0001 /* from original sripreplay.pl */

View File

@ -27,7 +27,6 @@
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <err.h>
#include <string.h>
#include <limits.h>
@ -37,6 +36,7 @@
#include "xalloc.h"
#include "strutils.h"
#include "writeall.h"
#include "c.h"
struct wipe_desc {
loff_t offset; /* magic string offset */

View File

@ -13,7 +13,6 @@
#include <sys/wait.h>
#include <fcntl.h>
#include <stdint.h>
#include <err.h>
#include <ctype.h>
#include "bitops.h"
@ -25,6 +24,7 @@
#include "swapheader.h"
#include "mangle.h"
#include "canonicalize.h"
#include "c.h"
#define PATH_MKSWAP "/sbin/mkswap"

View File

@ -13,7 +13,6 @@
#include <stdio.h>
#include <fcntl.h>
#include <err.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>

View File

@ -27,7 +27,6 @@
#include <unistd.h>
#include <getopt.h>
#include <errno.h>
#include <err.h>
#include "c.h"
#include "nls.h"

View File

@ -12,11 +12,10 @@
#include <getopt.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <err.h>
#include "nls.h"
#include "strutils.h"
#include "c.h"
static int tolerant;

View File

@ -24,12 +24,11 @@
#include <unistd.h>
#include <getopt.h>
#include <errno.h>
#include <err.h>
#include "cpuset.h"
#include "nls.h"
#include "strutils.h"
#include "c.h"
static void __attribute__((__noreturn__)) usage(FILE *out)
{

View File

@ -10,7 +10,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <err.h>
#include <errno.h>
#include <blkid.h>

View File

@ -10,7 +10,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <err.h>
#include <errno.h>
#include <blkid.h>

View File

@ -10,7 +10,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <err.h>
#include <errno.h>
#include <blkid.h>

View File

@ -10,7 +10,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <err.h>
#include <errno.h>
#include <blkid.h>

View File

@ -24,7 +24,6 @@
#include <errno.h>
#include <string.h>
#include <getopt.h>
#include <err.h>
#include <unistd.h>
#include <sys/types.h>

View File

@ -29,6 +29,7 @@
#include "pathnames.h"
#include "nls.h"
#include "c.h"
#include "mountP.h"
@ -429,7 +430,6 @@ failed:
}
#ifdef TEST_PROGRAM
#include <err.h>
struct libmnt_lock *lock;

View File

@ -5,13 +5,13 @@
* - added Native Language Support
*/
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "linux_reboot.h"
#include "nls.h"
#include "c.h"
int main(int argc, char *argv[])
{

View File

@ -30,7 +30,6 @@
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <err.h>
#include <limits.h>
#ifndef HAVE_FALLOCATE
@ -45,6 +44,7 @@
#include "nls.h"
#include "strutils.h"
#include "c.h"
static void __attribute__((__noreturn__)) usage(FILE *out)

View File

@ -20,7 +20,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <getopt.h>
#include <err.h>
#include "blkdev.h"
#include "nls.h"

View File

@ -32,7 +32,6 @@
#include <fcntl.h>
#include <limits.h>
#include <getopt.h>
#include <err.h>
#include <error.h>
#include <errno.h>
@ -42,6 +41,7 @@
#include "nls.h"
#include "strutils.h"
#include "c.h"
#ifndef FITRIM
struct fstrim_range {

View File

@ -23,7 +23,6 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <err.h>
#include <time.h>
#include <unistd.h>
@ -34,6 +33,7 @@
#include <sys/msg.h>
#include "nls.h"
#include "c.h"
static const char *progname;

View File

@ -26,7 +26,6 @@
#include <pwd.h>
#include <grp.h>
#include <unistd.h>
#include <err.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
@ -34,6 +33,7 @@
#include <sys/shm.h>
#include "nls.h"
#include "c.h"
/*-------------------------------------------------------------------*/
/* SHM_DEST and SHM_LOCKED are defined in kernel headers,

View File

@ -23,7 +23,6 @@
#include <errno.h>
#include <termios.h>
#include <unistd.h>
#include <err.h>
#include "c.h"
#include "nls.h"

View File

@ -21,7 +21,6 @@
#include <ctype.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
@ -37,6 +36,7 @@
#include "cpuset.h"
#include "nls.h"
#include "c.h"
#define CACHE_MAX 100

View File

@ -44,8 +44,8 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <err.h>
#include "nls.h"
#include "c.h"
static int donice(int,int,int);

View File

@ -28,7 +28,6 @@
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <err.h>
#include <sys/ioctl.h>
#include <sys/time.h>
@ -41,6 +40,7 @@
#include "pathnames.h"
#include "usleep.h"
#include "strutils.h"
#include "c.h"
/* constants from legacy PC/AT hardware */
#define RTC_PF 0x40

View File

@ -32,7 +32,7 @@
#include <errno.h>
#include <ctype.h>
#include <dirent.h>
#include <err.h>
#include "c.h"
#ifndef MS_MOVE
#define MS_MOVE 8192

View File

@ -18,7 +18,6 @@
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <sched.h>
@ -27,6 +26,7 @@
#include <unistd.h>
#include "nls.h"
#include "c.h"
#ifndef CLONE_NEWSNS
# define CLONE_NEWNS 0x00020000

View File

@ -47,12 +47,12 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <errno.h>
#include <getopt.h>
#include "nls.h"
#include "widechar.h"
#include "c.h"
#ifdef HAVE_WIDECHAR
#define wcs_width(s) wcswidth(s,wcslen(s))

View File

@ -55,12 +55,12 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <err.h>
#include <signal.h>
#include "nls.h"
#include "xalloc.h"
#include "widechar.h"
#include "c.h"
wchar_t *buf;

View File

@ -35,7 +35,6 @@
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include <err.h>
#ifdef HAVE_INOTIFY_INIT
#include <sys/inotify.h>
#endif
@ -43,6 +42,7 @@
#include "nls.h"
#include "xalloc.h"
#include "usleep.h"
#include "c.h"
#define DEFAULT_LINES 10

View File

@ -47,12 +47,12 @@
#include <stdlib.h> /* for getenv() */
#include <limits.h> /* for INT_MAX */
#include <signal.h> /* for signal() */
#include <err.h>
#include <errno.h>
#include "nls.h"
#include "xalloc.h"
#include "widechar.h"
#include "c.h"
#ifdef HAVE_WIDECHAR
static int put1wc(int c) /* Output an ASCII character as a wide character */