#! /bin/sh /usr/share/dpatch/dpatch-run ## 04_upstream_read_eagain.patch.dpatch by <Hector Garcia <hector@debian.org>> ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: No description. @DPATCH@ diff -urNad trunk~/src/tools.c trunk/src/tools.c --- trunk~/src/tools.c 2006-01-20 16:15:30.000000000 +0100 +++ trunk/src/tools.c 2006-01-20 16:25:51.000000000 +0100 @@ -559,6 +559,33 @@ } +/* read a single char from a file descriptor. If the descriptor + says that it is not available, then try again up to 5 times, + before giving up. + Required for Mac OS 10.3 +*/ + +static gint read_char(gint fd, gchar *c) { +gint rc; +gint retries; + + retries = 5; + + while (retries) { + rc = read(fd, c, 1); + + /* all ok, read one char or EOF */ + if (rc != -1) { + return rc; + } + + /* error code, try again after a little while */ + usleep(100); + retries--; + } + return rc; +} + /* * Read a line from a descriptor. Read the line one byte at a time, * looking for the newline. Works fine in nonblocking mode..here @@ -576,7 +603,7 @@ str = ptr; for (n = 1; n < maxlen; n++) { - if ( (rc = read(fd, &c, 1)) == 1) { + if ( (rc = read_char(fd, &c)) == 1) { *ptr++ = c; if (c == '\n') { break;