This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] Fix perror


Hi!

The recent stderr changes to perror broke it completely, since the functions
called before perror_internal may actually change errno, thus perror prints
a different string than it should.
Fixed thusly:

2001-08-31  Jakub Jelinek  <jakub@redhat.com>

	* stdio-common/perror.c (perror): Save errno early, pass it
	down to perror_internal.
	(perror_internal): Add errnum argument.

--- libc/stdio-common/perror.c.jj	Thu Aug 23 18:49:09 2001
+++ libc/stdio-common/perror.c	Fri Aug 31 21:47:08 2001
@@ -26,10 +26,9 @@
 #endif
 
 static void
-perror_internal (FILE *fp, const char *s)
+perror_internal (FILE *fp, const char *s, int errnum)
 {
   char buf[1024];
-  int errnum = errno;
   const char *colon;
   const char *errstring;
 
@@ -55,6 +54,7 @@ perror_internal (FILE *fp, const char *s
 void
 perror (const char *s)
 {
+  int errnum = errno;
 #ifdef USE_IN_LIBIO
   FILE *fp;
   int fd = -1;
@@ -73,20 +73,20 @@ perror (const char *s)
 	__close (fd);
 
       /* Use standard error as is.  */
-      perror_internal (stderr, s);
+      perror_internal (stderr, s, errnum);
     }
   else
     {
       /* We don't have to do any special hacks regarding the file
 	 position.  Since the stderr stream wasn't used so far we just
 	 write to the descriptor.  */
-      perror_internal (fp, s);
+      perror_internal (fp, s, errnum);
       /* Close the stream.  */
       fclose (fp);
 
       ((_IO_FILE *) stderr)->_offset = _IO_pos_BAD;
     }
 #else
-  perror_internal (stderr, s);
+  perror_internal (stderr, s, errnum);
 #endif
 }

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]