diff options
Diffstat (limited to 'src/libmdsserver')
-rw-r--r-- | src/libmdsserver/client-list.h | 49 | ||||
-rw-r--r-- | src/libmdsserver/config.h.in | 72 | ||||
-rw-r--r-- | src/libmdsserver/fd-table.h | 89 | ||||
-rw-r--r-- | src/libmdsserver/hash-help.h | 31 | ||||
-rw-r--r-- | src/libmdsserver/hash-list.h | 1 | ||||
-rw-r--r-- | src/libmdsserver/hash-table.h | 191 | ||||
-rw-r--r-- | src/libmdsserver/libmdsserver.pc.in | 1 | ||||
-rw-r--r-- | src/libmdsserver/linked-list.h | 143 | ||||
-rw-r--r-- | src/libmdsserver/macro-bits.h | 43 | ||||
-rw-r--r-- | src/libmdsserver/macros.h | 49 | ||||
-rw-r--r-- | src/libmdsserver/mds-message.h | 123 | ||||
-rw-r--r-- | src/libmdsserver/table-common.h | 1 | ||||
-rw-r--r-- | src/libmdsserver/util.h | 93 |
13 files changed, 425 insertions, 461 deletions
diff --git a/src/libmdsserver/client-list.h b/src/libmdsserver/client-list.h index 339f7c7..fcd9923 100644 --- a/src/libmdsserver/client-list.h +++ b/src/libmdsserver/client-list.h @@ -25,28 +25,28 @@ -#define CLIENT_LIST_T_VERSION 0 +#define CLIENT_LIST_T_VERSION 0 /** * Dynamic array of client ID:s */ typedef struct client_list { - /** - * The size of the array - */ - size_t capacity; - - /** - * The index after the last used index - */ - size_t size; - - /** - * Stored client ID:s - */ - uint64_t* clients; - + /** + * The size of the array + */ + size_t capacity; + + /** + * The index after the last used index + */ + size_t size; + + /** + * Stored client ID:s + */ + uint64_t *clients; + } client_list_t; @@ -59,7 +59,7 @@ typedef struct client_list * @return Non-zero on error, `errno` will have been set accordingly */ __attribute__((nonnull)) -int client_list_create(client_list_t* restrict this, size_t capacity); +int client_list_create(client_list_t *restrict this, size_t capacity); /** * Release all resources in a client list, should @@ -68,7 +68,7 @@ int client_list_create(client_list_t* restrict this, size_t capacity); * @param this The client list */ __attribute__((nonnull)) -void client_list_destroy(client_list_t* restrict this); +void client_list_destroy(client_list_t *restrict this); /** * Clone a client list @@ -78,7 +78,7 @@ void client_list_destroy(client_list_t* restrict this); * @return Non-zero on error, `errno` will have been set accordingly */ __attribute__((nonnull)) -int client_list_clone(const client_list_t* restrict this, client_list_t* restrict out); +int client_list_clone(const client_list_t *restrict this, client_list_t *restrict out); /** * Add a client to the list @@ -88,7 +88,7 @@ int client_list_clone(const client_list_t* restrict this, client_list_t* restric * @return Non-zero on error, `errno` will be set accordingly */ __attribute__((nonnull)) -int client_list_add(client_list_t* restrict this, uint64_t client); +int client_list_add(client_list_t *restrict this, uint64_t client); /** * Remove a client from the list, once @@ -97,7 +97,7 @@ int client_list_add(client_list_t* restrict this, uint64_t client); * @param client The client to remove */ __attribute__((nonnull)) -void client_list_remove(client_list_t* restrict this, uint64_t client); +void client_list_remove(client_list_t *restrict this, uint64_t client); /** * Calculate the buffer size need to marshal a client list @@ -106,7 +106,7 @@ void client_list_remove(client_list_t* restrict this, uint64_t client); * @return The number of bytes to allocate to the output buffer */ __attribute__((pure, nonnull)) -size_t client_list_marshal_size(const client_list_t* restrict this); +size_t client_list_marshal_size(const client_list_t *restrict this); /** * Marshals a client list @@ -115,7 +115,7 @@ size_t client_list_marshal_size(const client_list_t* restrict this); * @param data Output buffer for the marshalled data */ __attribute__((nonnull)) -void client_list_marshal(const client_list_t* restrict this, char* restrict data); +void client_list_marshal(const client_list_t *restrict this, char *restrict data); /** * Unmarshals a client list @@ -126,8 +126,7 @@ void client_list_marshal(const client_list_t* restrict this, char* restrict data * Destroy the list on error. */ __attribute__((nonnull)) -int client_list_unmarshal(client_list_t* restrict this, char* restrict data); +int client_list_unmarshal(client_list_t *restrict this, char *restrict data); #endif - diff --git a/src/libmdsserver/config.h.in b/src/libmdsserver/config.h.in index a1242f7..d018366 100644 --- a/src/libmdsserver/config.h.in +++ b/src/libmdsserver/config.h.in @@ -22,152 +22,128 @@ /** * The name under which this package is installed */ -#define PKGNAME "@PKGNAME@" - +#define PKGNAME "@PKGNAME@" /** * The directory where all servers are installed */ -#define LIBEXECDIR "@LIBEXECDIR@" - +#define LIBEXECDIR "@LIBEXECDIR@" /** * The system's directory for non-persistent temporary files */ -#define TMPDIR "@TMPDIR@" - +#define TMPDIR "@TMPDIR@" /** * The system's directory for runtime data */ -#define RUNDIR "@RUNDIR@" - +#define RUNDIR "@RUNDIR@" /** * The system's directory for site-specific configurations */ -#define SYSCONFDIR "@SYSCONFDIR@" - +#define SYSCONFDIR "@SYSCONFDIR@" /** * The system's directory for pseudo-devices */ -#define DEVDIR "@DEVDIR@" - +#define DEVDIR "@DEVDIR@" /** * Pathname pattern for virtual terminals */ -#define VT_PATH_PATTERN "@VT_PATH_PATTERN@" - +#define VT_PATH_PATTERN "@VT_PATH_PATTERN@" /** * The root directory of all runtime data stored by mds */ -#define MDS_RUNTIME_ROOT_DIRECTORY "@MDS_RUNTIME_ROOT_DIRECTORY@" - +#define MDS_RUNTIME_ROOT_DIRECTORY "@MDS_RUNTIME_ROOT_DIRECTORY@" /** * The root directory of temporarily stored data stored by mds servers */ -#define MDS_STORAGE_ROOT_DIRECTORY "@MDS_STORAGE_ROOT_DIRECTORY@" - +#define MDS_STORAGE_ROOT_DIRECTORY "@MDS_STORAGE_ROOT_DIRECTORY@" /** * The user ID for the root user */ -#define ROOT_USER_UID @ROOT_USER_UID@ - +#define ROOT_USER_UID @ROOT_USER_UID@ /** * The group ID for the root group */ -#define ROOT_GROUP_GID @ROOT_GROUP_GID@ - +#define ROOT_GROUP_GID @ROOT_GROUP_GID@ /** * The group ID for the nobody group */ -#define NOBODY_GROUP_GID @NOBODY_GROUP_GID@ +#define NOBODY_GROUP_GID @NOBODY_GROUP_GID@ /* These three names above are redundant, but that is to avoid errors. */ - /** * The byte length of the authentication token */ -#define TOKEN_LENGTH @TOKEN_LENGTH@ - +#define TOKEN_LENGTH @TOKEN_LENGTH@ /** * Random number generator to use for generating a token */ -#define TOKEN_RANDOM "@TOKEN_RANDOM@" - +#define TOKEN_RANDOM "@TOKEN_RANDOM@" /** * The path of the symlink to the executed command */ -#define SELF_EXE "@SELF_EXE@" - +#define SELF_EXE "@SELF_EXE@" /** * The path to the directory with symlinks to each file that is open */ -#define SELF_FD "@SELF_FD@" - +#define SELF_FD "@SELF_FD@" /** * Pattern for the names of shared object to which states are marshalled */ -#define SHM_PATH_PATTERN "@SHM_PATH_PATTERN@" - +#define SHM_PATH_PATTERN "@SHM_PATH_PATTERN@" /** * The maximum number of command line arguments to allow */ -#define ARGC_LIMIT @ARGC_LIMIT@ - +#define ARGC_LIMIT @ARGC_LIMIT@ /** * The number of additional arguments a libexec server may have */ -#define LIBEXEC_ARGC_EXTRA_LIMIT @LIBEXEC_ARGC_EXTRA_LIMIT@ - +#define LIBEXEC_ARGC_EXTRA_LIMIT @LIBEXEC_ARGC_EXTRA_LIMIT@ /** * The maximum number of display allowed on the system */ -#define DISPLAY_MAX @DISPLAY_MAX@ - +#define DISPLAY_MAX @DISPLAY_MAX@ /** * The name of the environment variable that * indicates the index of the display */ -#define DISPLAY_ENV "@DISPLAY_ENV@" - +#define DISPLAY_ENV "@DISPLAY_ENV@" /** * The name of the environment variable that * indicates the display server's process group */ -#define PGROUP_ENV "@PGROUP_ENV@" - +#define PGROUP_ENV "@PGROUP_ENV@" /** * The minimum time that most have elapsed * for respawning to be allowed */ -#define RESPAWN_TIME_LIMIT_SECONDS @RESPAWN_TIME_LIMIT_SECONDS@ - +#define RESPAWN_TIME_LIMIT_SECONDS @RESPAWN_TIME_LIMIT_SECONDS@ /** * The dot-prefixless basename of the initrc * file that the master server executes */ -#define INITRC_FILE "@INITRC_FILE@" +#define INITRC_FILE "@INITRC_FILE@" #endif - diff --git a/src/libmdsserver/fd-table.h b/src/libmdsserver/fd-table.h index 19d1f99..b611b43 100644 --- a/src/libmdsserver/fd-table.h +++ b/src/libmdsserver/fd-table.h @@ -25,43 +25,43 @@ -#define FD_TABLE_T_VERSION 0 +#define FD_TABLE_T_VERSION 0 /** * Value lookup table optimised for file descriptors as keys */ typedef struct fd_table { - /** - * The table's capacity, i.e. how many entries that can be stored, - * in total, before its internal table needs to grow - */ - size_t capacity; - - /** - * The number of entries stored in the table - */ - size_t size; - - /** - * Map from keys to values - */ - size_t* values; - - /** - * Map from keys to whether that are in used, bit-packed - */ - uint64_t* used; - - /** - * Check whether two values are equal - * - * If this function pointer is `NULL`, the identity is used - * - * Be aware, this variable cannot be marshalled - */ - compare_func* value_comparator; - + /** + * The table's capacity, i.e. how many entries that can be stored, + * in total, before its internal table needs to grow + */ + size_t capacity; + + /** + * The number of entries stored in the table + */ + size_t size; + + /** + * Map from keys to values + */ + size_t *values; + + /** + * Map from keys to whether that are in used, bit-packed + */ + uint64_t *used; + + /** + * Check whether two values are equal + * + * If this function pointer is `NULL`, the identity is used + * + * Be aware, this variable cannot be marshalled + */ + compare_func *value_comparator; + } fd_table_t; @@ -74,7 +74,7 @@ typedef struct fd_table * @return Non-zero on error, `errno` will have been set accordingly */ __attribute__((nonnull)) -int fd_table_create_tuned(fd_table_t* restrict this, size_t initial_capacity); +int fd_table_create_tuned(fd_table_t *restrict this, size_t initial_capacity); /** * Create a fd table @@ -82,8 +82,8 @@ int fd_table_create_tuned(fd_table_t* restrict this, size_t initial_capacity); * @param this:fd_table_t* Memory slot in which to store the new fd table * @return :int Non-zero on error, `errno` will have been set accordingly */ -#define fd_table_create(this) \ - fd_table_create_tuned(this, 16) +#define fd_table_create(this)\ + fd_table_create_tuned(this, 16) /** * Release all resources in a fd table, should @@ -94,7 +94,7 @@ int fd_table_create_tuned(fd_table_t* restrict this, size_t initial_capacity); * @param values_freer Function that frees a value, `NULL` if value should not be freed */ __attribute__((nonnull(1))) -void fd_table_destroy(fd_table_t* restrict this, free_func* key_freer, free_func* value_freer); +void fd_table_destroy(fd_table_t *restrict this, free_func *key_freer, free_func *value_freer); /** * Check whether a value is stored in the table @@ -104,7 +104,7 @@ void fd_table_destroy(fd_table_t* restrict this, free_func* key_freer, free_func * @return Whether the value is stored in the table */ __attribute__((pure, nonnull)) -int fd_table_contains_value(const fd_table_t* restrict this, size_t value); +int fd_table_contains_value(const fd_table_t *restrict this, size_t value); /** * Check whether a key is used in the table @@ -114,7 +114,7 @@ int fd_table_contains_value(const fd_table_t* restrict this, size_t value); * @return Whether the key is used */ __attribute__((pure, nonnull)) -int fd_table_contains_key(const fd_table_t* restrict this, int key); +int fd_table_contains_key(const fd_table_t *restrict this, int key); /** * Look up a value in the table @@ -124,7 +124,7 @@ int fd_table_contains_key(const fd_table_t* restrict this, int key); * @return The value associated with the key, 0 if the key was not used */ __attribute__((pure, nonnull)) -size_t fd_table_get(const fd_table_t* restrict this, int key); +size_t fd_table_get(const fd_table_t *restrict this, int key); /** * Add an entry to the table @@ -136,7 +136,7 @@ size_t fd_table_get(const fd_table_t* restrict this, int key); * 0 will also be returned on error, check the `errno` variable. */ __attribute__((nonnull)) -size_t fd_table_put(fd_table_t* restrict this, int key, size_t value); +size_t fd_table_put(fd_table_t *restrict this, int key, size_t value); /** * Remove an entry in the table @@ -146,7 +146,7 @@ size_t fd_table_put(fd_table_t* restrict this, int key, size_t value); * @return The previous value associated with the key, 0 if the key was not used */ __attribute__((nonnull)) -size_t fd_table_remove(fd_table_t* restrict this, int key); +size_t fd_table_remove(fd_table_t *restrict this, int key); /** * Remove all entries in the table @@ -154,7 +154,7 @@ size_t fd_table_remove(fd_table_t* restrict this, int key); * @param this The fd table */ __attribute__((nonnull)) -void fd_table_clear(fd_table_t* restrict this); +void fd_table_clear(fd_table_t *restrict this); /** * Calculate the buffer size need to marshal a fd table @@ -163,7 +163,7 @@ void fd_table_clear(fd_table_t* restrict this); * @return The number of bytes to allocate to the output buffer */ __attribute__((pure, nonnull)) -size_t fd_table_marshal_size(const fd_table_t* restrict this); +size_t fd_table_marshal_size(const fd_table_t *restrict this); /** * Marshals a fd table @@ -172,7 +172,7 @@ size_t fd_table_marshal_size(const fd_table_t* restrict this); * @param data Output buffer for the marshalled data */ __attribute__((nonnull)) -void fd_table_marshal(const fd_table_t* restrict this, char* restrict data); +void fd_table_marshal(const fd_table_t *restrict this, char *restrict data); /** * Unmarshals a fd table @@ -184,8 +184,7 @@ void fd_table_marshal(const fd_table_t* restrict this, char* restrict data); * Destroy the table on error. */ __attribute__((nonnull(1, 2))) -int fd_table_unmarshal(fd_table_t* restrict this, char* restrict data, remap_func* remapper); +int fd_table_unmarshal(fd_table_t *restrict this, char *restrict data, remap_func *remapper); #endif - diff --git a/src/libmdsserver/hash-help.h b/src/libmdsserver/hash-help.h index 21676f3..0b51bb8 100644 --- a/src/libmdsserver/hash-help.h +++ b/src/libmdsserver/hash-help.h @@ -29,16 +29,16 @@ * @param str The string * @return The hash of the string */ -__attribute__((pure)) -static inline size_t string_hash(const char* str) +static inline size_t __attribute__((pure)) +string_hash(const char *str) { - size_t hash = 0; - - if (str != NULL) - while (*str != '\0') - hash = hash * 31 + (size_t)(unsigned char)*str++; - - return hash; + size_t hash = 0; + + if (str) + while (*str != '\0') + hash = hash * 31 + (size_t)(unsigned char)*str++; + + return hash; } @@ -49,15 +49,14 @@ static inline size_t string_hash(const char* str) * @param str_b The second string * @return Whether the strings are equals */ -__attribute__((pure)) -static inline int string_comparator(char* str_a, char* str_b) +static inline int __attribute__((pure)) +string_comparator(char *str_a, char *str_b) { - if ((str_a != NULL) && (str_b != NULL) && (str_a != str_b)) - return !strcmp((char*)str_a, (char*)str_b); - else - return str_a == str_b; + if (str_a && str_b && str_a != str_b) + return !strcmp(str_a, str_b); + else + return str_a == str_b; } #endif - diff --git a/src/libmdsserver/hash-list.h b/src/libmdsserver/hash-list.h index 1381e4e..a376209 100644 --- a/src/libmdsserver/hash-list.h +++ b/src/libmdsserver/hash-list.h @@ -592,4 +592,3 @@ T##_unmarshal(T##_t* restrict this, char* restrict data)\ #endif - diff --git a/src/libmdsserver/hash-table.h b/src/libmdsserver/hash-table.h index 1a3a26c..5ccdefe 100644 --- a/src/libmdsserver/hash-table.h +++ b/src/libmdsserver/hash-table.h @@ -23,33 +23,33 @@ -#define HASH_TABLE_T_VERSION 0 +#define HASH_TABLE_T_VERSION 0 /** * Hash table entry */ typedef struct hash_entry { - /** - * A key - */ - size_t key; - - /** - * The value associated with the key - */ - size_t value; - - /** - * The truncated hash value of the key - */ - size_t hash; - - /** - * The next entry in the bucket - */ - struct hash_entry* next; - + /** + * A key + */ + size_t key; + + /** + * The value associated with the key + */ + size_t value; + + /** + * The truncated hash value of the key + */ + size_t hash; + + /** + * The next entry in the bucket + */ + struct hash_entry *next; + } hash_entry_t; @@ -58,61 +58,61 @@ typedef struct hash_entry */ typedef struct hash_table { - /** - * The table's capacity, i.e. the number of buckets - */ - size_t capacity; - - /** - * Entry buckets - */ - hash_entry_t** buckets; - - /** - * When, in the ratio of entries comparied to the capacity, to grow the table - */ - float load_factor; - - /** - * When, in the number of entries, to grow the table - */ - size_t threshold; - - /** - * The number of entries stored in the table - */ - size_t size; - - /** - * Check whether two values are equal - * - * If this function pointer is `NULL`, the identity is used - * - * Be aware, this variable cannot be marshalled - */ - compare_func* value_comparator; - - /** - * Check whether two keys are equal - * - * If this function pointer is `NULL`, the identity is used - * - * Be aware, this variable cannot be marshalled - */ - compare_func* key_comparator; - - /** - * Calculate the hash of a key - * - * If this function pointer is `NULL`, the identity hash is used - * - * Be aware, this variable cannot be marshalled - * - * @param key The key - * @return The hash of the key - */ - hash_func* hasher; - + /** + * The table's capacity, i.e. the number of buckets + */ + size_t capacity; + + /** + * Entry buckets + */ + hash_entry_t **buckets; + + /** + * When, in the ratio of entries comparied to the capacity, to grow the table + */ + float load_factor; + + /** + * When, in the number of entries, to grow the table + */ + size_t threshold; + + /** + * The number of entries stored in the table + */ + size_t size; + + /** + * Check whether two values are equal + * + * If this function pointer is `NULL`, the identity is used + * + * Be aware, this variable cannot be marshalled + */ + compare_func *value_comparator; + + /** + * Check whether two keys are equal + * + * If this function pointer is `NULL`, the identity is used + * + * Be aware, this variable cannot be marshalled + */ + compare_func *key_comparator; + + /** + * Calculate the hash of a key + * + * If this function pointer is `NULL`, the identity hash is used + * + * Be aware, this variable cannot be marshalled + * + * @param key The key + * @return The hash of the key + */ + hash_func *hasher; + } hash_table_t; @@ -126,7 +126,7 @@ typedef struct hash_table * @return Non-zero on error, `errno` will have been set accordingly */ __attribute__((nonnull)) -int hash_table_create_fine_tuned(hash_table_t* restrict this, size_t initial_capacity, float load_factor); +int hash_table_create_fine_tuned(hash_table_t *restrict this, size_t initial_capacity, float load_factor); /** * Create a hash table @@ -135,8 +135,8 @@ int hash_table_create_fine_tuned(hash_table_t* restrict this, size_t initial_cap * @param initial_capacity:size_t The initial capacity of the table * @return :int Non-zero on error, `errno` will have been set accordingly */ -#define hash_table_create_tuned(this, initial_capacity) \ - hash_table_create_fine_tuned(this, initial_capacity, 0.75f) +#define hash_table_create_tuned(this, initial_capacity)\ + hash_table_create_fine_tuned(this, initial_capacity, 0.75f) /** * Create a hash table @@ -144,8 +144,8 @@ int hash_table_create_fine_tuned(hash_table_t* restrict this, size_t initial_cap * @param this:hash_table_t* Memory slot in which to store the new hash table * @return :int Non-zero on error, `errno` will have been set accordingly */ -#define hash_table_create(this) \ - hash_table_create_tuned(this, 16) +#define hash_table_create(this)\ + hash_table_create_tuned(this, 16) /** * Release all resources in a hash table, should @@ -156,7 +156,7 @@ int hash_table_create_fine_tuned(hash_table_t* restrict this, size_t initial_cap * @param values_freer Function that frees a value, `NULL` if value should not be freed */ __attribute__((nonnull(1))) -void hash_table_destroy(hash_table_t* restrict this, free_func* key_freer, free_func* value_freer); +void hash_table_destroy(hash_table_t *restrict this, free_func *key_freer, free_func *value_freer); /** * Check whether a value is stored in the table @@ -166,7 +166,7 @@ void hash_table_destroy(hash_table_t* restrict this, free_func* key_freer, free_ * @return Whether the value is stored in the table */ __attribute__((pure, nonnull)) -int hash_table_contains_value(const hash_table_t* restrict this, size_t value); +int hash_table_contains_value(const hash_table_t *restrict this, size_t value); /** * Check whether a key is used in the table @@ -176,7 +176,7 @@ int hash_table_contains_value(const hash_table_t* restrict this, size_t value); * @return Whether the key is used */ __attribute__((pure, nonnull)) -int hash_table_contains_key(const hash_table_t* restrict this, size_t key); +int hash_table_contains_key(const hash_table_t *restrict this, size_t key); /** * Look up a value in the table @@ -186,7 +186,7 @@ int hash_table_contains_key(const hash_table_t* restrict this, size_t key); * @return The value associated with the key, 0 if the key was not used */ __attribute__((pure, nonnull)) -size_t hash_table_get(const hash_table_t* restrict this, size_t key); +size_t hash_table_get(const hash_table_t *restrict this, size_t key); /** * Look up an entry in the table @@ -196,7 +196,7 @@ size_t hash_table_get(const hash_table_t* restrict this, size_t key); * @return The entry associated with the key, `NULL` if the key was not used */ __attribute__((pure, nonnull)) -hash_entry_t* hash_table_get_entry(const hash_table_t* restrict this, size_t key); +hash_entry_t *hash_table_get_entry(const hash_table_t *restrict this, size_t key); /** * Add an entry to the table @@ -208,7 +208,7 @@ hash_entry_t* hash_table_get_entry(const hash_table_t* restrict this, size_t key * 0 will also be returned on error, check the `errno` variable. */ __attribute__((nonnull)) -size_t hash_table_put(hash_table_t* restrict this, size_t key, size_t value); +size_t hash_table_put(hash_table_t *restrict this, size_t key, size_t value); /** * Remove an entry in the table @@ -218,7 +218,7 @@ size_t hash_table_put(hash_table_t* restrict this, size_t key, size_t value); * @return The previous value associated with the key, 0 if the key was not used */ __attribute__((nonnull)) -size_t hash_table_remove(hash_table_t* restrict this, size_t key); +size_t hash_table_remove(hash_table_t *restrict this, size_t key); /** * Remove all entries in the table @@ -226,7 +226,7 @@ size_t hash_table_remove(hash_table_t* restrict this, size_t key); * @param this The hash table */ __attribute__((nonnull)) -void hash_table_clear(hash_table_t* restrict this); +void hash_table_clear(hash_table_t *restrict this); /** * Wrapper for `for` keyword that iterates over entry element in a hash table @@ -235,9 +235,9 @@ void hash_table_clear(hash_table_t* restrict this); * @param i:size_t The variable to store the buckey index in at each iteration * @param entry:hash_entry_t* The variable to store the entry in at each iteration */ -#define foreach_hash_table_entry(this, i, entry) \ - for (i = 0; i < (this).capacity; i++) \ - for (entry = (this).buckets[i]; entry != NULL; entry = entry->next) +#define foreach_hash_table_entry(this, i, entry)\ + for (i = 0; i < (this).capacity; i++)\ + for (entry = (this).buckets[i]; entry; entry = entry->next) /** * Calculate the buffer size need to marshal a hash table @@ -246,7 +246,7 @@ void hash_table_clear(hash_table_t* restrict this); * @return The number of bytes to allocate to the output buffer */ __attribute__((pure, nonnull)) -size_t hash_table_marshal_size(const hash_table_t* restrict this); +size_t hash_table_marshal_size(const hash_table_t *restrict this); /** * Marshals a hash table @@ -255,7 +255,7 @@ size_t hash_table_marshal_size(const hash_table_t* restrict this); * @param data Output buffer for the marshalled data */ __attribute__((nonnull)) -void hash_table_marshal(const hash_table_t* restrict this, char* restrict data); +void hash_table_marshal(const hash_table_t *restrict this, char *restrict data); /** * Unmarshals a hash table @@ -267,8 +267,7 @@ void hash_table_marshal(const hash_table_t* restrict this, char* restrict data); * Destroy the table on error. */ __attribute__((nonnull(1, 2))) -int hash_table_unmarshal(hash_table_t* restrict this, char* restrict data, remap_func* remapper); +int hash_table_unmarshal(hash_table_t *restrict this, char *restrict data, remap_func *remapper); #endif - diff --git a/src/libmdsserver/libmdsserver.pc.in b/src/libmdsserver/libmdsserver.pc.in index 4b463af..ddaa591 100644 --- a/src/libmdsserver/libmdsserver.pc.in +++ b/src/libmdsserver/libmdsserver.pc.in @@ -6,4 +6,3 @@ Description: Library for mds-servers Version: @VERSION@ Libs: -L${libdir} -lmdsserver @LIBS@ Cflags: -I${includedir} @CFLAGS@ - diff --git a/src/libmdsserver/linked-list.h b/src/libmdsserver/linked-list.h index 6a8ff2d..1d0cabb 100644 --- a/src/libmdsserver/linked-list.h +++ b/src/libmdsserver/linked-list.h @@ -46,63 +46,63 @@ /** * Sentinel value indicating that the position is unused */ -#define LINKED_LIST_UNUSED (-((ssize_t)(SIZE_MAX >> 1)) - 1) +#define LINKED_LIST_UNUSED (-((ssize_t)(SIZE_MAX >> 1)) - 1) -#define LINKED_LIST_T_VERSION 0 +#define LINKED_LIST_T_VERSION 0 /** * Linear array sentinel doubly linked list class */ typedef struct linked_list { - /** - * The size of the arrays - */ - size_t capacity; - - /** - * The index after the last used index in - * `values` and `next` - */ - size_t end; - - /** - * Head of the stack of reusable positions - */ - size_t reuse_head; - - /** - * Stack of indices than are no longer in use - */ - ssize_t* reusable; - - /** - * The value stored in each node - */ - size_t* values; - - /** - * The next node for each node, `edge` if the current - * node is the last node, and `LINKED_LIST_UNUSED` - * if there is no node on this position - */ - ssize_t* next; - - /** - * The previous node for each node, `edge` if - * the current node is the first node, and - * `LINKED_LIST_UNUSED` if there is no node - * on this position - */ - ssize_t* previous; - - /** - * The sentinel node in the list - */ - ssize_t edge; - + /** + * The size of the arrays + */ + size_t capacity; + + /** + * The index after the last used index in + * `values` and `next` + */ + size_t end; + + /** + * Head of the stack of reusable positions + */ + size_t reuse_head; + + /** + * Stack of indices than are no longer in use + */ + ssize_t *reusable; + + /** + * The value stored in each node + */ + size_t *values; + + /** + * The next node for each node, `edge` if the current + * node is the last node, and `LINKED_LIST_UNUSED` + * if there is no node on this position + */ + ssize_t *next; + + /** + * The previous node for each node, `edge` if + * the current node is the first node, and + * `LINKED_LIST_UNUSED` if there is no node + * on this position + */ + ssize_t *previous; + + /** + * The sentinel node in the list + */ + ssize_t edge; + } linked_list_t; @@ -115,7 +115,7 @@ typedef struct linked_list * @return Non-zero on error, `errno` will have been set accordingly */ __attribute__((nonnull)) -int linked_list_create(linked_list_t* restrict this, size_t capacity); +int linked_list_create(linked_list_t *restrict this, size_t capacity); /** * Release all resources in a linked list, should @@ -124,7 +124,7 @@ int linked_list_create(linked_list_t* restrict this, size_t capacity); * @param this The linked list */ __attribute__((nonnull)) -void linked_list_destroy(linked_list_t* restrict this); +void linked_list_destroy(linked_list_t *restrict this); /** * Clone a linked list @@ -134,7 +134,7 @@ void linked_list_destroy(linked_list_t* restrict this); * @return Non-zero on error, `errno` will have been set accordingly */ __attribute__((nonnull)) -int linked_list_clone(const linked_list_t* restrict this, linked_list_t* restrict out); +int linked_list_clone(const linked_list_t *restrict this, linked_list_t *restrict out); /** * Pack the list so that there are no reusable @@ -151,7 +151,7 @@ int linked_list_clone(const linked_list_t* restrict this, linked_list_t* restric * @return Non-zero on error, `errno` will have been set accordingly */ __attribute__((nonnull)) -int linked_list_pack(linked_list_t* restrict this); +int linked_list_pack(linked_list_t *restrict this); /** * Insert a value in the beginning of the list @@ -161,8 +161,8 @@ int linked_list_pack(linked_list_t* restrict this); * @return :ssize_t The node that has been created and inserted, * `LINKED_LIST_UNUSED` on error, `errno` will be set accordingly */ -#define linked_list_insert_beginning(this, value) \ - (linked_list_insert_after(this, value, this->edge)) +#define linked_list_insert_beginning(this, value)\ + (linked_list_insert_after(this, value, this->edge)) /** * Remove the node at the beginning of the list @@ -170,8 +170,8 @@ int linked_list_pack(linked_list_t* restrict this); * @param this:linked_list_t* The list * @return :ssize_t The node that has been removed */ -#define linked_list_remove_beginning(this) \ - (linked_list_remove_after(this, this->edge)) +#define linked_list_remove_beginning(this)\ + (linked_list_remove_after(this, this->edge)) /** * Insert a value after a specified, reference, node @@ -183,7 +183,7 @@ int linked_list_pack(linked_list_t* restrict this); * `LINKED_LIST_UNUSED` on error, `errno` will be set accordingly */ __attribute__((nonnull)) -ssize_t linked_list_insert_after(linked_list_t* restrict this, size_t value, ssize_t predecessor); +ssize_t linked_list_insert_after(linked_list_t *restrict this, size_t value, ssize_t predecessor); /** * Remove the node after a specified, reference, node @@ -193,7 +193,7 @@ ssize_t linked_list_insert_after(linked_list_t* restrict this, size_t value, ssi * @return The node that has been removed */ __attribute__((nonnull)) -ssize_t linked_list_remove_after(linked_list_t* restrict this, ssize_t predecessor); +ssize_t linked_list_remove_after(linked_list_t *restrict this, ssize_t predecessor); /** * Insert a value before a specified, reference, node @@ -205,7 +205,7 @@ ssize_t linked_list_remove_after(linked_list_t* restrict this, ssize_t predecess * `LINKED_LIST_UNUSED` on error, `errno` will be set accordingly */ __attribute__((nonnull)) -ssize_t linked_list_insert_before(linked_list_t* restrict this, size_t value, ssize_t successor); +ssize_t linked_list_insert_before(linked_list_t *restrict this, size_t value, ssize_t successor); /** * Remove the node before a specified, reference, node @@ -215,7 +215,7 @@ ssize_t linked_list_insert_before(linked_list_t* restrict this, size_t value, ss * @return The node that has been removed */ __attribute__((nonnull)) -ssize_t linked_list_remove_before(linked_list_t* restrict this, ssize_t successor); +ssize_t linked_list_remove_before(linked_list_t *restrict this, ssize_t successor); /** * Remove the node from the list @@ -224,7 +224,7 @@ ssize_t linked_list_remove_before(linked_list_t* restrict this, ssize_t successo * @param node The node to remove */ __attribute__((nonnull)) -void linked_list_remove(linked_list_t* restrict this, ssize_t node); +void linked_list_remove(linked_list_t *restrict this, ssize_t node); /** * Insert a value in the end of the list @@ -234,8 +234,8 @@ void linked_list_remove(linked_list_t* restrict this, ssize_t node); * @return :ssize_t The node that has been created and inserted, * `LINKED_LIST_UNUSED` on error, `errno` will be set accordingly */ -#define linked_list_insert_end(this, value) \ - (linked_list_insert_before((this), (value), (this)->edge)) +#define linked_list_insert_end(this, value)\ + (linked_list_insert_before((this), (value), (this)->edge)) /** * Remove the node at the end of the list @@ -243,8 +243,8 @@ void linked_list_remove(linked_list_t* restrict this, ssize_t node); * @param this:linked_list_t* The list * @return :ssize_t The node that has been removed */ -#define linked_list_remove_end(this) \ - (linked_list_remove_before((this), (this)->edge)) +#define linked_list_remove_end(this)\ + (linked_list_remove_before((this), (this)->edge)) /** * Calculate the buffer size need to marshal a linked list @@ -253,7 +253,7 @@ void linked_list_remove(linked_list_t* restrict this, ssize_t node); * @return The number of bytes to allocate to the output buffer */ __attribute__((pure, nonnull)) -size_t linked_list_marshal_size(const linked_list_t* restrict this); +size_t linked_list_marshal_size(const linked_list_t *restrict this); /** * Marshals a linked list @@ -262,7 +262,7 @@ size_t linked_list_marshal_size(const linked_list_t* restrict this); * @param data Output buffer for the marshalled data */ __attribute__((nonnull)) -void linked_list_marshal(const linked_list_t* restrict this, char* restrict data); +void linked_list_marshal(const linked_list_t *restrict this, char *restrict data); /** * Unmarshals a linked list @@ -273,7 +273,7 @@ void linked_list_marshal(const linked_list_t* restrict this, char* restrict data * Destroy the list on error. */ __attribute__((nonnull)) -int linked_list_unmarshal(linked_list_t* restrict this, char* restrict data); +int linked_list_unmarshal(linked_list_t *restrict this, char *restrict data); /** * Wrapper for `for` keyword that iterates over each element in a linked list @@ -281,8 +281,8 @@ int linked_list_unmarshal(linked_list_t* restrict this, char* restrict data); * @param list:linked_list_t The linked list * @param node:ssize_t The variable to store the node in at each iteration */ -#define foreach_linked_list_node(list, node) \ - for (node = (list).edge; node = (list).next[node], node != (list).edge;) +#define foreach_linked_list_node(list, node)\ + for (node = (list).edge; node = (list).next[node], node != (list).edge;) /** * Print the content of the list @@ -291,8 +291,7 @@ int linked_list_unmarshal(linked_list_t* restrict this, char* restrict data); * @param output Output file */ __attribute__((nonnull)) -void linked_list_dump(linked_list_t* restrict this, FILE* restrict output); +void linked_list_dump(linked_list_t *restrict this, FILE *restrict output); #endif - diff --git a/src/libmdsserver/macro-bits.h b/src/libmdsserver/macro-bits.h index abfb34a..2d1dbf5 100644 --- a/src/libmdsserver/macro-bits.h +++ b/src/libmdsserver/macro-bits.h @@ -31,7 +31,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -#define atoz(str) ((size_t)atol(str)) +#define atoz(str) ((size_t)atol(str)) /** * Convert the beginning of a `const char*` to an `ssize_t` @@ -39,7 +39,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -#define atosz(str) ((ssize_t)atol(str)) +#define atosz(str) ((ssize_t)atol(str)) /** * Convert the beginning of a `const char*` to a `short int` @@ -47,7 +47,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -#define atoh(str) ((short)atol(str)) +#define atoh(str) ((short)atol(str)) /** * Convert the beginning of a `const char*` to an `unsigned short int` @@ -55,7 +55,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -#define atouh(str) ((unsigned short)atol(str)) +#define atouh(str) ((unsigned short)atol(str)) /** * Convert the beginning of a `const char*` to an `unsigned int` @@ -63,7 +63,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -#define atou(str) ((unsigned int)atoi(str)) +#define atou(str) ((unsigned int)atoi(str)) /** * Convert the beginning of a `const char*` to an `unsigned long int` @@ -71,7 +71,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -#define atoul(str) ((unsigned long)atol(str)) +#define atoul(str) ((unsigned long)atol(str)) /** * Convert the beginning of a `const char*` to an `unsigned long long int` @@ -79,7 +79,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -#define atoull(str) ((unsigned long long)atoll(str)) +#define atoull(str) ((unsigned long long)atoll(str)) /** * Convert the beginning of a `const char*` to an `int8_t` @@ -87,7 +87,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define ato8(str) ((int8_t)atoi(str)) +#define ato8(str) ((int8_t)atoi(str)) /** * Convert the beginning of a `const char*` to an `uint8_t` @@ -95,7 +95,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define atou8(str) ((uint8_t)atou(str)) +#define atou8(str) ((uint8_t)atou(str)) /** * Convert the beginning of a `const char*` to an `int16_t` @@ -103,7 +103,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define ato16(str) ((int16_t)atoi(str)) +#define ato16(str) ((int16_t)atoi(str)) /** * Convert the beginning of a `const char*` to an `uint16_t` @@ -111,7 +111,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define atou16(str) ((uint16_t)atou(str)) +#define atou16(str) ((uint16_t)atou(str)) #if UINT_MAX == UINT32_MAX /** @@ -120,7 +120,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define ato32(str) ((int32_t)atoi(str)) +# define ato32(str) ((int32_t)atoi(str)) /** * Convert the beginning of a `const char*` to an `uint32_t` @@ -128,7 +128,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define atou32(str) ((uint32_t)atou(str)) +# define atou32(str) ((uint32_t)atou(str)) #else /** * Convert the beginning of a `const char*` to an `int32_t` @@ -136,7 +136,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define ato32(str) ((int32_t)atol(str)) +# define ato32(str) ((int32_t)atol(str)) /** * Convert the beginning of a `const char*` to an `uint32_t` @@ -144,7 +144,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define atou32(str) ((uint32_t)atoul(str)) +# define atou32(str) ((uint32_t)atoul(str)) #endif #if ULONG_MAX == UINT64_MAX @@ -154,7 +154,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define ato64(str) ((int64_t)atol(str)) +# define ato64(str) ((int64_t)atol(str)) /** * Convert the beginning of a `const char*` to an `uint64_t` @@ -162,7 +162,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define atou64(str) ((uint64_t)atoul(str)) +# define atou64(str) ((uint64_t)atoul(str)) #else /** * Convert the beginning of a `const char*` to an `int64_t` @@ -170,7 +170,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define ato64(str) ((int64_t)atoll(str)) +# define ato64(str) ((int64_t)atoll(str)) /** * Convert the beginning of a `const char*` to an `uint64_t` @@ -178,7 +178,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define atou64(str) ((uint64_t)atoull(str)) +# define atou64(str) ((uint64_t)atoull(str)) #endif /** @@ -187,7 +187,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define atoj(str) ((intmax_t)atou64(str)) +#define atoj(str) ((intmax_t)atou64(str)) /** * Convert the beginning of a `const char*` to an `uintmax_t` @@ -195,8 +195,7 @@ * @param str:const char* The string that begins with an integer * @return The integer at the beginning of the string */ -# define atouj(str) ((uintmax_t)atou64(str)) +#define atouj(str) ((uintmax_t)atou64(str)) #endif - diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h index 14ce80b..3621268 100644 --- a/src/libmdsserver/macros.h +++ b/src/libmdsserver/macros.h @@ -729,8 +729,8 @@ * * @param str:const char* The argument passed to `perror` */ -#define xperror(str) \ - (errno ? perror(str), errno = 0 : 0) +#define xperror(str)\ + (errno ? perror(str), errno = 0 : 0) /** @@ -738,17 +738,17 @@ * * @param ... The condition */ -#define fail_if(...) \ - do \ - if (__VA_ARGS__) \ - { \ - int _fail_if_saved_errno = errno; \ - if ((errno != EMSGSIZE) && (errno != ECONNRESET) && (errno != EINTR)) \ - fprintf(stderr, "failure at %s:%i\n", __FILE__, __LINE__); \ - errno = _fail_if_saved_errno; \ - goto fail; \ - } \ - while (0) +#define fail_if(...)\ + do {\ + int _fail_if_saved_errno;\ + if (__VA_ARGS__) {\ + _fail_if_saved_errno = errno;\ + if (errno != EMSGSIZE && errno != ECONNRESET && errno != EINTR)\ + fprintf(stderr, "failure at %s:%i\n", __FILE__, __LINE__);\ + errno = _fail_if_saved_errno;\ + goto fail;\ + }\ + } while (0) /** @@ -757,8 +757,8 @@ * @param condition The condition * @param instructions The instruction (semicolon-terminated) */ -#define exit_if(condition, instructions) \ - do { if (condition) { instructions return 1; } } while (0) +#define exit_if(condition, instructions)\ + do { if (condition) { instructions return 1; } } while (0) /** @@ -769,8 +769,8 @@ * the compiler you are using, you may want to edit this * macro. */ -#define STREND(str) \ - (strchr(str, '\0')) +#define STREND(str)\ + (strchr(str, '\0')) /** @@ -778,7 +778,7 @@ * Quick, free up all your unused memory or kill yourself! */ #ifndef SIGDANGER -# define SIGDANGER (SIGRTMIN + 1) +# define SIGDANGER (SIGRTMIN + 1) #endif @@ -787,7 +787,7 @@ * about the server's state or statistics */ #ifndef SIGINFO -# define SIGINFO (SIGRTMIN + 2) +# define SIGINFO (SIGRTMIN + 2) #endif @@ -796,7 +796,7 @@ * into an updated binary */ #ifndef SIGUPDATE -# define SIGUPDATE SIGUSR1 +# define SIGUPDATE SIGUSR1 #endif @@ -804,8 +804,8 @@ * Normal signal handlers should place this macro * at the top of the function */ -#define SIGHANDLER_START \ - int sighandler_saved_errno = errno +#define SIGHANDLER_START\ + int sighandler_saved_errno = errno /** @@ -813,9 +813,8 @@ * at the bottom of the function, or just before * any `return` */ -#define SIGHANDLER_END \ - (errno = sighandler_saved_errno) +#define SIGHANDLER_END\ + (errno = sighandler_saved_errno) #endif - diff --git a/src/libmdsserver/mds-message.h b/src/libmdsserver/mds-message.h index 68c3c86..a2254e7 100644 --- a/src/libmdsserver/mds-message.h +++ b/src/libmdsserver/mds-message.h @@ -22,63 +22,63 @@ #include <stddef.h> -#define MDS_MESSAGE_T_VERSION 0 +#define MDS_MESSAGE_T_VERSION 0 /** * Message passed between a server and a client or between two of either */ typedef struct mds_message { - /** - * The headers in the message, each element in this list - * as an unparsed header, it consists of both the header - * name and its associated value, joined by ": ". A header - * cannot be `NULL` (unless its memory allocation failed,) - * but `headers` itself is `NULL` if there are no headers. - * The "Length" header should be included in this list. - */ - char** headers; - - /** - * The number of headers in the message - */ - size_t header_count; - - /** - * The payload of the message, `NULL` if none (of zero-length) - */ - char* payload; - - /** - * The size of the payload - */ - size_t payload_size; - - /** - * How much of the payload that has been stored (internal data) - */ - size_t payload_ptr; - - /** - * Internal buffer for the reading function (internal data) - */ - char* buffer; - - /** - * The size allocated to `buffer` (internal data) - */ - size_t buffer_size; - - /** - * The number of bytes used in `buffer` (internal data) - */ - size_t buffer_ptr; - - /** - * 0 while reading headers, 1 while reading payload, and 2 when done (internal data) - */ - int stage; - + /** + * The headers in the message, each element in this list + * as an unparsed header, it consists of both the header + * name and its associated value, joined by ": ". A header + * cannot be `NULL` (unless its memory allocation failed,) + * but `headers` itself is `NULL` if there are no headers. + * The "Length" header should be included in this list. + */ + char **headers; + + /** + * The number of headers in the message + */ + size_t header_count; + + /** + * The payload of the message, `NULL` if none (of zero-length) + */ + char *payload; + + /** + * The size of the payload + */ + size_t payload_size; + + /** + * How much of the payload that has been stored (internal data) + */ + size_t payload_ptr; + + /** + * Internal buffer for the reading function (internal data) + */ + char *buffer; + + /** + * The size allocated to `buffer` (internal data) + */ + size_t buffer_size; + + /** + * The number of bytes used in `buffer` (internal data) + */ + size_t buffer_ptr; + + /** + * 0 while reading headers, 1 while reading payload, and 2 when done (internal data) + */ + int stage; + } mds_message_t; @@ -91,7 +91,7 @@ typedef struct mds_message * Destroy the message on error. */ __attribute__((nonnull)) -int mds_message_initialise(mds_message_t* restrict this); +int mds_message_initialise(mds_message_t *restrict this); /** * Zero initialise a message slot @@ -99,7 +99,7 @@ int mds_message_initialise(mds_message_t* restrict this); * @param this Memory slot in which to store the new message */ __attribute__((nonnull)) -void mds_message_zero_initialise(mds_message_t* restrict this); +void mds_message_zero_initialise(mds_message_t *restrict this); /** * Release all resources in a message, should @@ -108,7 +108,7 @@ void mds_message_zero_initialise(mds_message_t* restrict this); * @param this The message */ __attribute__((nonnull)) -void mds_message_destroy(mds_message_t* restrict this); +void mds_message_destroy(mds_message_t *restrict this); /** * Extend the header list's allocation @@ -118,7 +118,7 @@ void mds_message_destroy(mds_message_t* restrict this); * @return Zero on success, -1 on error */ __attribute__((nonnull)) -int mds_message_extend_headers(mds_message_t* restrict this, size_t extent); +int mds_message_extend_headers(mds_message_t *restrict this, size_t extent); /** * Read the next message from a file descriptor @@ -134,7 +134,7 @@ int mds_message_extend_headers(mds_message_t* restrict this, size_t extent); * which is a state that cannot be recovered from. */ __attribute__((nonnull)) -int mds_message_read(mds_message_t* restrict this, int fd); +int mds_message_read(mds_message_t *restrict this, int fd); /** * Get the required allocation size for `data` of the @@ -144,7 +144,7 @@ int mds_message_read(mds_message_t* restrict this, int fd); * @return The size of the message when marshalled */ __attribute__((pure, nonnull)) -size_t mds_message_marshal_size(const mds_message_t* restrict this); +size_t mds_message_marshal_size(const mds_message_t *restrict this); /** * Marshal a message for state serialisation @@ -153,7 +153,7 @@ size_t mds_message_marshal_size(const mds_message_t* restrict this); * @param data Output buffer for the marshalled data */ __attribute__((nonnull)) -void mds_message_marshal(const mds_message_t* restrict this, char* restrict data); +void mds_message_marshal(const mds_message_t *restrict this, char *restrict data); /** * Unmarshal a message for state deserialisation @@ -164,7 +164,7 @@ void mds_message_marshal(const mds_message_t* restrict this, char* restrict data * Destroy the message on error. */ __attribute__((nonnull)) -int mds_message_unmarshal(mds_message_t* restrict this, char* restrict data); +int mds_message_unmarshal(mds_message_t *restrict this, char *restrict data); /** * Get the required allocation size for `data` of the @@ -174,7 +174,7 @@ int mds_message_unmarshal(mds_message_t* restrict this, char* restrict data); * @return The size of the message when marshalled */ __attribute__((pure, nonnull)) -size_t mds_message_compose_size(const mds_message_t* restrict this); +size_t mds_message_compose_size(const mds_message_t *restrict this); /** * Marshal a message for communication @@ -183,8 +183,7 @@ size_t mds_message_compose_size(const mds_message_t* restrict this); * @param data Output buffer for the marshalled data */ __attribute__((nonnull)) -void mds_message_compose(const mds_message_t* restrict this, char* restrict data); +void mds_message_compose(const mds_message_t *restrict this, char *restrict data); #endif - diff --git a/src/libmdsserver/table-common.h b/src/libmdsserver/table-common.h index 850358a..1fb95d9 100644 --- a/src/libmdsserver/table-common.h +++ b/src/libmdsserver/table-common.h @@ -56,4 +56,3 @@ typedef size_t remap_func(size_t obj); #endif - diff --git a/src/libmdsserver/util.h b/src/libmdsserver/util.h index acb8d5e..2bcad50 100644 --- a/src/libmdsserver/util.h +++ b/src/libmdsserver/util.h @@ -26,14 +26,14 @@ #ifndef __USE_GNU -__attribute__((pure, nonnull)) -static inline void* rawmemchr(const void* str, int chr) +static inline void *__attribute__((pure, nonnull)) +rawmemchr(const void *str, int chr) { - intptr_t str_address = (intptr_t)str; - void* str_nonconst = (void*)str_address; - char* s = str_nonconst; - while ((int)*s++ != chr); - return s - 1; + intptr_t str_address = (intptr_t)str; + void *str_nonconst = (void*)str_address; + char *s = str_nonconst; + while ((int)*s++ != chr); + return s - 1; } #endif @@ -45,7 +45,7 @@ static inline void* rawmemchr(const void* str, int chr) * @return The client ID integer */ __attribute__((pure, nonnull)) -uint64_t parse_client_id(const char* str); +uint64_t parse_client_id(const char *str); /** * Read an environment variable, but handle it as undefined if empty @@ -54,7 +54,7 @@ uint64_t parse_client_id(const char* str); * @return The environment variable's value, `NULL` if empty or not defined */ __attribute__((nonnull)) -char* getenv_nonempty(const char* var); +char *getenv_nonempty(const char *var); /** * Prepare the server so that it can reexec into @@ -88,7 +88,7 @@ int prepare_reexec(void); * @param argv The command line arguments * @param reexeced Whether the server has previously been re-exec:ed */ -void reexec_server(int argc, char** argv, int reexeced); +void reexec_server(int argc, char **argv, int reexeced); /** * Set up a signal trap. @@ -112,7 +112,7 @@ int xsigaction(int signo, void (*function)(int signo)); * @param length The length of the message * @return The number of bytes that have been sent (even on error) */ -size_t send_message(int socket, const char* message, size_t length); +size_t send_message(int socket, const char *message, size_t length); /** * A version of `atoi` that is strict about the syntax and bounds @@ -124,7 +124,7 @@ size_t send_message(int socket, const char* message, size_t length); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atoi(const char* str, int* value, int min, int max); +int strict_atoi(const char *str, int *value, int min, int max); /** * A version of `atoj` that is strict about the syntax and bounds @@ -136,7 +136,7 @@ int strict_atoi(const char* str, int* value, int min, int max); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atoj(const char* str, intmax_t* value, intmax_t min, intmax_t max); +int strict_atoj(const char *str, intmax_t *value, intmax_t min, intmax_t max); /** * A version of `atouj` that is strict about the syntax and bounds @@ -148,7 +148,7 @@ int strict_atoj(const char* str, intmax_t* value, intmax_t min, intmax_t max); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atouj(const char* str, uintmax_t* value, uintmax_t min, uintmax_t max); +int strict_atouj(const char *str, uintmax_t *value, uintmax_t min, uintmax_t max); /** * A version of `atoh` that is strict about the syntax and bounds @@ -160,7 +160,7 @@ int strict_atouj(const char* str, uintmax_t* value, uintmax_t min, uintmax_t max * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atoh(const char* str, short int* value, int min, int max); +int strict_atoh(const char *str, short int *value, int min, int max); /** * A version of `atouh` that is strict about the syntax and bounds @@ -172,7 +172,7 @@ int strict_atoh(const char* str, short int* value, int min, int max); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atouh(const char* str, unsigned short int* value, unsigned int min, unsigned int max); +int strict_atouh(const char *str, unsigned short int *value, unsigned int min, unsigned int max); /** * A version of `atou` that is strict about the syntax and bounds @@ -184,7 +184,7 @@ int strict_atouh(const char* str, unsigned short int* value, unsigned int min, u * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atou(const char* str, unsigned int* value, unsigned int min, unsigned int max); +int strict_atou(const char *str, unsigned int *value, unsigned int min, unsigned int max); /** * A version of `atol` that is strict about the syntax and bounds @@ -196,7 +196,7 @@ int strict_atou(const char* str, unsigned int* value, unsigned int min, unsigned * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atol(const char* str, long int* value, long int min, long int max); +int strict_atol(const char *str, long int *value, long int min, long int max); /** * A version of `atoul` that is strict about the syntax and bounds @@ -208,7 +208,7 @@ int strict_atol(const char* str, long int* value, long int min, long int max); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atoul(const char* str, unsigned long int* value, unsigned long int min, unsigned long int max); +int strict_atoul(const char *str, unsigned long int *value, unsigned long int min, unsigned long int max); /** * A version of `atoll` that is strict about the syntax and bounds @@ -220,7 +220,7 @@ int strict_atoul(const char* str, unsigned long int* value, unsigned long int mi * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atoll(const char* str, long long int* value, long long int min, long long int max); +int strict_atoll(const char *str, long long int *value, long long int min, long long int max); /** * A version of `atoull` that is strict about the syntax and bounds @@ -232,8 +232,8 @@ int strict_atoll(const char* str, long long int* value, long long int min, long * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atoull(const char* str, unsigned long long int* value, - unsigned long long int min, unsigned long long int max); +int strict_atoull(const char *str, unsigned long long int *value, + unsigned long long int min, unsigned long long int max); /** * A version of `atoz` that is strict about the syntax and bounds @@ -245,7 +245,7 @@ int strict_atoull(const char* str, unsigned long long int* value, * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atoz(const char* str, size_t* value, size_t min, size_t max); +int strict_atoz(const char *str, size_t *value, size_t min, size_t max); /** * A version of `atosz` that is strict about the syntax and bounds @@ -257,7 +257,7 @@ int strict_atoz(const char* str, size_t* value, size_t min, size_t max); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atosz(const char* str, ssize_t* value, ssize_t min, ssize_t max); +int strict_atosz(const char *str, ssize_t *value, ssize_t min, ssize_t max); /** * A version of `ato8` that is strict about the syntax and bounds @@ -269,7 +269,7 @@ int strict_atosz(const char* str, ssize_t* value, ssize_t min, ssize_t max); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_ato8(const char* str, int8_t* value, int min, int max); +int strict_ato8(const char *str, int8_t *value, int min, int max); /** * A version of `atou8` that is strict about the syntax and bounds @@ -281,7 +281,7 @@ int strict_ato8(const char* str, int8_t* value, int min, int max); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atou8(const char* str, uint8_t* value, int min, int max); +int strict_atou8(const char *str, uint8_t *value, int min, int max); /** * A version of `ato16` that is strict about the syntax and bounds @@ -293,7 +293,7 @@ int strict_atou8(const char* str, uint8_t* value, int min, int max); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_ato16(const char* str, int16_t* value, int min, int max); +int strict_ato16(const char *str, int16_t *value, int min, int max); /** * A version of `atou16` that is strict about the syntax and bounds @@ -305,7 +305,7 @@ int strict_ato16(const char* str, int16_t* value, int min, int max); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atou16(const char* str, uint16_t* value, unsigned int min, unsigned int max); +int strict_atou16(const char *str, uint16_t *value, unsigned int min, unsigned int max); /** * A version of `ato32` that is strict about the syntax and bounds @@ -317,7 +317,7 @@ int strict_atou16(const char* str, uint16_t* value, unsigned int min, unsigned i * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_ato32(const char* str, int32_t* value, int32_t min, int32_t max); +int strict_ato32(const char *str, int32_t *value, int32_t min, int32_t max); /** * A version of `atou32` that is strict about the syntax and bounds @@ -329,7 +329,7 @@ int strict_ato32(const char* str, int32_t* value, int32_t min, int32_t max); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atou32(const char* str, uint32_t* value, uint32_t min, uint32_t max); +int strict_atou32(const char *str, uint32_t *value, uint32_t min, uint32_t max); /** * A version of `ato64` that is strict about the syntax and bounds @@ -341,7 +341,7 @@ int strict_atou32(const char* str, uint32_t* value, uint32_t min, uint32_t max); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_ato64(const char* str, int64_t* value, int64_t min, int64_t max); +int strict_ato64(const char *str, int64_t *value, int64_t min, int64_t max); /** * A version of `atou64` that is strict about the syntax and bounds @@ -353,7 +353,7 @@ int strict_ato64(const char* str, int64_t* value, int64_t min, int64_t max); * @return Zero on success, -1 on syntax error */ __attribute__((nonnull)) -int strict_atou64(const char* str, uint64_t* value, uint64_t min, uint64_t max); +int strict_atou64(const char *str, uint64_t *value, uint64_t min, uint64_t max); /** * Send a buffer into a file and ignore interruptions @@ -363,7 +363,7 @@ int strict_atou64(const char* str, uint64_t* value, uint64_t min, uint64_t max); * @param length The length of the buffer * @return Zero on success, -1 on error */ -int full_write(int fd, const char* buffer, size_t length); +int full_write(int fd, const char *buffer, size_t length); /** * Read a file completely and ignore interruptions @@ -372,7 +372,7 @@ int full_write(int fd, const char* buffer, size_t length); * @param length Output parameter for the length of the file, may be `NULL` * @return The content of the file, you will need to free it. `NULL` on error */ -char* full_read(int fd, size_t* length); +char *full_read(int fd, size_t *length); /** * Send a full message even if interrupted @@ -382,7 +382,7 @@ char* full_read(int fd, size_t* length); * @param length The length of the message * @return Zero on success, -1 on error */ -int full_send(int socket, const char* message, size_t length); +int full_send(int socket, const char *message, size_t length); /** * Check whether a string begins with a specific string, @@ -395,7 +395,7 @@ int full_send(int socket, const char* message, size_t length); * @return Whether the `haystack` begins with `needle` */ __attribute__((pure, nonnull)) -int startswith_n(const char* haystack, const char* needle, size_t haystack_n, size_t needle_n); +int startswith_n(const char *haystack, const char *needle, size_t haystack_n, size_t needle_n); /** * Wrapper around `waitpid` that never returns on an interruption unless @@ -406,7 +406,7 @@ int startswith_n(const char* haystack, const char* needle, size_t haystack_n, si * @param options See description of `options` in the documentation for `waitpid` * @return See the documentation for `waitpid` */ -pid_t uninterruptable_waitpid(pid_t pid, int* restrict status, int options); +pid_t uninterruptable_waitpid(pid_t pid, int *restrict status, int options); /** * Check whether a NUL-terminated string is encoded in UTF-8 @@ -416,7 +416,7 @@ pid_t uninterruptable_waitpid(pid_t pid, int* restrict status, int options); * @return Zero if good, -1 on encoding error */ __attribute__((pure, nonnull)) -int verify_utf8(const char* string, int allow_modified_nul); +int verify_utf8(const char *string, int allow_modified_nul); /** * Construct an error message to be sent to a client @@ -444,10 +444,10 @@ int verify_utf8(const char* string, int allow_modified_nul); * @return The length of the message, zero on error */ __attribute__((nonnull(1, 2, 3, 7, 8))) -size_t construct_error_message(const char* restrict recv_client_id, const char* restrict recv_message_id, - const char* restrict recv_command, int custom, int errnum, - const char* restrict message, char** restrict send_buffer, - size_t* restrict send_buffer_size, uint32_t message_id); +size_t construct_error_message(const char *restrict recv_client_id, const char *restrict recv_message_id, + const char *restrict recv_command, int custom, int errnum, + const char *restrict message, char **restrict send_buffer, + size_t *restrict send_buffer_size, uint32_t message_id); /** * Send an error message @@ -476,11 +476,10 @@ size_t construct_error_message(const char* restrict recv_client_id, const char* * @return Zero on success, -1 on error */ __attribute__((nonnull(1, 2, 3, 7, 8))) -int send_error(const char* restrict recv_client_id, const char* restrict recv_message_id, - const char* restrict recv_command, int custom, int errnum, const char* restrict message, - char** restrict send_buffer, size_t* restrict send_buffer_size, uint32_t message_id, - int socket_fd); +int send_error(const char *restrict recv_client_id, const char *restrict recv_message_id, + const char *restrict recv_command, int custom, int errnum, const char *restrict message, + char **restrict send_buffer, size_t *restrict send_buffer_size, uint32_t message_id, + int socket_fd); #endif - |