diff --git a/README.md b/README.md index 959a3c0..8f1dbc9 100644 --- a/README.md +++ b/README.md @@ -55,12 +55,12 @@ Creates a new node holding a string value. Returns a pointer to the newly allocated `pd_node_t` structure or `NULL`. ```C -int pd_read_file(const char *file_name, pd_node_t ***nodes); +int pd_read_file(const char *path, pd_node_t ***nodes); ``` Reads a `.pd` file and creates an array of nodes. - Parameters - - `file_name` - path to the input file. + - `path` - path to the input file. - `nodes` - output parameter. On success, `*nodes` points to a newly allocated NULL‑terminated array of `pd_node_t*` pointers. - Returns - `0` on success (including the case of an empty file, in which case a minimal array containing only a `NULL` pointer is allocated). @@ -69,18 +69,28 @@ Reads a `.pd` file and creates an array of nodes. - Negative values for other I/O or memory errors. ```C -int pd_write_file(const char *file_name, const pd_node_t **nodes); +int pd_read_file_ws(const WSHDR *path, pd_node_t ***nodes); +``` +`WSHDR` version of `pd_read_file`. + +```C +int pd_write_file(const char *path, const pd_node_t **nodes); ``` Writes an array of nodes to a file in the `.pd` format. - Parameters - - `file_name` - path to the output file. + - `path` - path to the output file. - `nodes` - NULL‑terminated array of node pointers. - Returns - `0` on success. - `-1` if the file cannot be created. - `-2` if a write error occurs. +```C +int pd_write_file_ws(const WSHDR *path, const pd_node_t **nodes); +``` +`WSHDR` version of `pd_write_file`. + ```C size_t pd_get_max_group_size(void); ``` diff --git a/src/pd.c b/src/pd.c index fd4b5cc..0521902 100644 --- a/src/pd.c +++ b/src/pd.c @@ -128,8 +128,8 @@ static pd_node_t *pd_parse_line(const char *p) { return node; } -int pd_read_file(const char *file_name, PD_NODE ***nodes) { - FILE *file = fopen(file_name, "r"); +int pd_read_file(const char *path, pd_node_t ***nodes) { + FILE *file = fopen(path, "r"); if (!file) { return -1; } @@ -225,8 +225,14 @@ int pd_read_file(const char *file_name, PD_NODE ***nodes) { return 0; } -int pd_write_file(const char *file_name, const pd_node_t **nodes) { - FILE *file = fopen(file_name, "w"); +int pd_read_file_ws(const WSHDR *path, pd_node_t ***nodes) { + char p[256 + 1]; + ws_2str(path, p, 255); + return pd_read_file(p, nodes); +} + +int pd_write_file(const char *path, const pd_node_t **nodes) { + FILE *file = fopen(path, "w"); if (!file) { return -1; } @@ -275,6 +281,12 @@ int pd_write_file(const char *file_name, const pd_node_t **nodes) { return 0; } +int pd_write_file_ws(const WSHDR *path, const pd_node_t **nodes) { + char p[256 + 1]; + ws_2str(path, p, 255); + return pd_write_file(p, nodes); +} + size_t pd_get_max_group_size() { return PD_MAX_GROUP_SIZE; } diff --git a/src/pd.h b/src/pd.h index b6543bc..c8ae5a5 100644 --- a/src/pd.h +++ b/src/pd.h @@ -25,8 +25,10 @@ typedef PD_NODE pd_node_t; pd_node_t *pd_alloc_integer_node(const char *group, const char *key, long value); pd_node_t *pd_alloc_string_node(const char *group, const char *key, const char *value); -int pd_read_file(const char *file_name, pd_node_t ***nodes); -int pd_write_file(const char *file_name, const pd_node_t **nodes); +int pd_read_file(const char *path, pd_node_t ***nodes); +int pd_read_file_ws(const WSHDR *path, pd_node_t ***nodes); +int pd_write_file(const char *path, const pd_node_t **nodes); +int pd_write_file_ws(const WSHDR *path, const pd_node_t **nodes); size_t pd_get_max_group_size(); size_t pd_get_max_key_size();