Finita la conversione dei listati in file separati. Passato anche alla nuova
[gapil.git] / listati / FullRead.c
diff --git a/listati/FullRead.c b/listati/FullRead.c
new file mode 100644 (file)
index 0000000..fcc265b
--- /dev/null
@@ -0,0 +1,23 @@
+#include <unistd.h>
+
+ssize_t FullRead(int fd, void *buf, size_t count) 
+{
+    size_t nleft;
+    ssize_t nread;
+    nleft = count;
+    while (nleft > 0) {             /* repeat until no left */
+        if ( (nread = read(fd, buf, nleft)) < 0) {
+            if (errno == EINTR) {   /* if interrupted by system call */
+                continue;           /* repeat the loop */
+            } else {
+                return(nread);      /* otherwise exit */
+            }
+        } else if (nread == 0) {    /* EOF */
+            break;                  /* break loop here */ 
+        }
+        nleft -= nread;             /* set left to read */
+        buf +=nread;                /* set pointer */
+    }
+    return (count - nleft);
+}