summaryrefslogtreecommitdiff
path: root/src/readclose.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-09 14:41:53 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-09 14:41:53 +0200
commit5fadc0cbb8577c61d66bd6f19ceaf0507c11e23b (patch)
tree684758441f5b431d0008253243034b6a4a29417c /src/readclose.c
parent249866e3d1e11dc72eaa1305f4bb479ded92ef38 (diff)
initial clang-format
Diffstat (limited to 'src/readclose.c')
-rw-r--r--src/readclose.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/readclose.c b/src/readclose.c
index b0bce7e..2804965 100644
--- a/src/readclose.c
+++ b/src/readclose.c
@@ -1,7 +1,9 @@
+#include "readclose.h"
+
#include <unistd.h>
-#include "open.h"
+
#include "error.h"
-#include "readclose.h"
+#include "open.h"
/**
@file readclose.c
@@ -12,32 +14,42 @@
'readclose' was introduced here initial.
*/
-int readclose_append(int fd,stralloc *sa,unsigned int bufsize)
+int readclose_append(int fd, stralloc *sa, unsigned int bufsize)
{
int r;
for (;;) {
- if (!stralloc_readyplus(sa,bufsize)) { close(fd); return -1; }
- r = read(fd,sa->s + sa->len,bufsize);
- if (r == -1) if (errno == EINTR) continue;
- if (r <= 0) { close(fd); return r; }
+ if (!stralloc_readyplus(sa, bufsize)) {
+ close(fd);
+ return -1;
+ }
+ r = read(fd, sa->s + sa->len, bufsize);
+ if (r == -1)
+ if (errno == EINTR) continue;
+ if (r <= 0) {
+ close(fd);
+ return r;
+ }
sa->len += r;
}
}
-int readclose(int fd,stralloc *sa,unsigned int bufsize)
+int readclose(int fd, stralloc *sa, unsigned int bufsize)
{
- if (!stralloc_copys(sa,"")) { close(fd); return -1; }
- return readclose_append(fd,sa,bufsize);
+ if (!stralloc_copys(sa, "")) {
+ close(fd);
+ return -1;
+ }
+ return readclose_append(fd, sa, bufsize);
}
-int openreadclose(const char *fn,stralloc *sa,unsigned int bufsize)
+int openreadclose(const char *fn, stralloc *sa, unsigned int bufsize)
{
int fd;
- fd = open_read((char *) fn);
+ fd = open_read((char *)fn);
if (fd == -1) {
if (errno == ENOENT) return 0;
return -1;
}
- if (readclose(fd,sa,bufsize) == -1) return -1;
+ if (readclose(fd, sa, bufsize) == -1) return -1;
return 1;
}