diff options
author | pommicket <pommicket@gmail.com> | 2025-09-14 11:49:47 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-09-14 11:49:47 -0400 |
commit | c8ef3a67210c980d5d1ff2c1bd7d8fffd39846b5 (patch) | |
tree | 4a89c76e2fc573e8e9a88fc3a602272a049b9d09 | |
parent | 931a11868a81fc877c083b987108f72fc3fd2976 (diff) |
New typed-get API, again
-rw-r--r-- | pom.c | 3 | ||||
-rw-r--r-- | pom.h | 73 |
2 files changed, 42 insertions, 34 deletions
@@ -234,9 +234,10 @@ make_error(const char *file, uint64_t line, const char *fmt, ...) { err->line = line; err->message = message; char *string = strchr(message, '\0') + 1; - // no, clang, string will not overlap with message. + // no, GCC, string will not overlap with message. #if __GNUC__ >= 4 #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wunknown-warning-option" #pragma GCC diagnostic ignored "-Wrestrict" #endif sprintf(string, "Error:\n%s:%" PRIu64 ": %s\n", file, line, message); @@ -239,82 +239,89 @@ pom_conf_get_or_default(const pom_conf *conf, const char *key, const char *dflt) /// Get signed integer value of `key`. /// -/// Returns true on success, putting the integer value in `*value`. +/// Returns `NULL` on success, putting the integer value in `*value`. /// -/// If `key` is not set or `key` is set but not a valid integer, -/// returns false. -/// `*value` is set to 0 in this case. -bool +/// If `key` is not set, returns `""`. +/// If `key` is set but not a valid integer +/// (decimal or `0x`/`0X`-prefixed hexadecimal, absolute value less than 2<sup>53</sup>), +/// returns the value of `key`. +/// `*value` is set to 0 in these cases. +const char * pom_conf_get_int(const pom_conf *conf, const char *key, int64_t *value); /// Get signed integer value of `key`, or `dflt` if not present. /// -/// Returns true on success, putting the integer value in `*value`. +/// Returns `NULL` on success, putting the integer value in `*value`. /// -/// If `key` is set but not a valid integer, -/// returns false. +/// If `key` is set but not a valid integer +/// (decimal or `0x`/`0X`-prefixed hexadecimal, absolute value less than 2<sup>53</sup>), +/// returns the value of `key`. /// `*value` is still set to `dflt` in this case. -bool +const char * pom_conf_get_int_or_default(const pom_conf *conf, const char *key, int64_t *value, int64_t dflt); /// Get unsigned integer value of `key`. /// -/// Returns true on success, putting the unsigned integer value in `*value`. +/// Returns `NULL` on success, putting the unsigned integer value in `*value`. /// -/// If `key` is not set or `key` is set but not a valid unsigned integer, -/// returns false. -/// `*value` is set to 0 in this case. -bool +/// If `key` is not set, returns `""`. If `key` is set but not a valid unsigned integer +/// (decimal or `0x`/`0X`-prefixed hexadecimal, less than 2<sup>53</sup>), +/// returns the value of `key`. +/// `*value` is set to 0 in these case cases. +const char * pom_conf_get_uint(const pom_conf *conf, const char *key, uint64_t *value); /// Get unsigned integer value of `key`, or `dflt` if not present. /// -/// Returns true on success, putting the unsigned integer value in `*value`. +/// Returns `NULL` on success, putting the unsigned integer value in `*value`. /// -/// If `key` is set but not a valid unsigned integer, -/// returns false. +/// If `key` is set but not a valid unsigned integer +/// (decimal or `0x`/`0X`-prefixed hexadecimal, less than 2<sup>53</sup>), +/// returns the value of `key`. /// `*value` is set to 0 in this case. -bool +const char * pom_conf_get_uint_or_default(const pom_conf *conf, const char *key, uint64_t *value, uint64_t dflt); /// Get floating-point value of `key`. /// -/// Returns true on success, putting the floating-point value in `*value`. +/// Returns `NULL` on success, putting the floating-point value in `*value`. /// -/// If `key` is not set or `key` is set but not a valid floating-point number, -/// returns false. +/// If `key` is not set, returns `""`. If `key` is set but not a valid floating-point number, +/// returns the value of `key`. /// `*value` is set to 0.0 in this case. -bool +const char * pom_conf_get_float(const pom_conf *conf, const char *key, double *value); /// Get floating-point value of `key`, or `dflt` if not present. /// -/// Returns true on success, putting the floating-point value in `*value`. +/// Returns `NULL` on success, putting the floating-point value in `*value`. /// /// If `key` is set but not a valid floating-point number, -/// returns false. +/// returns the value of `key`. /// `*value` is still set to `dflt` in this case. -bool +const char * pom_conf_get_float_or_default(const pom_conf *conf, const char *key, double *value, double dflt); /// Get boolean value of `key`. /// -/// Returns true on success], putting the boolean value in `*value`. +/// Returns `NULL` on success, putting the boolean value in `*value`. /// -/// If `key` is not set or `key` is set but not a valid boolean, -/// returns false. +/// If `key` is not set, returns `""`. If `key` is set but not a valid boolean +/// (`off`/`false`/`no`/`on`/`true`/`yes`), +/// returns the value of `key`. /// `*value` is set to `false` in this case. -bool +const char * pom_conf_get_bool(const pom_conf *conf, const char *key, bool *value); /// Get boolean value of `key`, or `dflt` if not present. /// -/// Returns true on success, putting the boolean value in `*value`. +/// Returns `NULL` on success, putting the boolean value in `*value`. /// -/// If `key` is set but not a valid boolean, -/// returns false. +/// If `key` is set but not a valid boolean +/// (`off`/`false`/`no`/`on`/`true`/`yes`), +/// returns the value of `key`. /// `*value` is still set to `dflt` in this case. -bool +const char * pom_conf_get_bool_or_default(const pom_conf *conf, const char *key, bool *value, bool dflt); /// Get comma-separated list value of `key`, or `NULL` if not present. The return value must be freed with `free`. |