]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: Do not set errno in libkmod-index
authorMax Kunzelmann <maxdev@posteo.de>
Tue, 12 Nov 2024 21:49:41 +0000 (22:49 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 19 Nov 2024 06:04:54 +0000 (00:04 -0600)
Don't set errno in read functions ad it's a libc interface which we
should not be overriding. None of the functions up the call stack (some
examples) check on it.

Signed-off-by: Max Kunzelmann <maxdev@posteo.de>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/240
[ Reword commit message according to suggestion by Emil and remove
  inline ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-index.c

index 4046977ce386664ea640b4d3242a63e7e05b695d..f1d74aedbd9e9b4914f42be510dc94cae24a0f38 100644 (file)
@@ -167,24 +167,16 @@ static int add_value(struct index_value **values, const char *value, size_t len,
        return 0;
 }
 
-static int read_char(FILE *in)
+static inline int read_char(FILE *in)
 {
-       int ch;
-
-       errno = 0;
-       ch = getc_unlocked(in);
-       if (ch == EOF)
-               errno = EINVAL;
-       return ch;
+       return getc_unlocked(in);
 }
 
 static bool read_u32s(FILE *in, uint32_t *l, size_t n)
 {
        size_t i;
 
-       errno = 0;
        if (fread_unlocked(l, sizeof(uint32_t), n, in) != n) {
-               errno = EINVAL;
                return false;
        }
        for (i = 0; i < n; i++)
@@ -312,7 +304,6 @@ struct index_file *index_file_open(const char *filename)
        file = fopen(filename, "re");
        if (!file)
                return NULL;
-       errno = EINVAL;
 
        if (!read_u32(file, &magic) || magic != INDEX_MAGIC)
                goto err;
@@ -332,7 +323,6 @@ struct index_file *index_file_open(const char *filename)
        new->tmp = NULL;
        new->tmp_size = 0;
 
-       errno = 0;
        return new;
 err:
        fclose(file);