X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=listati%2FFullRead.c;fp=listati%2FFullRead.c;h=fcc265b6030a30b293c9aaa4e1ba2f2f83f40310;hp=0000000000000000000000000000000000000000;hb=06661f47754a536098afe2b30cb04469918f2fa3;hpb=bdf6e88eeb9b3aef06d57930ec8b89083639e56d diff --git a/listati/FullRead.c b/listati/FullRead.c new file mode 100644 index 0000000..fcc265b --- /dev/null +++ b/listati/FullRead.c @@ -0,0 +1,23 @@ +#include + +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); +}