diff options
author | pommicket <pommicket@gmail.com> | 2025-09-15 14:30:33 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-09-15 14:30:33 -0400 |
commit | 627278a0cb84bca7751e97f13d9c235abac678f0 (patch) | |
tree | 6d674f6ceb0be295c126ba9fcf08179054411e90 /pom.h | |
parent | 4f2644f354184d5febc1aa8f37e987eca03f7f25 (diff) |
pom_settings
Diffstat (limited to 'pom.h')
-rw-r--r-- | pom.h | 44 |
1 files changed, 26 insertions, 18 deletions
@@ -6,8 +6,6 @@ /// Of course, you should not free or \ref pom_conf_merge into /// a configuration while another thread is using it. /// -/// \ref pom_set_error_language is not thread-safe — see its documentation for more notes. -/// /// Otherwise, libpom is fully thread-safe /// provided that C11 atomics are available /// (`__STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)`). @@ -95,18 +93,26 @@ typedef struct pom_item { uint64_t line; } pom_item; -/// Set language for error messages. -/// -/// This function is **not** thread-safe. Ensure synchronization between calling -/// this and any functions which can return errors. -/// -/// If `lang` is `NULL` or unrecognized, the default of `"en-US"` will be used. -/// -/// Currently supported languages: -/// -/// - `en-US` -void -pom_set_error_language(const char *lang); +/// Settings for libpom. +/// +/// Start by initializing this to zero, +/// then fill out only the fields you need. +typedef struct pom_settings { + /// Data to pass to allocation functions. + void *allocator_udata; + /// calloc function to use for all purposes, or `NULL` to use libc `calloc`. + void *(*calloc)(void *udata, size_t nmemb, size_t sz); + /// realloc function to use for all purposes, or `NULL` to use libc `realloc`. + void *(*realloc)(void *udata, void *ptr, size_t new_sz); + /// free function to use for all purposes, or `NULL` to use libc `free`. + void (*free)(void *udata, void *ptr); + /// Language for error messages. + /// + /// If empty, the default of `"en-US"` will be used. + char error_lang[16]; + /// Reserved for future use. Must be set to 0. + void *reserved[4]; +} pom_settings; /// Load a configuration using a `read`-like function. /// @@ -115,6 +121,8 @@ pom_set_error_language(const char *lang); /// \ref pom_load_path to load from a path, /// and \ref pom_load_string to load from a string. /// +/// `settings` can be `NULL`, in which case the default settings are used. +/// /// On success, a configuration is returned and `*error` is set to `NULL` /// if `error` is not `NULL`. /// @@ -135,7 +143,7 @@ pom_set_error_language(const char *lang); /// `filename` is only used for errors. POM__MUST_USE_L pom_conf * -pom_load(const char *filename, +pom_load(const pom_settings *settings, const char *filename, size_t (*read_func)(void *userdata, char *buf, size_t len), void *userdata, pom_error **error) POM__MUST_USE_R; @@ -153,7 +161,7 @@ POM__MUST_USE_R; /// `filename` is only used for errors. POM__MUST_USE_L pom_conf * -pom_load_file(const char *filename, FILE *file, pom_error **error) +pom_load_file(const pom_settings *settings, const char *filename, FILE *file, pom_error **error) POM__MUST_USE_R; /// Load configuration from a file path. @@ -166,7 +174,7 @@ POM__MUST_USE_R; /// in which case it must be freed with `free`. POM__MUST_USE_L pom_conf * -pom_load_path(const char *path, pom_error **error) +pom_load_path(const pom_settings *settings, const char *path, pom_error **error) POM__MUST_USE_R; #endif @@ -181,7 +189,7 @@ POM__MUST_USE_R; /// `filename` is only used for errors. POM__MUST_USE_L pom_conf * -pom_load_string(const char *filename, const char *string, pom_error **error) +pom_load_string(const pom_settings *settings, const char *filename, const char *string, pom_error **error) POM__MUST_USE_R; /// Get the message of this error. |