commit 9f979287ca878ea53868ba6159f44ef09d26001f
parent 83d25f33ff40201e4d45af45066143deb78465f5
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Sun, 20 Dec 2020 19:33:29 -0800
Replace fclose with costom wfclose
Diffstat:
M | main.c | | | 25 | +++++++++++++++---------- |
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/main.c b/main.c
@@ -65,6 +65,16 @@ wfopen(const char *path, const char *mode)
}
int
+wfclose(FILE *fp)
+{
+ if (fclose(fp) == EOF) {
+ warn("unable to close file");
+ return EOF;
+ }
+ return 0;
+}
+
+int
resolve(const char *host, const char *port)
{
int error, s;
@@ -215,13 +225,13 @@ fetch(int sock, const char *path)
while ((bytes = recv(sock, buf, sizeof(buf), 0)) > 0) {
if (fwrite(buf, 1, bytes, fp) != bytes) {
- fclose(fp);
+ wfclose(fp);
return 1;
}
}
error = ferror(fp);
- if (fclose(fp) || error)
+ if (wfclose(fp) || error)
return 1;
return 0;
}
@@ -382,20 +392,15 @@ int
cputs(const char *path, int argc, const char **argv)
{
FILE *fp;
+ int status;
fp = wfopen(path, "r");
if (fp == NULL)
return 1;
- if (fput(fp) != 0) {
- fclose(fp);
+ status = fput(fp);
+ if (wfclose(fp) || status)
return 1;
- }
-
- if (fclose(fp)) {
- warn("fclose '%s'", path);
- return 1;
- }
return 0;
}