[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 2/3] libc: POSIX: Rueckgabewert von read



! libc: POSIX: Wenn read 0 zurueckgibt, heisst das EOF. Wenn nur im
  Moment nichts da ist, ist -1/EAGAIN der richtige Wert.

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/lib/posix/posix_files.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/modules/lib/posix/posix_files.c b/src/modules/lib/posix/posix_files.c
index 34cc4ee..bbf4413 100644
--- a/src/modules/lib/posix/posix_files.c
+++ b/src/modules/lib/posix/posix_files.c
@@ -254,6 +254,14 @@ ssize_t read(int fd, void* buffer, size_t size)
 
     size_t bytes = fread(buffer, 1, size, file);
     // FIXME: Fehlerbehandlung
+
+    if (bytes == 0) {
+        if (!feof(file)) {
+            errno = EAGAIN;
+            return -1;
+        }
+    }
+
     return bytes;
 }
 
-- 
1.6.0.2