aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTristan Riehs <tristan.riehs@inria.fr>2025-12-25 19:14:42 +0100
committerTristan Riehs <tristan.riehs@inria.fr>2025-12-25 19:14:42 +0100
commit1f27fe745289ae18f36484d8b646ed6bceadc5b3 (patch)
tree283bd592704ab1f8a040606851d4708ed087a5eb /src
parent0f927065eca05a73f795863196c1ca14c7540fac (diff)
Sligtly change sum function
- directly return the sum - directly exit on error
Diffstat (limited to 'src')
-rw-r--r--src/main.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/main.c b/src/main.c
index 9b17d54..02b2973 100644
--- a/src/main.c
+++ b/src/main.c
@@ -118,11 +118,10 @@ static void sanitize_sql_str(char **str)
*str = new_str;
}
-/* Compute something that identifies the content of FILE and write it to
- OUT. Algorithm from http://www.cse.yorku.ca/~oz/hash.html via
- https://stackoverflow.com/a/7666577/20138083. Return 0 on success, -1 on
- error. */
-static int sum(uint32_t *out, const char *file)
+/* Compute something that identifies the content of FILE. Algorithm by Dan
+ Bernstein from http://www.cse.yorku.ca/~oz/hash.html via
+ https://stackoverflow.com/a/7666577/20138083. */
+static uint32_t sum(const char *file)
{
FILE *stream = fopen(file, "r");
uint8_t buf[4096];
@@ -130,7 +129,7 @@ static int sum(uint32_t *out, const char *file)
uint32_t sum = 5381;
if (!file) {
perror("fopen");
- return -1;
+ exit(EXIT_FAILURE);
}
while ((buf_len = fread(&buf, 1, sizeof(buf), stream)) != 0) {
for (int i = 0; i < buf_len; i++) {
@@ -140,12 +139,10 @@ static int sum(uint32_t *out, const char *file)
}
if (ferror(stream)) {
perror("fread");
- fclose(stream);
- return -1;
+ exit(EXIT_FAILURE);
}
fclose(stream);
- *out = sum;
- return 0;
+ return sum;
}
static time_t time_from_str(const char *str)