X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=lib%2Fperror.c;h=827a37cc8d42b3b617d6b01915af7a255b659f6e;hb=92249085071a973e2c0621b0415b93d2e48bb00d;hp=bc3c764911dfec960ea29b9bee85db4b0f43ada3;hpb=dc0ab95dbae38577efebe2283fc9b76e92ef4233;p=debian%2Fgzip
diff --git a/lib/perror.c b/lib/perror.c
index bc3c764..827a37c 100644
--- a/lib/perror.c
+++ b/lib/perror.c
@@ -1,5 +1,5 @@
/* Print a message describing error code.
- Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+ Copyright (C) 2008-2018 Free Software Foundation, Inc.
Written by Bruno Haible and Simon Josefsson.
This program is free software: you can redistribute it and/or modify
@@ -13,7 +13,7 @@
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 . */
+ along with this program. If not, see . */
#include
@@ -21,15 +21,29 @@
#include
#include
+#include
#include
+#include "strerror-override.h"
+
+/* Use the system functions, not the gnulib overrides in this file. */
+#undef fprintf
+
void
perror (const char *string)
{
- const char *errno_description = strerror (errno);
+ char stackbuf[STACKBUF_LEN];
+ int ret;
+
+ /* Our implementation guarantees that this will be a non-empty
+ string, even if it returns EINVAL; and stackbuf should be sized
+ large enough to avoid ERANGE. */
+ ret = strerror_r (errno, stackbuf, sizeof stackbuf);
+ if (ret == ERANGE)
+ abort ();
if (string != NULL && *string != '\0')
- fprintf (stderr, "%s: %s\n", string, errno_description);
+ fprintf (stderr, "%s: %s\n", string, stackbuf);
else
- fprintf (stderr, "%s\n", errno_description);
+ fprintf (stderr, "%s\n", stackbuf);
}