aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-08-19 01:42:49 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-08-19 01:42:49 +0300
commit6e20bab8f5fcfbe4fe816425704f9edd8ad88444 (patch)
tree5f11825e1afc4dbc75ed9778afcdd9e12cddcb05 /include
parent5ed7b33fa8ce0c91af1a58bc17636d6bf0406d24 (diff)
downloadparcini-6e20bab8f5fcfbe4fe816425704f9edd8ad88444.tar.gz
parcini-6e20bab8f5fcfbe4fe816425704f9edd8ad88444.zip
Example and new helper funcion
* Added an example program an ini file to example/ * Added a new helper function `parcini_value_handle` to handle and copy parsed values, depending on the expected value type.
Diffstat (limited to 'include')
-rw-r--r--include/parcini.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/include/parcini.h b/include/parcini.h
index 3bcaf59..d485ffd 100644
--- a/include/parcini.h
+++ b/include/parcini.h
@@ -94,6 +94,21 @@ struct parcini_line {
};
/*
+ * Helper function to handle a value that was parsed by parcini. Pass a pointer
+ * of a parcini_value, and the expected type. If the parcini_value typematches
+ * the expected type, then *dst is set to the provided value casting it to the
+ * correct type.
+ *
+ * IMPORTANT: in the case of "string" values, you need to pass a pointer to a
+ * char pointer (i.e. char **), and the memory in the string value is copied
+ * over to the char *. That means, that if some memory was already allocated in
+ * the passed pointer, there could be a memory leak if you don't free that
+ * memory before, unless you have another pointer to that same memory elsewhere.
+ */
+bool parcini_value_handle(const struct parcini_value *,
+ const enum parcini_value_type expected, void *dst);
+
+/*
* Parse the next line in the stream returning the kind of result/error of
* parsing and filling the parcini_line structure with the information that was
* extracted from the line, as well as the current section (including after
@@ -115,7 +130,7 @@ parcini_t *parcini_init(FILE *stream);
/*
* Helper function to open a file and then initialize a parcini_t object with
- * said as the source stream.
+ * said as the source stream. Returns NULL if the file couldn't be opened.
*/
parcini_t *parcini_from_file(const char *fpath);