summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2002-03-22 15:18:58 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2002-03-22 15:18:58 +0100
commit0be1a13c60b6e43d1ef6357444111c35b4c0a942 (patch)
treecc84ed67edf983c0c640b7f798385f59f9ac57b8 /tools.c
parent70db7f17bcc8142fbb80a6811fe8a5fa090cee65 (diff)
downloadvdr-0be1a13c60b6e43d1ef6357444111c35b4c0a942.tar.gz
vdr-0be1a13c60b6e43d1ef6357444111c35b4c0a942.tar.bz2
Improved file I/O in case of EINTR
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/tools.c b/tools.c
index 3764a644..21a91dc1 100644
--- a/tools.c
+++ b/tools.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 1.59 2002/02/17 12:57:23 kls Exp $
+ * $Id: tools.c 1.60 2002/03/22 15:18:58 kls Exp $
*/
#include "tools.h"
@@ -33,14 +33,21 @@ ssize_t safe_read(int filedes, void *buffer, size_t size)
ssize_t safe_write(int filedes, const void *buffer, size_t size)
{
- for (;;) {
- ssize_t p = write(filedes, buffer, size);
- if (p < 0 && errno == EINTR) {
- dsyslog(LOG_INFO, "EINTR while writing to file handle %d - retrying", filedes);
- continue;
- }
- return p;
- }
+ ssize_t p = -1;
+ const unsigned char *ptr = (const unsigned char *)buffer;
+ while (size > 0) {
+ p = write(filedes, ptr, size);
+ if (p < 0) {
+ if (errno == EINTR) {
+ dsyslog(LOG_INFO, "EINTR while writing to file handle %d - retrying", filedes);
+ continue;
+ }
+ break;
+ }
+ ptr += p;
+ size -= p;
+ }
+ return p;
}
void writechar(int filedes, char c)