[PATCH] Added large file support ("backported" to collectd-3).
[collectd.git] / src / common.c
index 138b767..e7d561f 100644 (file)
  *   Niki W. Waibel <niki.waibel@gmx.net>
 **/
 
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 #include "common.h"
 #include "utils_debug.h"
 
@@ -144,6 +148,15 @@ ssize_t sread (int fd, void *buf, size_t count)
                if (status < 0)
                        return (status);
 
+               if (status == 0)
+               {
+                       DBG ("Received EOF from fd %i. "
+                                       "Closing fd and returning error.",
+                                       fd);
+                       close (fd);
+                       return (-1);
+               }
+
                assert (nleft >= status);
 
                nleft = nleft - status;
@@ -161,7 +174,7 @@ ssize_t swrite (int fd, const void *buf, size_t count)
        ssize_t     status;
 
        ptr   = (const char *) buf;
-       nleft = buflen;
+       nleft = count;
 
        while (nleft > 0)
        {