fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
readclose.c
Go to the documentation of this file.
1#include <unistd.h>
2#include "open.h"
3#include "error.h"
4#include "readclose.h"
5
15int readclose_append(int fd,stralloc *sa,unsigned int bufsize)
16{
17 int r;
18 for (;;) {
19 if (!stralloc_readyplus(sa,bufsize)) { close(fd); return -1; }
20 r = read(fd,sa->s + sa->len,bufsize);
21 if (r == -1) if (errno == EINTR) continue;
22 if (r <= 0) { close(fd); return r; }
23 sa->len += r;
24 }
25}
26
27int readclose(int fd,stralloc *sa,unsigned int bufsize)
28{
29 if (!stralloc_copys(sa,"")) { close(fd); return -1; }
30 return readclose_append(fd,sa,bufsize);
31}
32
33int openreadclose(const char *fn,stralloc *sa,unsigned int bufsize)
34{
35 int fd;
36 fd = open_read((char *) fn);
37 if (fd == -1) {
38 if (errno == ENOENT) return 0;
39 return -1;
40 }
41 if (readclose(fd,sa,bufsize) == -1) return -1;
42 return 1;
43}
int read(int _str, void *_buf, int _b)
int readclose_append(int fd, stralloc *sa, unsigned int bufsize)
Definition: readclose.c:15
int readclose(int fd, stralloc *sa, unsigned int bufsize)
Definition: readclose.c:27
int openreadclose(const char *fn, stralloc *sa, unsigned int bufsize)
Definition: readclose.c:33
int close(int __fd)
int open_read(const char *)
Definition: open.c:18
int stralloc_readyplus(stralloc *sa, size_t len)
Definition: stralloc.c:61
int stralloc_copys(stralloc *, const char *)
Definition: stralloc.c:79
size_t len
Definition: stralloc.h:19
char * s
Definition: stralloc.h:18