aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
authorRandy Palamar <randy@rnpnr.xyz>2025-12-05 21:54:50 -0700
committerRandy Palamar <randy@rnpnr.xyz>2025-12-08 09:58:02 -0700
commit48fbf21a6d6085d561757afb162d9f7b98792bf9 (patch)
tree5749a9ffc34199718b2e11fdea81e184f8c68202 /map.c
parentb389733ab0fa46f2cecd302cc5826fc7dc322c8e (diff)
downloadvis-48fbf21a6d6085d561757afb162d9f7b98792bf9.tar.gz
vis-48fbf21a6d6085d561757afb162d9f7b98792bf9.tar.xz
map: stop setting errno on error
the return of these functions already give all the necessary information. this is not c standard library code, we have no need of such a nonsensical error reporting mechanism NOTE: since errno needs to be thread local accessing it from non-libc code ends up being a function call and serves as a pointless optimization barrier.
Diffstat (limited to 'map.c')
-rw-r--r--map.c31
1 files changed, 8 insertions, 23 deletions
diff --git a/map.c b/map.c
index f6e5c64..6ec02d6 100644
--- a/map.c
+++ b/map.c
@@ -11,7 +11,6 @@
*/
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
#include <inttypes.h>
#include "map.h"
@@ -63,14 +62,10 @@ void *map_get(const Map *map, const char *key)
void *map_closest(const Map *map, const char *prefix)
{
- errno = 0;
- void *v = map_get(map, prefix);
- if (v)
- return v;
- const Map *m = map_prefix(map, prefix);
- if (map_empty(m))
- errno = ENOENT;
- return m->v;
+ void *result = map_get(map, prefix);
+ if (!result)
+ result = map_prefix(map, prefix)->v;
+ return result;
}
bool map_contains(const Map *map, const char *prefix)
@@ -88,15 +83,11 @@ bool map_put(Map *map, const char *k, const void *value)
uint8_t bit_num, new_dir;
char *key;
- if (!value) {
- errno = EINVAL;
+ if (!value)
return false;
- }
- if (!(key = strdup(k))) {
- errno = ENOMEM;
+ if (!(key = strdup(k)))
return false;
- }
/* Empty map? */
if (!map->u.n) {
@@ -113,7 +104,6 @@ bool map_put(Map *map, const char *k, const void *value)
if (key[byte_num] == '\0') {
/* All identical! */
free(key);
- errno = EEXIST;
return false;
}
}
@@ -130,7 +120,6 @@ bool map_put(Map *map, const char *k, const void *value)
newn = malloc(sizeof(*newn));
if (!newn) {
free(key);
- errno = ENOMEM;
return false;
}
newn->byte_num = byte_num;
@@ -171,10 +160,8 @@ void *map_delete(Map *map, const char *key)
uint8_t direction;
/* Empty map? */
- if (!map->u.n) {
- errno = ENOENT;
+ if (!map->u.n)
return NULL;
- }
/* Find closest, but keep track of parent. */
n = map;
@@ -193,10 +180,8 @@ void *map_delete(Map *map, const char *key)
}
/* Did we find it? */
- if (strcmp(key, n->u.s)) {
- errno = ENOENT;
+ if (strcmp(key, n->u.s))
return NULL;
- }
free((char*)n->u.s);
value = n->v;