summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorVincent Douillet <vincent@vdouillet.fr>2024-02-20 21:17:01 +0100
committerVincent Douillet <vincent@vdouillet.fr>2024-02-20 22:13:53 +0100
commit0effd40bad7ae753102e7040159afd76be4e8732 (patch)
tree20c80821ba637a395d8874414e00f4d120a837ea /util.c
parent42f538cc66546997a166dbe67e489c9afabbb908 (diff)
browse: http page
Diffstat (limited to 'util.c')
-rw-r--r--util.c44
1 files changed, 0 insertions, 44 deletions
diff --git a/util.c b/util.c
deleted file mode 100644
index 2822c89..0000000
--- a/util.c
+++ /dev/null
@@ -1,44 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "util.h"
-
-int
-read_file(char *path, char **output, size_t * read_size)
-{
- long file_size;
- FILE *fp;
-
- fp = fopen(path, "r");
- if (fp == NULL)
- return -1;
-
- /* get file size */
- if (fseek(fp, 0L, SEEK_END) != 0)
- return -1;
-
- file_size = ftell(fp);
- if (file_size < 0)
- return -1;
-
- /* rewind to file start */
- if (fseek(fp, 0L, SEEK_SET) != 0)
- return -1;
-
- /* create output buffer */
- *output = malloc(sizeof(char) * (file_size + 1));
- if (*output == NULL)
- return -1;
-
- /* read the file */
- *read_size = fread(*output, sizeof(char), file_size, fp);
- if (*read_size == 0 || ferror(fp) != 0) {
- free(*output);
- return -1;
- }
- /* enforce string termination */
- (*output)[*read_size] = '\0';
-
- return 0;
-}