aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/config_global.c24
-rw-r--r--lib/manifest.c12
-rw-r--r--lib/version_spec.c4
3 files changed, 19 insertions, 21 deletions
diff --git a/lib/config_global.c b/lib/config_global.c
index 16d97cf..f63566b 100644
--- a/lib/config_global.c
+++ b/lib/config_global.c
@@ -10,20 +10,16 @@
*/
char *get_user_conf_dir(void) {
char *result = NULL;
- wordexp_t wexp;
- wordexp("~/.spm", &wexp, 0);
- if (wexp.we_wordc != 0) {
- result = (char *)calloc(strlen(wexp.we_wordv[0]) + 1, sizeof(char));
- if (!result) {
- wordfree(&wexp);
- return NULL;
- }
- strncpy(result, wexp.we_wordv[0], strlen(wexp.we_wordv[0]));
- if (access(result, F_OK) != 0) {
- mkdirs(result, 0755);
- }
+
+ result = expandpath("~/.spm");
+ if (result == NULL) {
+ perror("get_user_conf_dir");
+ return NULL;
+ }
+
+ if (access(result, F_OK) != 0) {
+ mkdirs(result, 0755);
}
- wordfree(&wexp);
return result;
}
@@ -44,6 +40,7 @@ char *get_user_config_file(void) {
sprintf(template, "%s%c%s", ucd, DIRSEP, filename);
if (access(template, F_OK) != 0) {
// No configuration exists, so fail
+ free(ucd);
return NULL;
}
free(ucd);
@@ -109,6 +106,7 @@ char *get_package_manifest(void) {
if (manifest == NULL) {
perror("manifest generator");
fprintf(SYSERROR);
+ free(ucd);
return NULL;
}
manifest_write(manifest, PKG_DIR);
diff --git a/lib/manifest.c b/lib/manifest.c
index 1b2b600..72919ff 100644
--- a/lib/manifest.c
+++ b/lib/manifest.c
@@ -11,7 +11,7 @@
* @param b
* @return 0 = same, !0 = different
*/
-int manifest_package_cmp(ManifestPackage *a, ManifestPackage *b) {
+int manifest_package_cmp(const ManifestPackage *a, const ManifestPackage *b) {
int result = 0;
if (a == NULL || b == NULL) {
return -1;
@@ -517,7 +517,7 @@ Manifest *manifest_read(char *file_or_url) {
* @param _package package name
* @return found=`ManifestPackage`, not found=NULL
*/
-ManifestPackage *manifest_search(Manifest *info, const char *_package) {
+ManifestPackage *manifest_search(const Manifest *info, const char *_package) {
ManifestPackage *match = NULL;
char package[PATH_MAX];
@@ -535,7 +535,7 @@ ManifestPackage *manifest_search(Manifest *info, const char *_package) {
* @param manifest
* @return `ManifestPackage`
*/
-ManifestPackage *manifest_package_copy(ManifestPackage *manifest) {
+ManifestPackage *manifest_package_copy(const ManifestPackage *manifest) {
if (manifest == NULL) {
return NULL;
}
@@ -543,7 +543,7 @@ ManifestPackage *manifest_package_copy(ManifestPackage *manifest) {
ManifestPackage *result = calloc(1, sizeof(ManifestPackage));
memcpy(result, manifest, sizeof(ManifestPackage));
- if (manifest->requirements_records > 0) {
+ if (manifest->requirements_records > 0 && manifest->requirements != NULL) {
result->requirements = (char **)calloc(manifest->requirements_records, sizeof(char *));
for (size_t i = 0; i < manifest->requirements_records; i++) {
result->requirements[i] = strdup(manifest->requirements[i]);
@@ -615,7 +615,7 @@ ManifestPackage *manifestlist_search(ManifestList *pManifestList, const char *_p
* @param ManifestList
* @return
*/
-size_t manifestlist_count(ManifestList *pManifestList) {
+size_t manifestlist_count(const ManifestList *pManifestList) {
return pManifestList->num_inuse;
}
@@ -642,7 +642,7 @@ void manifestlist_set(ManifestList *pManifestList, size_t index, Manifest *value
* @param index
* @return string
*/
-Manifest *manifestlist_item(ManifestList *pManifestList, size_t index) {
+Manifest *manifestlist_item(const ManifestList *pManifestList, size_t index) {
if (index > manifestlist_count(pManifestList)) {
return NULL;
}
diff --git a/lib/version_spec.c b/lib/version_spec.c
index 06fcd1b..d7c8b2e 100644
--- a/lib/version_spec.c
+++ b/lib/version_spec.c
@@ -279,7 +279,7 @@ static int _find_by_spec_compare(const void *a, const void *b) {
* @param version_str
* @return
*/
-ManifestPackage **find_by_spec(Manifest *manifest, const char *name, const char *op, const char *version_str) {
+ManifestPackage **find_by_spec(const Manifest *manifest, const char *name, const char *op, const char *version_str) {
size_t record = 0;
ManifestPackage **list = (ManifestPackage **) calloc(manifest->records + 1, sizeof(ManifestPackage *));
if (!list) {
@@ -387,7 +387,7 @@ static char *get_operators(char **op, const char *_strspec) {
return pos;
}
-ManifestPackage *find_by_strspec(Manifest *manifest, const char *_strspec) {
+ManifestPackage *find_by_strspec(const Manifest *manifest, const char *_strspec) {
char *pos = NULL;
char s_op[NAME_MAX];
char s_name[NAME_MAX];