diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-02-26 16:09:32 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-02-26 16:09:32 -0500 |
commit | d3580f8c0b5c17150382c4b4456e0b1bfa81a50f (patch) | |
tree | 5d0fa6911974b2a0541738a7cffc408b09918b8b /src/str.c | |
parent | 639aa9dbf60050bf1bbaeea67df13729239c3a31 (diff) | |
download | spmc-d3580f8c0b5c17150382c4b4456e0b1bfa81a50f.tar.gz |
Multiple things:
* Add strdup_array()
* Begin consolidating spm root information into SPM_Hierarchy
* Begin consolidating metadata
* Begin trimming repeated code (mostly file reading)
* Store information about installed packages under [root]/var/db/records
Diffstat (limited to 'src/str.c')
-rw-r--r-- | src/str.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -597,4 +597,28 @@ char *normalize_space(char *s) { return result; } +/** + * Duplicate an array of strings + * @param array + * @return + */ +char **strdup_array(char **array) { + char **result = NULL; + size_t elems = 0; + + // Guard + if (array == NULL) { + return NULL; + } + // Count elements in `array` + for (elems = 0; array[elems] != NULL; elems++); + + // Create new array + result = calloc(elems + 1, sizeof(char *)); + for (size_t i = 0; i < elems; i++) { + result[i] = strdup(array[i]); + } + + return result; +} |