do not clobber errno
authorOlivier Matz <zer0@droids-corp.org>
Thu, 21 Jun 2018 17:00:09 +0000 (19:00 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Thu, 21 Jun 2018 17:00:09 +0000 (19:00 +0200)
lib/ecoli_keyval.c
lib/ecoli_log.c
lib/ecoli_node_file.c
lib/ecoli_node_int.c

index 97c5da8..12fe66b 100644 (file)
@@ -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;
index 7dbf2c8..e7577cd 100644 (file)
@@ -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;
index 09f96fc..001dcb6 100644 (file)
@@ -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))
index 34fd501..c72ee04 100644 (file)
@@ -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;
 }