Ticket #38137: 0004-configure-Check-for-error.h.patch

File 0004-configure-Check-for-error.h.patch, 2.7 KB (added by raimue (Rainer Müller), 12 years ago)
  • configure.ac

    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 
    137137dnl     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"
    138138dnl fi
    139139
     140AC_CHECK_HEADERS(error.h, [], [], AC_INCLUDES_DEFAULT)
     141
    140142AC_CHECK_HEADERS(stdio_ext.h, [], [], AC_INCLUDES_DEFAULT)
    141143
    142144AC_MSG_CHECKING(whether program_invocation_name is defined)
  • include/c.h

    diff --git a/include/c.h b/include/c.h
    index 737630b..6bcdf5f 100644
    a b  
    1616#include <stdlib.h>
    1717#include <string.h>
    1818#include <errno.h>
     19#ifdef HAVE_ERROR_H
    1920#include <error.h>
     21#else
     22#include <stdarg.h>
     23#endif
    2024
    2125/*
    2226 * Compiler specific stuff
    static inline char *prog_inv_sh_nm_from_file(char *f, char stripext) 
    103107/*
    104108 * Error printing.
    105109 */
     110#ifndef HAVE_ERROR_H
     111/* Emulate the error() function from glibc */
     112__attribute__((__format__(__printf__, 3, 4)))
     113static 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
    106127#define xwarn(...) error(0, errno, __VA_ARGS__)
    107128#define xwarnx(...) error(0, 0, __VA_ARGS__)
    108129#define xerr(STATUS, ...) error(STATUS, errno, __VA_ARGS__)
  • lib/fileutils.c

    diff --git a/lib/fileutils.c b/lib/fileutils.c
    index c50d6aa..a9ef2ff 100644
    a b  
    11#include <errno.h>
    2 #include <error.h>
     2#ifdef HAVE_ERROR_H
     3# include <error.h>
     4#endif
    35#ifdef HAVE_STDIO_EXT_H
    46# include <stdio_ext.h>
    57#else
     
    1214
    1315#include "nls.h"
    1416#include "fileutils.h"
     17#ifndef HAVE_ERROR_H
     18# include "c.h" /* for error() emulation */
     19#endif
    1520
    1621int close_stream(FILE * stream)
    1722{