summaryrefslogtreecommitdiff
path: root/tests/error.c
diff options
context:
space:
mode:
authorStephen Kitt <skitt@debian.org>2016-05-27 10:11:04 +0200
committerManuel A. Fernandez Montecelo <manuel.montezelo@gmail.com>2016-05-27 14:28:33 +0100
commit752fd7247bc223bcea35bd89cf56d1c08ead9ba6 (patch)
treeb4a428f847a963738faaf24c8eff070fdb03a3a5 /tests/error.c
parent9f7d4fa477ff2a51d7c932b13d57ac22dc033105 (diff)
parenta9a31b1de5776a3b08a82101a4fa711294f0dd1d (diff)
Imported Debian patch 0.9.6+really0.9.3-0.1debian/0.9.6+really0.9.3-0.1
Diffstat (limited to 'tests/error.c')
-rw-r--r--tests/error.c74
1 files changed, 17 insertions, 57 deletions
diff --git a/tests/error.c b/tests/error.c
index 0ac7695..c79e8d4 100644
--- a/tests/error.c
+++ b/tests/error.c
@@ -1,5 +1,5 @@
/* Error handler for noninteractive utilities
- Copyright (C) 1990-1998, 2000-2007, 2009-2015 Free Software Foundation, Inc.
+ Copyright (C) 1990-1998, 2000-2007, 2009-2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify
@@ -39,9 +39,6 @@
# include <stdint.h>
# include <wchar.h>
# define mbsrtowcs __mbsrtowcs
-# define USE_UNLOCKED_IO 0
-# define _GL_ATTRIBUTE_FORMAT_PRINTF(a, b)
-# define _GL_ARG_NONNULL(a)
#endif
#if USE_UNLOCKED_IO
@@ -57,7 +54,7 @@
function without parameters instead. */
void (*error_print_progname) (void);
-/* This variable is incremented each time 'error' is called. */
+/* This variable is incremented each time `error' is called. */
unsigned int error_message_count;
#ifdef _LIBC
@@ -68,21 +65,21 @@ unsigned int error_message_count;
# include <limits.h>
# include <libio/libioP.h>
-/* In GNU libc we want do not want to use the common name 'error' directly.
+/* In GNU libc we want do not want to use the common name `error' directly.
Instead make it a weak alias. */
extern void __error (int status, int errnum, const char *message, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
extern void __error_at_line (int status, int errnum, const char *file_name,
unsigned int line_number, const char *message,
...)
- __attribute__ ((__format__ (__printf__, 5, 6)));
+ __attribute__ ((__format__ (__printf__, 5, 6)));;
# define error __error
# define error_at_line __error_at_line
# include <libio/iolibio.h>
-# define fflush(s) _IO_fflush (s)
+# define fflush(s) INTUSE(_IO_fflush) (s)
# undef putc
-# define putc(c, fp) _IO_putc (c, fp)
+# define putc(c, fp) INTUSE(_IO_putc) (c, fp)
# include <bits/libc-lock.h>
@@ -91,26 +88,11 @@ extern void __error_at_line (int status, int errnum, const char *file_name,
# include <fcntl.h>
# include <unistd.h>
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* Get declarations of the native Windows API functions. */
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
-# endif
-
-/* The gnulib override of fcntl is not needed in this file. */
-# undef fcntl
-
-# if !HAVE_DECL_STRERROR_R
+# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
# ifndef HAVE_DECL_STRERROR_R
"this configure-time declaration test was not run"
# endif
-# if STRERROR_R_CHAR_P
char *strerror_r ();
-# else
-int strerror_r ();
-# endif
# endif
/* The calling program should define program_name and set it to the
@@ -122,30 +104,10 @@ extern char *program_name;
# endif /* HAVE_STRERROR_R || defined strerror_r */
#endif /* not _LIBC */
-#if !_LIBC
-/* Return non-zero if FD is open. */
-static int
-is_open (int fd)
-{
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- /* On native Windows: The initial state of unassigned standard file
- descriptors is that they are open but point to an INVALID_HANDLE_VALUE.
- There is no fcntl, and the gnulib replacement fcntl does not support
- F_GETFL. */
- return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
-# else
-# ifndef F_GETFL
-# error Please port fcntl to your platform
-# endif
- return 0 <= fcntl (fd, F_GETFL);
-# endif
-}
-#endif
-
-static void
+static inline void
flush_stdout (void)
{
-#if !_LIBC
+#if !_LIBC && defined F_GETFL
int stdout_fd;
# if GNULIB_FREOPEN_SAFER
@@ -162,7 +124,7 @@ flush_stdout (void)
/* POSIX states that fflush (stdout) after fclose is unspecified; it
is safe in glibc, but not on all other platforms. fflush (NULL)
is always defined, but too draconian. */
- if (0 <= stdout_fd && is_open (stdout_fd))
+ if (0 <= stdout_fd && 0 <= fcntl (stdout_fd, F_GETFL))
#endif
fflush (stdout);
}
@@ -174,7 +136,7 @@ print_errno_message (int errnum)
#if defined HAVE_STRERROR_R || _LIBC
char errbuf[1024];
-# if _LIBC || STRERROR_R_CHAR_P
+# if STRERROR_R_CHAR_P || _LIBC
s = __strerror_r (errnum, errbuf, sizeof errbuf);
# else
if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
@@ -198,12 +160,13 @@ print_errno_message (int errnum)
#endif
}
-static void _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) _GL_ARG_NONNULL ((3))
+static void
error_tail (int status, int errnum, const char *message, va_list args)
{
#if _LIBC
if (_IO_fwide (stderr, 0) > 0)
{
+# define ALLOCA_LIMIT 2000
size_t len = strlen (message) + 1;
wchar_t *wmessage = NULL;
mbstate_t st;
@@ -239,7 +202,7 @@ error_tail (int status, int errnum, const char *message, va_list args)
if (res != len)
break;
- if (__builtin_expect (len >= SIZE_MAX / sizeof (wchar_t) / 2, 0))
+ if (__builtin_expect (len >= SIZE_MAX / 2, 0))
{
/* This really should not happen if everything is fine. */
res = (size_t) -1;
@@ -344,10 +307,7 @@ error_at_line (int status, int errnum, const char *file_name,
if (old_line_number == line_number
&& (file_name == old_file_name
- || (old_file_name != NULL
- && file_name != NULL
- && strcmp (old_file_name, file_name) == 0)))
-
+ || strcmp (old_file_name, file_name) == 0))
/* Simply return and print nothing. */
return;
@@ -379,10 +339,10 @@ error_at_line (int status, int errnum, const char *file_name,
}
#if _LIBC
- __fxprintf (NULL, file_name != NULL ? "%s:%u: " : " ",
+ __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ",
file_name, line_number);
#else
- fprintf (stderr, file_name != NULL ? "%s:%u: " : " ",
+ fprintf (stderr, file_name != NULL ? "%s:%d: " : " ",
file_name, line_number);
#endif