@@ -16,6 +16,7 @@
|
||||
#include "fileio.h"
|
||||
#include "log.h"
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
#include "utf8.h"
|
||||
|
||||
#if defined(__x86_64__)
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
/*
|
||||
* MAX_ERRNO is defined as 4095 in linux/err.h
|
||||
* We use the same value here.
|
||||
@@ -16,7 +17,7 @@ static inline const char* errno_to_name(int id) {
|
||||
if (id == 0) /* To stay in line with our own impl */
|
||||
return NULL;
|
||||
|
||||
return strerrorname_np(abs(id));
|
||||
return strerrorname_np(ABS(id));
|
||||
}
|
||||
#else
|
||||
const char* errno_to_name(int id);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
@@ -16,7 +15,7 @@
|
||||
* https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks
|
||||
*
|
||||
* Note that we use the GNU variant of strerror_r() here. */
|
||||
#define STRERROR(errnum) strerror_r(abs(errnum), (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN)
|
||||
#define STRERROR(errnum) strerror_r(ABS(errnum), (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN)
|
||||
|
||||
/* A helper to print an error message or message for functions that return 0 on EOF.
|
||||
* Note that we can't use ({ … }) to define a temporary variable, so errnum is
|
||||
@@ -41,7 +40,7 @@ static inline void _reset_errno_(int *saved_errno) {
|
||||
|
||||
#define LOCAL_ERRNO(value) \
|
||||
PROTECT_ERRNO; \
|
||||
errno = abs(value)
|
||||
errno = ABS(value)
|
||||
|
||||
static inline int negative_errno(void) {
|
||||
/* This helper should be used to shut up gcc if you know 'errno' is
|
||||
@@ -93,15 +92,14 @@ static inline int errno_or_else(int fallback) {
|
||||
if (errno > 0)
|
||||
return -errno;
|
||||
|
||||
return -abs(fallback);
|
||||
return -ABS(fallback);
|
||||
}
|
||||
|
||||
/* abs(3) says: Trying to take the absolute value of the most negative integer is not defined. */
|
||||
#define _DEFINE_ABS_WRAPPER(name) \
|
||||
static inline bool ERRNO_IS_##name(intmax_t r) { \
|
||||
if (r == INTMAX_MIN) \
|
||||
return false; \
|
||||
return ERRNO_IS_NEG_##name(-imaxabs(r)); \
|
||||
return ERRNO_IS_NEG_##name(-ABS(r)); \
|
||||
}
|
||||
|
||||
assert_cc(INT_MAX <= INTMAX_MAX);
|
||||
|
||||
+35
-43
@@ -138,11 +138,6 @@ struct hashmap_debug_info {
|
||||
LIST_FIELDS(struct hashmap_debug_info, debug_list);
|
||||
unsigned max_entries; /* high watermark of n_entries */
|
||||
|
||||
/* who allocated this hashmap */
|
||||
int line;
|
||||
const char *file;
|
||||
const char *func;
|
||||
|
||||
/* fields to detect modification while iterating */
|
||||
unsigned put_count; /* counts puts into the hashmap */
|
||||
unsigned rem_count; /* counts removals from hashmap */
|
||||
@@ -778,7 +773,7 @@ static void shared_hash_key_initialize(void) {
|
||||
random_bytes(shared_hash_key, sizeof(shared_hash_key));
|
||||
}
|
||||
|
||||
static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) {
|
||||
static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type) {
|
||||
HashmapBase *h;
|
||||
const struct hashmap_type_info *hi = &hashmap_type_info[type];
|
||||
|
||||
@@ -803,9 +798,6 @@ static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enu
|
||||
assert_se(pthread_once(&once, shared_hash_key_initialize) == 0);
|
||||
|
||||
#if ENABLE_DEBUG_HASHMAP
|
||||
h->debug.func = func;
|
||||
h->debug.file = file;
|
||||
h->debug.line = line;
|
||||
assert_se(pthread_mutex_lock(&hashmap_debug_list_mutex) == 0);
|
||||
LIST_PREPEND(debug_list, hashmap_debug_list, &h->debug);
|
||||
assert_se(pthread_mutex_unlock(&hashmap_debug_list_mutex) == 0);
|
||||
@@ -814,20 +806,20 @@ static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enu
|
||||
return h;
|
||||
}
|
||||
|
||||
Hashmap *_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
|
||||
return (Hashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_PLAIN HASHMAP_DEBUG_PASS_ARGS);
|
||||
Hashmap *hashmap_new(const struct hash_ops *hash_ops) {
|
||||
return (Hashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_PLAIN);
|
||||
}
|
||||
|
||||
OrderedHashmap *_ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
|
||||
return (OrderedHashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_ORDERED HASHMAP_DEBUG_PASS_ARGS);
|
||||
OrderedHashmap *ordered_hashmap_new(const struct hash_ops *hash_ops) {
|
||||
return (OrderedHashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_ORDERED);
|
||||
}
|
||||
|
||||
Set *_set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
|
||||
return (Set*) hashmap_base_new(hash_ops, HASHMAP_TYPE_SET HASHMAP_DEBUG_PASS_ARGS);
|
||||
Set *set_new(const struct hash_ops *hash_ops) {
|
||||
return (Set*) hashmap_base_new(hash_ops, HASHMAP_TYPE_SET);
|
||||
}
|
||||
|
||||
static int hashmap_base_ensure_allocated(HashmapBase **h, const struct hash_ops *hash_ops,
|
||||
enum HashmapType type HASHMAP_DEBUG_PARAMS) {
|
||||
enum HashmapType type) {
|
||||
HashmapBase *q;
|
||||
|
||||
assert(h);
|
||||
@@ -835,7 +827,7 @@ static int hashmap_base_ensure_allocated(HashmapBase **h, const struct hash_ops
|
||||
if (*h)
|
||||
return 0;
|
||||
|
||||
q = hashmap_base_new(hash_ops, type HASHMAP_DEBUG_PASS_ARGS);
|
||||
q = hashmap_base_new(hash_ops, type);
|
||||
if (!q)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -843,52 +835,52 @@ static int hashmap_base_ensure_allocated(HashmapBase **h, const struct hash_ops
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
|
||||
return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_PLAIN HASHMAP_DEBUG_PASS_ARGS);
|
||||
int hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops) {
|
||||
return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_PLAIN);
|
||||
}
|
||||
|
||||
int _ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
|
||||
return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_ORDERED HASHMAP_DEBUG_PASS_ARGS);
|
||||
int ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops) {
|
||||
return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_ORDERED);
|
||||
}
|
||||
|
||||
int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
|
||||
return hashmap_base_ensure_allocated((HashmapBase**)s, hash_ops, HASHMAP_TYPE_SET HASHMAP_DEBUG_PASS_ARGS);
|
||||
int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops) {
|
||||
return hashmap_base_ensure_allocated((HashmapBase**)s, hash_ops, HASHMAP_TYPE_SET);
|
||||
}
|
||||
|
||||
int _hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) {
|
||||
int hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value) {
|
||||
int r;
|
||||
|
||||
r = _hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = hashmap_ensure_allocated(h, hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return hashmap_put(*h, key, value);
|
||||
}
|
||||
|
||||
int _ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) {
|
||||
int ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value) {
|
||||
int r;
|
||||
|
||||
r = _ordered_hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = ordered_hashmap_ensure_allocated(h, hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return ordered_hashmap_put(*h, key, value);
|
||||
}
|
||||
|
||||
int _ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) {
|
||||
int ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value) {
|
||||
int r;
|
||||
|
||||
r = _ordered_hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = ordered_hashmap_ensure_allocated(h, hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return ordered_hashmap_replace(*h, key, value);
|
||||
}
|
||||
|
||||
int _hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) {
|
||||
int hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value) {
|
||||
int r;
|
||||
|
||||
r = _hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = hashmap_ensure_allocated(h, hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1290,20 +1282,20 @@ int set_put(Set *s, const void *key) {
|
||||
return hashmap_put_boldly(s, hash, &swap, true);
|
||||
}
|
||||
|
||||
int _set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key HASHMAP_DEBUG_PARAMS) {
|
||||
int set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key) {
|
||||
int r;
|
||||
|
||||
r = _set_ensure_allocated(s, hash_ops HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = _set_ensure_allocated(s, hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return set_put(*s, key);
|
||||
}
|
||||
|
||||
int _set_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key HASHMAP_DEBUG_PARAMS) {
|
||||
int set_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key) {
|
||||
int r;
|
||||
|
||||
r = _set_ensure_put(s, hash_ops, key HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = set_ensure_put(s, hash_ops, key);
|
||||
if (r <= 0) {
|
||||
if (hash_ops && hash_ops->free_key)
|
||||
hash_ops->free_key(key);
|
||||
@@ -1754,13 +1746,13 @@ int _hashmap_move_one(HashmapBase *h, HashmapBase *other, const void *key) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) {
|
||||
HashmapBase* _hashmap_copy(HashmapBase *h) {
|
||||
HashmapBase *copy;
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
|
||||
copy = hashmap_base_new(h->hash_ops, h->type HASHMAP_DEBUG_PASS_ARGS);
|
||||
copy = hashmap_base_new(h->hash_ops, h->type);
|
||||
if (!copy)
|
||||
return NULL;
|
||||
|
||||
@@ -1850,10 +1842,10 @@ int set_consume(Set *s, void *value) {
|
||||
return r;
|
||||
}
|
||||
|
||||
int _hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v HASHMAP_DEBUG_PARAMS) {
|
||||
int hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v) {
|
||||
int r;
|
||||
|
||||
r = _hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = hashmap_ensure_allocated(h, hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1884,14 +1876,14 @@ int _hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const
|
||||
return r;
|
||||
}
|
||||
|
||||
int _set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *p, size_t n HASHMAP_DEBUG_PARAMS) {
|
||||
int set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *p, size_t n) {
|
||||
char *c;
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
assert(p);
|
||||
|
||||
r = _set_ensure_allocated(s, hash_ops HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = _set_ensure_allocated(s, hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1908,13 +1900,13 @@ int _set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *
|
||||
return set_consume(*s, c);
|
||||
}
|
||||
|
||||
int _set_put_strdupv_full(Set **s, const struct hash_ops *hash_ops, char **l HASHMAP_DEBUG_PARAMS) {
|
||||
int set_put_strdupv_full(Set **s, const struct hash_ops *hash_ops, char **l) {
|
||||
int n = 0, r;
|
||||
|
||||
assert(s);
|
||||
|
||||
STRV_FOREACH(i, l) {
|
||||
r = _set_put_strndup_full(s, hash_ops, *i, SIZE_MAX HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = set_put_strndup_full(s, hash_ops, *i, SIZE_MAX);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
+19
-34
@@ -73,20 +73,8 @@ typedef struct {
|
||||
(Hashmap*)(h), \
|
||||
(void)0)
|
||||
|
||||
#if ENABLE_DEBUG_HASHMAP
|
||||
# define HASHMAP_DEBUG_PARAMS , const char *func, const char *file, int line
|
||||
# define HASHMAP_DEBUG_SRC_ARGS , __func__, PROJECT_FILE, __LINE__
|
||||
# define HASHMAP_DEBUG_PASS_ARGS , func, file, line
|
||||
#else
|
||||
# define HASHMAP_DEBUG_PARAMS
|
||||
# define HASHMAP_DEBUG_SRC_ARGS
|
||||
# define HASHMAP_DEBUG_PASS_ARGS
|
||||
#endif
|
||||
|
||||
Hashmap* _hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
|
||||
OrderedHashmap* _ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
|
||||
#define hashmap_new(ops) _hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS)
|
||||
#define ordered_hashmap_new(ops) _ordered_hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS)
|
||||
Hashmap* hashmap_new(const struct hash_ops *hash_ops);
|
||||
OrderedHashmap* ordered_hashmap_new(const struct hash_ops *hash_ops);
|
||||
|
||||
#define hashmap_free_and_replace(a, b) \
|
||||
free_and_replace_full(a, b, hashmap_free)
|
||||
@@ -104,25 +92,21 @@ static inline OrderedHashmap* ordered_hashmap_free(OrderedHashmap *h) {
|
||||
IteratedCache* iterated_cache_free(IteratedCache *cache);
|
||||
int iterated_cache_get(IteratedCache *cache, const void ***res_keys, const void ***res_values, unsigned *res_n_entries);
|
||||
|
||||
HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS);
|
||||
#define hashmap_copy(h) ((Hashmap*) _hashmap_copy(HASHMAP_BASE(h) HASHMAP_DEBUG_SRC_ARGS))
|
||||
#define ordered_hashmap_copy(h) ((OrderedHashmap*) _hashmap_copy(HASHMAP_BASE(h) HASHMAP_DEBUG_SRC_ARGS))
|
||||
HashmapBase* _hashmap_copy(HashmapBase *h);
|
||||
static inline Hashmap* hashmap_copy(Hashmap *h) {
|
||||
return (Hashmap*) _hashmap_copy(HASHMAP_BASE(h));
|
||||
}
|
||||
static inline OrderedHashmap* ordered_hashmap_copy(OrderedHashmap *h) {
|
||||
return (OrderedHashmap*) _hashmap_copy(HASHMAP_BASE(h));
|
||||
}
|
||||
|
||||
int _hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
|
||||
int _hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS);
|
||||
int _ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
|
||||
int _hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS);
|
||||
int hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops);
|
||||
int hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value);
|
||||
int ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops);
|
||||
int hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value);
|
||||
|
||||
#define hashmap_ensure_allocated(h, ops) _hashmap_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS)
|
||||
#define hashmap_ensure_put(s, ops, key, value) _hashmap_ensure_put(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS)
|
||||
#define ordered_hashmap_ensure_allocated(h, ops) _ordered_hashmap_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS)
|
||||
#define hashmap_ensure_replace(s, ops, key, value) _hashmap_ensure_replace(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS)
|
||||
|
||||
int _ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS);
|
||||
#define ordered_hashmap_ensure_put(s, ops, key, value) _ordered_hashmap_ensure_put(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS)
|
||||
|
||||
int _ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS);
|
||||
#define ordered_hashmap_ensure_replace(s, ops, key, value) _ordered_hashmap_ensure_replace(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS)
|
||||
int ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value);
|
||||
int ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value);
|
||||
|
||||
IteratedCache* _hashmap_iterated_cache_new(HashmapBase *h);
|
||||
static inline IteratedCache* hashmap_iterated_cache_new(Hashmap *h) {
|
||||
@@ -137,9 +121,10 @@ static inline int ordered_hashmap_put(OrderedHashmap *h, const void *key, void *
|
||||
return hashmap_put(PLAIN_HASHMAP(h), key, value);
|
||||
}
|
||||
|
||||
int _hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v HASHMAP_DEBUG_PARAMS);
|
||||
#define hashmap_put_strdup_full(h, hash_ops, k, v) _hashmap_put_strdup_full(h, hash_ops, k, v HASHMAP_DEBUG_SRC_ARGS)
|
||||
#define hashmap_put_strdup(h, k, v) hashmap_put_strdup_full(h, &string_hash_ops_free_free, k, v)
|
||||
int hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v);
|
||||
static inline int hashmap_put_strdup(Hashmap **h, const char *k, const char *v) {
|
||||
return hashmap_put_strdup_full(h, &string_hash_ops_free_free, k, v);
|
||||
}
|
||||
|
||||
int hashmap_update(Hashmap *h, const void *key, void *value);
|
||||
static inline int ordered_hashmap_update(OrderedHashmap *h, const void *key, void *value) {
|
||||
|
||||
+2
-2
@@ -33,9 +33,9 @@ typedef enum LogTarget{
|
||||
#define LOG_NULL (LOG_EMERG - 1)
|
||||
assert_cc(LOG_NULL == -1);
|
||||
|
||||
#define SYNTHETIC_ERRNO(num) (abs(num) | (1 << 30))
|
||||
#define SYNTHETIC_ERRNO(num) (ABS(num) | (1 << 30))
|
||||
#define IS_SYNTHETIC_ERRNO(val) (((val) >> 30) == 1)
|
||||
#define ERRNO_VALUE(val) (abs(val) & ~(1 << 30))
|
||||
#define ERRNO_VALUE(val) (ABS(val) & ~(1 << 30))
|
||||
|
||||
/* The callback function to be invoked when syntax warnings are seen
|
||||
* in the unit files. */
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ static inline size_t GREEDY_ALLOC_ROUND_UP(size_t l) {
|
||||
|
||||
#define return_with_errno(r, err) \
|
||||
do { \
|
||||
errno = abs(err); \
|
||||
errno = ABS(err); \
|
||||
return r; \
|
||||
} while (false)
|
||||
|
||||
|
||||
@@ -244,7 +244,13 @@ filesystem_includes = files(
|
||||
)
|
||||
|
||||
check_filesystems = find_program('check-filesystems.sh')
|
||||
r = run_command([check_filesystems, cpp, files('filesystems-gperf.gperf')] + filesystem_includes, check: false)
|
||||
r = run_command(
|
||||
[
|
||||
'env', '--chdir', meson.project_build_root(),
|
||||
check_filesystems, cpp, files('filesystems-gperf.gperf')
|
||||
] + filesystem_includes,
|
||||
check: false,
|
||||
)
|
||||
if r.returncode() != 0
|
||||
warning('Unknown filesystems defined in kernel headers:\n\n' + r.stdout())
|
||||
endif
|
||||
|
||||
@@ -4,21 +4,21 @@
|
||||
#include "ordered-set.h"
|
||||
#include "strv.h"
|
||||
|
||||
int _ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops HASHMAP_DEBUG_PARAMS) {
|
||||
int ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops) {
|
||||
if (*s)
|
||||
return 0;
|
||||
|
||||
*s = _ordered_set_new(ops HASHMAP_DEBUG_PASS_ARGS);
|
||||
*s = ordered_set_new(ops);
|
||||
if (!*s)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p HASHMAP_DEBUG_PARAMS) {
|
||||
int ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p) {
|
||||
int r;
|
||||
|
||||
r = _ordered_set_ensure_allocated(s, ops HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = ordered_set_ensure_allocated(s, ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -35,14 +35,14 @@ int ordered_set_consume(OrderedSet *s, void *p) {
|
||||
return r;
|
||||
}
|
||||
|
||||
int _ordered_set_put_strdup(OrderedSet **s, const char *p HASHMAP_DEBUG_PARAMS) {
|
||||
int ordered_set_put_strdup(OrderedSet **s, const char *p) {
|
||||
char *c;
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
assert(p);
|
||||
|
||||
r = _ordered_set_ensure_allocated(s, &string_hash_ops_free HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = ordered_set_ensure_allocated(s, &string_hash_ops_free);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -56,11 +56,11 @@ int _ordered_set_put_strdup(OrderedSet **s, const char *p HASHMAP_DEBUG_PARAMS)
|
||||
return ordered_set_consume(*s, c);
|
||||
}
|
||||
|
||||
int _ordered_set_put_strdupv(OrderedSet **s, char **l HASHMAP_DEBUG_PARAMS) {
|
||||
int ordered_set_put_strdupv(OrderedSet **s, char **l) {
|
||||
int n = 0, r;
|
||||
|
||||
STRV_FOREACH(i, l) {
|
||||
r = _ordered_set_put_strdup(s, *i HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = ordered_set_put_strdup(s, *i);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
+6
-11
@@ -7,16 +7,13 @@
|
||||
|
||||
typedef struct OrderedSet OrderedSet;
|
||||
|
||||
static inline OrderedSet* _ordered_set_new(const struct hash_ops *ops HASHMAP_DEBUG_PARAMS) {
|
||||
return (OrderedSet*) _ordered_hashmap_new(ops HASHMAP_DEBUG_PASS_ARGS);
|
||||
static inline OrderedSet* ordered_set_new(const struct hash_ops *ops) {
|
||||
return (OrderedSet*) ordered_hashmap_new(ops);
|
||||
}
|
||||
#define ordered_set_new(ops) _ordered_set_new(ops HASHMAP_DEBUG_SRC_ARGS)
|
||||
|
||||
int _ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops HASHMAP_DEBUG_PARAMS);
|
||||
#define ordered_set_ensure_allocated(s, ops) _ordered_set_ensure_allocated(s, ops HASHMAP_DEBUG_SRC_ARGS)
|
||||
int ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops);
|
||||
|
||||
int _ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p HASHMAP_DEBUG_PARAMS);
|
||||
#define ordered_set_ensure_put(s, hash_ops, key) _ordered_set_ensure_put(s, hash_ops, key HASHMAP_DEBUG_SRC_ARGS)
|
||||
int ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p);
|
||||
|
||||
static inline void ordered_set_clear(OrderedSet *s) {
|
||||
return ordered_hashmap_clear((OrderedHashmap*) s);
|
||||
@@ -71,10 +68,8 @@ static inline int ordered_set_reserve(OrderedSet *s, unsigned entries_add) {
|
||||
}
|
||||
|
||||
int ordered_set_consume(OrderedSet *s, void *p);
|
||||
int _ordered_set_put_strdup(OrderedSet **s, const char *p HASHMAP_DEBUG_PARAMS);
|
||||
#define ordered_set_put_strdup(s, p) _ordered_set_put_strdup(s, p HASHMAP_DEBUG_SRC_ARGS)
|
||||
int _ordered_set_put_strdupv(OrderedSet **s, char **l HASHMAP_DEBUG_PARAMS);
|
||||
#define ordered_set_put_strdupv(s, l) _ordered_set_put_strdupv(s, l HASHMAP_DEBUG_SRC_ARGS)
|
||||
int ordered_set_put_strdup(OrderedSet **s, const char *p);
|
||||
int ordered_set_put_strdupv(OrderedSet **s, char **l);
|
||||
int ordered_set_put_string_set(OrderedSet **s, OrderedSet *l);
|
||||
void ordered_set_print(FILE *f, const char *field, OrderedSet *s);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "format-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "parse-util.h"
|
||||
#include "process-util.h"
|
||||
#include "rlimit-util.h"
|
||||
#include "string-table.h"
|
||||
|
||||
+8
-13
@@ -8,17 +8,16 @@
|
||||
#define set_free_and_replace(a, b) \
|
||||
free_and_replace_full(a, b, set_free)
|
||||
|
||||
Set* _set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
|
||||
#define set_new(ops) _set_new(ops HASHMAP_DEBUG_SRC_ARGS)
|
||||
Set* set_new(const struct hash_ops *hash_ops);
|
||||
|
||||
static inline Set* set_free(Set *s) {
|
||||
return (Set*) _hashmap_free(HASHMAP_BASE(s));
|
||||
}
|
||||
|
||||
#define set_copy(s) ((Set*) _hashmap_copy(HASHMAP_BASE(s) HASHMAP_DEBUG_SRC_ARGS))
|
||||
#define set_copy(s) ((Set*) _hashmap_copy(HASHMAP_BASE(s)))
|
||||
|
||||
int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
|
||||
#define set_ensure_allocated(h, ops) _set_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS)
|
||||
int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops);
|
||||
#define set_ensure_allocated(h, ops) _set_ensure_allocated(h, ops)
|
||||
|
||||
int set_put(Set *s, const void *key);
|
||||
/* no set_update */
|
||||
@@ -93,22 +92,18 @@ static inline char **set_get_strv(Set *s) {
|
||||
|
||||
char** set_to_strv(Set **s);
|
||||
|
||||
int _set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key HASHMAP_DEBUG_PARAMS);
|
||||
#define set_ensure_put(s, hash_ops, key) _set_ensure_put(s, hash_ops, key HASHMAP_DEBUG_SRC_ARGS)
|
||||
int set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key);
|
||||
|
||||
int _set_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key HASHMAP_DEBUG_PARAMS);
|
||||
#define set_ensure_consume(s, hash_ops, key) _set_ensure_consume(s, hash_ops, key HASHMAP_DEBUG_SRC_ARGS)
|
||||
int set_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key);
|
||||
|
||||
int set_consume(Set *s, void *value);
|
||||
|
||||
int _set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *p, size_t n HASHMAP_DEBUG_PARAMS);
|
||||
#define set_put_strndup_full(s, hash_ops, p, n) _set_put_strndup_full(s, hash_ops, p, n HASHMAP_DEBUG_SRC_ARGS)
|
||||
int set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *p, size_t n);
|
||||
#define set_put_strdup_full(s, hash_ops, p) set_put_strndup_full(s, hash_ops, p, SIZE_MAX)
|
||||
#define set_put_strndup(s, p, n) set_put_strndup_full(s, &string_hash_ops_free, p, n)
|
||||
#define set_put_strdup(s, p) set_put_strndup(s, p, SIZE_MAX)
|
||||
|
||||
int _set_put_strdupv_full(Set **s, const struct hash_ops *hash_ops, char **l HASHMAP_DEBUG_PARAMS);
|
||||
#define set_put_strdupv_full(s, hash_ops, l) _set_put_strdupv_full(s, hash_ops, l HASHMAP_DEBUG_SRC_ARGS)
|
||||
int set_put_strdupv_full(Set **s, const struct hash_ops *hash_ops, char **l );
|
||||
#define set_put_strdupv(s, l) set_put_strdupv_full(s, &string_hash_ops_free, l)
|
||||
|
||||
int set_put_strsplit(Set *s, const char *v, const char *separators, ExtractFlags flags);
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "parse-util.h"
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
|
||||
ssize_t string_table_lookup(const char * const *table, size_t len, const char *key) {
|
||||
const char* string_table_lookup_to_string(const char * const *table, size_t len, ssize_t i) {
|
||||
if (i < 0 || i >= (ssize_t) len)
|
||||
return NULL;
|
||||
|
||||
return table[i];
|
||||
}
|
||||
|
||||
ssize_t string_table_lookup_from_string(const char * const *table, size_t len, const char *key) {
|
||||
if (!key)
|
||||
return -EINVAL;
|
||||
|
||||
@@ -13,3 +21,49 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ssize_t string_table_lookup_from_string_with_boolean(const char * const *table, size_t len, const char *key, ssize_t yes) {
|
||||
if (!key)
|
||||
return -EINVAL;
|
||||
|
||||
int b = parse_boolean(key);
|
||||
if (b == 0)
|
||||
return 0;
|
||||
if (b > 0)
|
||||
return yes;
|
||||
|
||||
return string_table_lookup_from_string(table, len, key);
|
||||
}
|
||||
|
||||
int string_table_lookup_to_string_fallback(const char * const *table, size_t len, ssize_t i, size_t max, char **ret) {
|
||||
char *s;
|
||||
|
||||
if (i < 0 || i > (ssize_t) max)
|
||||
return -ERANGE;
|
||||
if (i < (ssize_t) len && table[i]) {
|
||||
s = strdup(table[i]);
|
||||
if (!s)
|
||||
return -ENOMEM;
|
||||
} else if (asprintf(&s, "%zd", i) < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t string_table_lookup_from_string_fallback(const char * const *table, size_t len, const char *s, size_t max) {
|
||||
unsigned u = 0;
|
||||
|
||||
if (!s)
|
||||
return -EINVAL;
|
||||
|
||||
ssize_t i = string_table_lookup_from_string(table, len, s);
|
||||
if (i >= 0)
|
||||
return i;
|
||||
if (safe_atou(s, &u) < 0)
|
||||
return -EINVAL;
|
||||
if (u > max)
|
||||
return -EINVAL;
|
||||
|
||||
return u;
|
||||
}
|
||||
|
||||
+49
-74
@@ -2,105 +2,80 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "parse-util.h"
|
||||
#include "string-util.h"
|
||||
|
||||
ssize_t string_table_lookup(const char * const *table, size_t len, const char *key);
|
||||
const char* string_table_lookup_to_string(const char * const *table, size_t len, ssize_t i);
|
||||
|
||||
ssize_t string_table_lookup_from_string(const char * const *table, size_t len, const char *key);
|
||||
|
||||
ssize_t string_table_lookup_from_string_with_boolean(const char * const *table, size_t len, const char *key, ssize_t yes);
|
||||
|
||||
int string_table_lookup_to_string_fallback(const char * const *table, size_t len, ssize_t i, size_t max, char **ret);
|
||||
|
||||
ssize_t string_table_lookup_from_string_fallback(const char * const *table, size_t len, const char *s, size_t max);
|
||||
|
||||
/* For basic lookup tables with strictly enumerated entries */
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \
|
||||
scope const char* name##_to_string(type i) { \
|
||||
if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \
|
||||
return NULL; \
|
||||
return name##_table[i]; \
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, scope) \
|
||||
scope const char* name##_to_string(type i) { \
|
||||
return string_table_lookup_to_string(name##_table, ELEMENTSOF(name##_table), i); \
|
||||
}
|
||||
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \
|
||||
scope type name##_from_string(const char *s) { \
|
||||
return (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, scope) \
|
||||
scope type name##_from_string(const char *s) { \
|
||||
return (type) string_table_lookup_from_string(name##_table, ELEMENTSOF(name##_table), s); \
|
||||
}
|
||||
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes,scope) \
|
||||
scope type name##_from_string(const char *s) { \
|
||||
if (!s) \
|
||||
return -EINVAL; \
|
||||
int b = parse_boolean(s); \
|
||||
if (b == 0) \
|
||||
return (type) 0; \
|
||||
if (b > 0) \
|
||||
return yes; \
|
||||
return (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name, type, yes, scope) \
|
||||
scope type name##_from_string(const char *s) { \
|
||||
return (type) string_table_lookup_from_string_with_boolean(name##_table, ELEMENTSOF(name##_table), s, yes); \
|
||||
}
|
||||
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max,scope) \
|
||||
scope int name##_to_string_alloc(type i, char **str) { \
|
||||
char *s; \
|
||||
if (i < 0 || i > max) \
|
||||
return -ERANGE; \
|
||||
if (i < (type) ELEMENTSOF(name##_table) && name##_table[i]) { \
|
||||
s = strdup(name##_table[i]); \
|
||||
if (!s) \
|
||||
return -ENOMEM; \
|
||||
} else if (asprintf(&s, "%i", i) < 0) \
|
||||
return -ENOMEM; \
|
||||
*str = s; \
|
||||
return 0; \
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type, max, scope) \
|
||||
scope int name##_to_string_alloc(type i, char **ret) { \
|
||||
return string_table_lookup_to_string_fallback(name##_table, ELEMENTSOF(name##_table), i, max, ret); \
|
||||
}
|
||||
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,scope) \
|
||||
scope type name##_from_string(const char *s) { \
|
||||
unsigned u = 0; \
|
||||
type i; \
|
||||
if (!s) \
|
||||
return -EINVAL; \
|
||||
i = (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \
|
||||
if (i >= 0) \
|
||||
return i; \
|
||||
if (safe_atou(s, &u) < 0) \
|
||||
return -EINVAL; \
|
||||
if (u > max) \
|
||||
return -EINVAL; \
|
||||
return (type) u; \
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max, scope) \
|
||||
scope type name##_from_string(const char *s) { \
|
||||
return (type) string_table_lookup_from_string_fallback(name##_table, ELEMENTSOF(name##_table), s, max); \
|
||||
}
|
||||
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope)
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP(name, type, scope) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, scope) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, scope)
|
||||
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes,scope) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes,scope)
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes, scope) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, scope) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name, type, yes, scope)
|
||||
|
||||
#define DEFINE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,)
|
||||
#define DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,)
|
||||
#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,static)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,static)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,static)
|
||||
#define DEFINE_STRING_TABLE_LOOKUP(name, type) _DEFINE_STRING_TABLE_LOOKUP(name, type,)
|
||||
#define DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type,)
|
||||
#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type,)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name, type) _DEFINE_STRING_TABLE_LOOKUP(name, type, static)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, static)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, static)
|
||||
|
||||
#define DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes) _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes,)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes) _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes,static)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes,static)
|
||||
#define DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes) _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes,)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes) _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes, static)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name, type, yes) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name, type, yes, static)
|
||||
|
||||
/* For string conversions where numbers are also acceptable */
|
||||
#define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name,type,max) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max,) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,)
|
||||
#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_FALLBACK(name,type,max) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,)
|
||||
#define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name, type, max) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type, max,) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max,)
|
||||
#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_FALLBACK(name, type, max) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max,)
|
||||
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max,static)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,static)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type, max) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type, max, static)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max, static)
|
||||
|
||||
#define DUMP_STRING_TABLE(name,type,max) \
|
||||
#define DUMP_STRING_TABLE(name, type, max) \
|
||||
({ \
|
||||
flockfile(stdout); \
|
||||
for (type _k = 0; _k < (max); _k++) { \
|
||||
|
||||
+4
-4
@@ -1126,28 +1126,28 @@ static int string_strv_hashmap_put_internal(Hashmap *h, const char *key, const c
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _string_strv_hashmap_put(Hashmap **h, const char *key, const char *value HASHMAP_DEBUG_PARAMS) {
|
||||
int string_strv_hashmap_put(Hashmap **h, const char *key, const char *value) {
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
assert(key);
|
||||
assert(value);
|
||||
|
||||
r = _hashmap_ensure_allocated(h, &string_hash_ops_free_strv_free HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = hashmap_ensure_allocated(h, &string_hash_ops_free_strv_free);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return string_strv_hashmap_put_internal(*h, key, value);
|
||||
}
|
||||
|
||||
int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value HASHMAP_DEBUG_PARAMS) {
|
||||
int string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value) {
|
||||
int r;
|
||||
|
||||
assert(h);
|
||||
assert(key);
|
||||
assert(value);
|
||||
|
||||
r = _ordered_hashmap_ensure_allocated(h, &string_hash_ops_free_strv_free HASHMAP_DEBUG_PASS_ARGS);
|
||||
r = ordered_hashmap_ensure_allocated(h, &string_hash_ops_free_strv_free);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
+4
-4
@@ -262,10 +262,10 @@ void string_strv_hashmap_remove(Hashmap *h, const char *key, const char *value);
|
||||
static inline void string_strv_ordered_hashmap_remove(OrderedHashmap *h, const char *key, const char *value) {
|
||||
string_strv_hashmap_remove(PLAIN_HASHMAP(h), key, value);
|
||||
}
|
||||
int _string_strv_hashmap_put(Hashmap **h, const char *key, const char *value HASHMAP_DEBUG_PARAMS);
|
||||
int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value HASHMAP_DEBUG_PARAMS);
|
||||
#define string_strv_hashmap_put(h, k, v) _string_strv_hashmap_put(h, k, v HASHMAP_DEBUG_SRC_ARGS)
|
||||
#define string_strv_ordered_hashmap_put(h, k, v) _string_strv_ordered_hashmap_put(h, k, v HASHMAP_DEBUG_SRC_ARGS)
|
||||
int _string_strv_hashmap_put(Hashmap **h, const char *key, const char *value);
|
||||
int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value);
|
||||
#define string_strv_hashmap_put(h, k, v) _string_strv_hashmap_put(h, k, v)
|
||||
#define string_strv_ordered_hashmap_put(h, k, v) _string_strv_ordered_hashmap_put(h, k, v)
|
||||
|
||||
int strv_rebreak_lines(char **l, size_t width, char ***ret);
|
||||
|
||||
|
||||
@@ -1785,7 +1785,7 @@ DEFINE_STRING_TABLE_LOOKUP_TO_STRING(timestamp_style, TimestampStyle);
|
||||
TimestampStyle timestamp_style_from_string(const char *s) {
|
||||
TimestampStyle t;
|
||||
|
||||
t = (TimestampStyle) string_table_lookup(timestamp_style_table, ELEMENTSOF(timestamp_style_table), s);
|
||||
t = (TimestampStyle) string_table_lookup_from_string(timestamp_style_table, ELEMENTSOF(timestamp_style_table), s);
|
||||
if (t >= 0)
|
||||
return t;
|
||||
if (STRPTR_IN_SET(s, "µs", "μs")) /* accept both µ symbols in unicode, i.e. micro symbol + Greek small letter mu. */
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "namespace-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "process-util.h"
|
||||
#include "stat-util.h"
|
||||
#include "string-table.h"
|
||||
|
||||
Reference in New Issue
Block a user