From: Olivier Matz Date: Thu, 21 Jun 2018 17:00:09 +0000 (+0200) Subject: do not clobber errno X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=48570f34e53592d7725e00e1d1e75cc28d293914;p=protos%2Flibecoli.git do not clobber errno --- diff --git a/lib/ecoli_keyval.c b/lib/ecoli_keyval.c index 97c5da8..12fe66b 100644 --- a/lib/ecoli_keyval.c +++ b/lib/ecoli_keyval.c @@ -80,10 +80,8 @@ ec_keyval_lookup(const struct ec_keyval *keyval, const char *key) h = ec_murmurhash3(key, strlen(key), ec_keyval_seed); LIST_FOREACH(ref, &keyval->table[h & mask], next) { - if (strcmp(ref->elt->key, key) == 0) { - errno = 0; + if (strcmp(ref->elt->key, key) == 0) return ref; - } } errno = ENOENT; diff --git a/lib/ecoli_log.c b/lib/ecoli_log.c index 7dbf2c8..e7577cd 100644 --- a/lib/ecoli_log.c +++ b/lib/ecoli_log.c @@ -58,8 +58,6 @@ int ec_log_default_cb(int type, enum ec_log_level level, void *opaque, int ec_log_fct_register(ec_log_t usr_log, void *opaque) { - errno = 0; - if (usr_log == NULL) { ec_log_fct = ec_log_default_cb; ec_log_opaque = NULL; diff --git a/lib/ecoli_node_file.c b/lib/ecoli_node_file.c index 09f96fc..001dcb6 100644 --- a/lib/ecoli_node_file.c +++ b/lib/ecoli_node_file.c @@ -161,13 +161,17 @@ ec_node_file_complete(const struct ec_node *gen_node, bname_len = strlen(bname); while (1) { + int save_errno = errno; + errno = 0; de = node->readdir(dir); if (de == NULL) { - if (errno == 0) + if (errno == 0) { + errno = save_errno; goto out; - else + } else { goto fail; + } } if (!ec_str_startswith(de->d_name, bname)) diff --git a/lib/ecoli_node_int.c b/lib/ecoli_node_int.c index 34fd501..c72ee04 100644 --- a/lib/ecoli_node_int.c +++ b/lib/ecoli_node_int.c @@ -43,6 +43,7 @@ static int parse_llint(struct ec_node_int_uint *node, const char *str, int64_t *val) { char *endptr; + int save_errno = errno; errno = 0; *val = strtoll(str, &endptr, node->base); @@ -66,6 +67,7 @@ static int parse_llint(struct ec_node_int_uint *node, const char *str, return -1; } + errno = save_errno; return 0; } @@ -73,6 +75,7 @@ static int parse_ullint(struct ec_node_int_uint *node, const char *str, uint64_t *val) { char *endptr; + int save_errno = errno; /* since a negative input is silently converted to a positive * one by strtoull(), first check that it is positive */ @@ -95,6 +98,7 @@ static int parse_ullint(struct ec_node_int_uint *node, const char *str, if (*endptr != 0) return -1; + errno = save_errno; return 0; }