]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
database: Improve error reporting when the magic cannot be read
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 Aug 2022 14:06:53 +0000 (14:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 Aug 2022 14:06:53 +0000 (14:06 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c

index b28166ab6649b64f2249d00d2796abff652b04c5..d2b76f8925ae5e0e66cbb29182219319126a0179 100644 (file)
@@ -142,7 +142,7 @@ static int loc_database_read_magic(struct loc_database* db) {
        if (bytes_read < sizeof(magic)) {
                ERROR(db->ctx, "Could not read enough data to validate magic bytes\n");
                DEBUG(db->ctx, "Read %zu bytes, but needed %zu\n", bytes_read, sizeof(magic));
-               return -ENOMSG;
+               goto ERROR;
        }
 
        // Compare magic bytes
@@ -155,7 +155,9 @@ static int loc_database_read_magic(struct loc_database* db) {
                return 0;
        }
 
+ERROR:
        ERROR(db->ctx, "Unrecognized file type\n");
+       errno = ENOMSG;
 
        // Return an error
        return 1;