bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new module 'perror'


From: Bruno Haible
Subject: new module 'perror'
Date: Sun, 14 Sep 2008 13:50:40 +0200
User-agent: KMail/1.5.4

This extends 'perror' so that it knows about the added errno values.

2008-09-14  Bruno Haible  <address@hidden>

        New module 'perror'.
        * lib/stdio.in.h (perror): New declaration.
        * lib/perror.c: New file.
        * m4/perror.m4: New file.
        * modules/perror: New file.
        * MODULES.html.sh (Support for systems lacking POSIX:2001): Add perror.
        * doc/posix-functions/perror.texi: Mention the perror module.
        * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Initialize GNULIB_PERROR,
        REPLACE_PERROR.
        * modules/stdio (Makefile.am): Substitute GNULIB_PERROR,
        REPLACE_PERROR.

*** lib/stdio.in.h.orig 2008-09-14 13:44:49.000000000 +0200
--- lib/stdio.in.h      2008-09-14 12:50:42.000000000 +0200
***************
*** 395,400 ****
--- 395,416 ----
     getline (l, s, f))
  #endif
  
+ #if @GNULIB_PERROR@
+ # if @REPLACE_PERROR@
+ #  define perror rpl_perror
+ /* Print a message to standard error, describing the value of ERRNO,
+    (if STRING is not NULL and not empty) prefixed with STRING and ": ",
+    and terminated with a newline.  */
+ extern void perror (const char *string);
+ # endif
+ #elif defined GNULIB_POSIXCHECK
+ # undef perror
+ # define perror(s) \
+     (GL_LINK_WARNING ("perror is not always POSIX compliant - " \
+                       "use gnulib module perror for portability"), \
+      perror (s))
+ #endif
+ 
  #ifdef __cplusplus
  }
  #endif
============================= lib/perror.c ===================================
/* Print a message describing error code.
   Copyright (C) 2008 Free Software Foundation, Inc.
   Written by Bruno Haible and Simon Josefsson.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#include <config.h>

/* Specification.  */
#include <stdio.h>

#include <errno.h>
#include <string.h>

void
perror (const char *string)
{
  const char *errno_description = strerror (errno);

  if (string != NULL && *string != '\0')
    fprintf (stderr, "%s: %s\n", string, errno_description);
  else
    fprintf (stderr, "%s\n", errno_description);
}
============================= m4/perror.m4 ===================================
# perror.m4 serial 1
dnl Copyright (C) 2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_FUNC_PERROR],
[
  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
  AC_REQUIRE([gl_HEADER_ERRNO_H])
  if test -n "$ERRNO_H"; then
    dnl The system's perror() cannot know about the new errno values we add
    dnl to <errno.h>. Replace it.
    REPLACE_PERROR=1
    AC_LIBOBJ([perror])
  fi
])
============================= modules/perror =================================
Description:
perror() function: print a message describing error code.

Files:
lib/perror.c
m4/perror.m4

Depends-on:
stdio
errno
strerror

configure.ac:
gl_FUNC_PERROR
gl_STRING_MODULE_INDICATOR([perror])

Makefile.am:

Include:
<stdio.h>

License:
LGPL

Maintainer:
all
==============================================================================
*** MODULES.html.sh.orig        2008-09-14 13:44:48.000000000 +0200
--- MODULES.html.sh     2008-09-14 12:43:44.000000000 +0200
***************
*** 2112,2117 ****
--- 2112,2118 ----
    func_module mkstemp
    func_module netinet_in
    func_module open
+   func_module perror
    func_module poll
    func_module printf-posix
    func_module readlink
*** doc/posix-functions/perror.texi.orig        2008-09-14 13:44:49.000000000 
+0200
--- doc/posix-functions/perror.texi     2008-09-14 12:34:51.000000000 +0200
***************
*** 4,13 ****
  
  POSIX specification: @url{http://www.opengroup.org/susv3xsh/perror.html}
  
! Gnulib module: ---
  
  Portability problems fixed by Gnulib:
  @itemize
  @end itemize
  
  Portability problems not fixed by Gnulib:
--- 4,17 ----
  
  POSIX specification: @url{http://www.opengroup.org/susv3xsh/perror.html}
  
! Gnulib module: perror
  
  Portability problems fixed by Gnulib:
  @itemize
+ @item
+ This function does not support the error values that are specified by POSIX
+ but not defined by the system, on some platforms:
+ OpenBSD 4.0, OSF/1 5.1, mingw.
  @end itemize
  
  Portability problems not fixed by Gnulib:
*** m4/stdio_h.m4.orig  2008-09-14 13:44:49.000000000 +0200
--- m4/stdio_h.m4       2008-09-14 13:00:44.000000000 +0200
***************
*** 39,44 ****
--- 39,45 ----
    GNULIB_FFLUSH=0;               AC_SUBST([GNULIB_FFLUSH])
    GNULIB_GETDELIM=0;             AC_SUBST([GNULIB_GETDELIM])
    GNULIB_GETLINE=0;              AC_SUBST([GNULIB_GETLINE])
+   GNULIB_PERROR=0;               AC_SUBST([GNULIB_PERROR])
    dnl Assume proper GNU behavior unless another module says otherwise.
    REPLACE_FPRINTF=0;             AC_SUBST([REPLACE_FPRINTF])
    REPLACE_VFPRINTF=0;            AC_SUBST([REPLACE_VFPRINTF])
***************
*** 66,71 ****
--- 67,73 ----
    HAVE_DECL_GETDELIM=1;          AC_SUBST([HAVE_DECL_GETDELIM])
    HAVE_DECL_GETLINE=1;           AC_SUBST([HAVE_DECL_GETLINE])
    REPLACE_GETLINE=0;             AC_SUBST([REPLACE_GETLINE])
+   REPLACE_PERROR=0;              AC_SUBST([REPLACE_PERROR])
  ])
  
  dnl Code shared by fseeko and ftello.  Determine if large files are supported,
*** modules/stdio.orig  2008-09-14 13:44:49.000000000 +0200
--- modules/stdio       2008-09-14 13:00:40.000000000 +0200
***************
*** 43,48 ****
--- 43,49 ----
              -e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
              -e 's|@''GNULIB_GETDELIM''@|$(GNULIB_GETDELIM)|g' \
              -e 's|@''GNULIB_GETLINE''@|$(GNULIB_GETLINE)|g' \
+             -e 's|@''GNULIB_PERROR''@|$(GNULIB_PERROR)|g' \
              -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \
              -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \
              -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \
***************
*** 67,72 ****
--- 68,74 ----
              -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \
              -e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \
              -e 's|@''REPLACE_GETLINE''@|$(REPLACE_GETLINE)|g' \
+             -e 's|@''REPLACE_PERROR''@|$(REPLACE_PERROR)|g' \
              -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
              < $(srcdir)/stdio.in.h; \
        } > address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]