fehQlibs 27
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
15
16int readclose_append(int fd,stralloc *sa,unsigned int bufsize)
17{
18 int r;
19 for (;;) {
20 if (!stralloc_readyplus(sa,bufsize)) { close(fd); return -1; }
21 r = read(fd,sa->s + sa->len,bufsize);
22 if (r == -1) if (errno == EINTR) continue;
23 if (r <= 0) { close(fd); return r; }
24 sa->len += r;
25 }
26}
27
28int readclose(int fd,stralloc *sa,unsigned int bufsize)
29{
30 if (!stralloc_copys(sa,"")) { close(fd); return -1; }
31 return readclose_append(fd,sa,bufsize);
32}
33
34int openreadclose(const char *fn,stralloc *sa,unsigned int bufsize)
35{
36 int fd;
37 fd = open_read((char *) fn);
38 if (fd == -1) {
39 if (errno == ENOENT) return 0;
40 return -1;
41 }
42 if (readclose(fd,sa,bufsize) == -1) return -1;
43 return 1;
44}
int stralloc_readyplus(stralloc *sa, size_t len)
Definition stralloc.c:61
int stralloc_copys(stralloc *, const char *)
Definition stralloc.c:79
int open_read(const char *)
Definition open.c:18
int close(int __fd)
int readclose_append(int fd, stralloc *sa, unsigned int bufsize)
Definition readclose.c:16
int readclose(int fd, stralloc *sa, unsigned int bufsize)
Definition readclose.c:28
int openreadclose(const char *fn, stralloc *sa, unsigned int bufsize)
Definition readclose.c:34
int read(int _str, void *_buf, int _b)
size_t len
Definition stralloc.h:19
char * s
Definition stralloc.h:18