]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/utils.c
Check for EAGAIN as well as EWOULDBLOCK, since they are
[ppp.git] / pppd / utils.c
index 8c7045298b7bf0546022fc25a8a705549df12659..31f9b52356b20e5fd68bbefb72393df3992d662c 100644 (file)
@@ -33,7 +33,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define RCSID  "$Id: utils.c,v 1.20 2002/12/04 23:03:33 paulus Exp $"
+#define RCSID  "$Id: utils.c,v 1.22 2003/04/07 00:01:46 paulus Exp $"
 
 #include <stdio.h>
 #include <ctype.h>
@@ -720,6 +720,7 @@ error __V((char *fmt, ...))
 
     logit(LOG_ERR, fmt, pvar);
     va_end(pvar);
+    ++error_count;
 }
 
 /*
@@ -832,6 +833,32 @@ dump_packet(const char *tag, unsigned char *p, int len)
     dbglog("%s %P", tag, p, len);
 }
 
+/*
+ * complete_read - read a full `count' bytes from fd,
+ * unless end-of-file or an error other than EINTR is encountered.
+ */
+ssize_t
+complete_read(int fd, void *buf, size_t count)
+{
+       size_t done;
+       ssize_t nb;
+       char *ptr = buf;
+
+       for (done = 0; done < count; ) {
+               nb = read(fd, ptr, count - done);
+               if (nb < 0) {
+                       if (errno == EINTR)
+                               continue;
+                       return -1;
+               }
+               if (nb == 0)
+                       break;
+               done += nb;
+               ptr += nb;
+       }
+       return done;
+}
+
 /* Procedures for locking the serial device using a lock file. */
 #ifndef LOCK_DIR
 #ifdef __linux__