piu errori

This commit is contained in:
Alessandro Mauri 2023-02-23 01:23:21 +01:00
parent 4939fd7068
commit 884d5a1987
No known key found for this signature in database
GPG key ID: 2B7BF9531FF03BE8
5 changed files with 111 additions and 91 deletions

View file

@ -4,6 +4,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <err.h>
@ -85,7 +86,8 @@ void dump_file(const char *path, char **buf, int *buf_len)
rewind(fp);
if (*buf_len == (off_t)-1)
err(EXIT_FAILURE, "lseek() failed");
*buf = emalloc(*buf_len);
*buf = emalloc(*buf_len+1);
memset(*buf, 0, *buf_len+1);
int ret = fread(*buf, 1, *buf_len, fp);
if (ret != *buf_len)
err(EXIT_FAILURE, "fread() returned short %s", ferror(fp) ? "stream error" : feof(fp) ? "EOF reached" : "unknown error");