This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
perror doesn't work if stderr is wide
- To: libc-alpha at sources dot redhat dot com
- Subject: perror doesn't work if stderr is wide
- From: Bruno Haible <haible at ilog dot fr>
- Date: Mon, 4 Dec 2000 14:26:27 +0100 (CET)
In glibc-2.2, the perror function produces no output if stderr is wide
oriented. But the SUSV2 spec says:
"The perror() function maps the error number accessed through the
symbol errno to a language-dependent error message, which is written
to the standard error stream as follows: ...
The perror() function does not change the orientation of the
standard error stream."
Here is a test program:
=====================================================================
#define _ISOC99_SOURCE 1
#include <stdio.h>
#include <wchar.h>
#include <errno.h>
int main ()
{
fwprintf (stderr, L"Wide output\n");
errno = EINVAL;
perror ("test");
return 0;
}
=====================================================================
It produces only one line of output.
Here is a fix.
2000-12-02 Bruno Haible <haible@clisp.cons.org>
* stdio-common/perror.c (perror): If stderr is wide-oriented, use
fwprintf instead of fprintf.
*** glibc-2.2/stdio-common/perror.c.bak Wed Apr 15 17:39:15 1998
--- glibc-2.2/stdio-common/perror.c Sat Dec 2 21:45:40 2000
***************
*** 1,4 ****
! /* Copyright (C) 1991, 1992, 1993, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
--- 1,4 ----
! /* Copyright (C) 1991, 1992, 1993, 1997, 1998, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
***************
*** 17,22 ****
--- 17,23 ----
Boston, MA 02111-1307, USA. */
#include <stdio.h>
+ #include <wchar.h>
#include <string.h>
#include <errno.h>
***************
*** 29,40 ****
char buf[1024];
int errnum = errno;
const char *colon;
if (s == NULL || *s == '\0')
s = colon = "";
else
colon = ": ";
! (void) fprintf (stderr, "%s%s%s\n",
! s, colon, __strerror_r (errnum, buf, sizeof buf));
}
--- 30,46 ----
char buf[1024];
int errnum = errno;
const char *colon;
+ const char *errstring;
if (s == NULL || *s == '\0')
s = colon = "";
else
colon = ": ";
! errstring = __strerror_r (errnum, buf, sizeof buf);
!
! if (fwide (stderr, 0) > 0)
! (void) fwprintf (stderr, L"%s%s%s\n", s, colon, errstring);
! else
! (void) fprintf (stderr, "%s%s%s\n", s, colon, errstring);
}