]> git.ipfire.org Git - collecty.git/commitdiff
file: Return the error code if we could not read the file
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Oct 2025 15:52:26 +0000 (15:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Oct 2025 15:52:26 +0000 (15:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/file.c

index 4780e734cb821a5814af288a92914d25db5dce6d..514ba02009c07ff0dc5b30d383a19b0909aafee9 100644 (file)
@@ -179,11 +179,15 @@ int td_file_walk(td_file* self,
                // Fetch the next line
                r = getline(&line, &length, self->f);
                if (r < 0) {
-                       // Reset r if have reached the end of the file
+                       // Break if we have reached the end of the line
                        if (feof(self->f))
-                               r = 0;
+                               break;
+
+                       // Handle errors
+                       if (ferror(self->f))
+                               r = -errno;
 
-                       break;
+                       goto ERROR;
                }
 
                // Remove the trailing newline
@@ -198,6 +202,9 @@ int td_file_walk(td_file* self,
                        goto ERROR;
        }
 
+       // Success
+       r = 0;
+
 ERROR:
        if (line)
                free(line);