From eb82bae2729801a0575d1d45b04d90b094f70e8f Mon Sep 17 00:00:00 2001 From: Max Kunzelmann Date: Tue, 12 Nov 2024 22:49:41 +0100 Subject: [PATCH] libkmod: Do not set errno in libkmod-index 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 Signed-off-by: Tobias Stoeckmann Reviewed-by: Emil Velikov 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 --- libkmod/libkmod-index.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index 4046977c..f1d74aed 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -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); -- 2.47.2