diff options
Diffstat (limited to 'lib/libalpm')
-rw-r--r-- | lib/libalpm/alpm.h | 1 | ||||
-rw-r--r-- | lib/libalpm/deps.c | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 880bbeb0..2000db4a 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -379,6 +379,7 @@ pmdepend_t *alpm_miss_get_dep(pmdepmissing_t *miss); pmdepmod_t alpm_dep_get_mod(pmdepend_t *dep); const char *alpm_dep_get_name(pmdepend_t *dep); const char *alpm_dep_get_version(pmdepend_t *dep); +char *alpm_dep_get_string(pmdepend_t *dep); /* * File conflicts diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 69c675cd..7f4fb0b5 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -838,4 +838,38 @@ const char SYMEXPORT *alpm_dep_get_version(pmdepend_t *dep) return dep->version; } +/* the return-string must be freed! */ +char SYMEXPORT *alpm_dep_get_string(pmdepend_t *dep) +{ + ALPM_LOG_FUNC; + + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(dep != NULL, return(NULL)); + + char *ptr; + char *depstring = malloc(sizeof(pmdepend_t)); + if(depstring == NULL) { + _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"), sizeof(pmdepend_t)); + return NULL; + } + + strcpy(depstring, dep->name); + ptr = depstring + strlen(depstring); + switch(dep->mod) { + case PM_DEP_MOD_ANY: + break; + case PM_DEP_MOD_EQ: + sprintf(ptr, "=%s", dep->version); + break; + case PM_DEP_MOD_GE: + sprintf(ptr, ">=%s", dep->version); + break; + case PM_DEP_MOD_LE: + sprintf(ptr, "<=%s", dep->version); + break; + } + + return(depstring); +} /* vim: set ts=2 sw=2 noet: */ |