bug-gnulib
[Top][All Lists]
Advanced

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

Re: [Bug-gnulib] safe-read.[ch] (safe_read): what do you think?


From: Jim Meyering
Subject: Re: [Bug-gnulib] safe-read.[ch] (safe_read): what do you think?
Date: Tue, 03 Dec 2002 11:16:53 +0100

Bruno Haible <address@hidden> wrote:
> Jim Meyering writes:
>
>> FYI, I've just checked in this change to restore
>> the old (coreutils) behavior:
>>
>>      * safe-read.c (EINTR): Define.
>>      (safe_read): Rewrite to iterate IFF the read fails with EINTR.
>>
>> because the previous version didn't work as used by cat.
>
> Thanks. I had put in the EOF handling into full-read.c but forgot it
> in safe-read.c :-(.
>
> I've applied your changes to safe-write.[hc] also, but removed the
> suspicious definition of EINTR: if EINTR is not defined a "while (0)"
> is sufficient.

I try hard to avoid adding cpp directives to the body
of a function.  And I try even harder to avoid it when such an
addition would be solely in support of deficient systems.

So here's a little clean-up that I've just checked in.
[ Hmm... there's too much duplication, so I'm looking at
  unifying safe-read.c and safe-write.c ... ]

Index: safe-read.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/safe-read.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -p -u -r1.17 -r1.18
--- safe-read.c 2 Dec 2002 18:53:53 -0000       1.17
+++ safe-read.c 3 Dec 2002 09:48:14 -0000       1.18
@@ -33,6 +33,12 @@
 extern int errno;
 #endif
 
+#ifdef EINTR
+# define IS_EINTR(x) ((x) == EINTR)
+#else
+# define IS_EINTR(x) 0
+#endif
+
 #include <limits.h>
 
 #ifndef CHAR_BIT
@@ -77,11 +83,7 @@ safe_read (int fd, void *buf, size_t cou
     {
       result = read (fd, buf, nbytes_to_read);
     }
-#ifdef EINTR
-  while (result < 0 && errno == EINTR);
-#else
-  while (0);
-#endif
+  while (result < 0 && IS_EINTR (errno));
 
   return (size_t) result;
 }




reply via email to

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