mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 15:58:50 -05:00
Enforce const correctness on dep functions and rewrite alpm_dep_get_string
Add some const specifiers to the dep functions that can have them. In addition, rewrite alpm_dep_get_string to use snprintf and cover all of the bases (operators). Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
ec6a7d689b
commit
1b2817f539
@ -378,14 +378,14 @@ int alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep);
|
||||
alpm_list_t *alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
|
||||
alpm_list_t *packages);
|
||||
|
||||
const char *alpm_miss_get_target(pmdepmissing_t *miss);
|
||||
pmdeptype_t alpm_miss_get_type(pmdepmissing_t *miss);
|
||||
const char *alpm_miss_get_target(const pmdepmissing_t *miss);
|
||||
pmdeptype_t alpm_miss_get_type(const pmdepmissing_t *miss);
|
||||
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);
|
||||
pmdepmod_t alpm_dep_get_mod(const pmdepend_t *dep);
|
||||
const char *alpm_dep_get_name(const pmdepend_t *dep);
|
||||
const char *alpm_dep_get_version(const pmdepend_t *dep);
|
||||
char *alpm_dep_get_string(const pmdepend_t *dep);
|
||||
|
||||
/*
|
||||
* File conflicts
|
||||
|
@ -770,23 +770,21 @@ error:
|
||||
return(-1);
|
||||
}
|
||||
|
||||
const char SYMEXPORT *alpm_miss_get_target(pmdepmissing_t *miss)
|
||||
const char SYMEXPORT *alpm_miss_get_target(const pmdepmissing_t *miss)
|
||||
{
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
/* Sanity checks */
|
||||
ASSERT(handle != NULL, return(NULL));
|
||||
ASSERT(miss != NULL, return(NULL));
|
||||
|
||||
return miss->target;
|
||||
}
|
||||
|
||||
pmdeptype_t SYMEXPORT alpm_miss_get_type(pmdepmissing_t *miss)
|
||||
pmdeptype_t SYMEXPORT alpm_miss_get_type(const pmdepmissing_t *miss)
|
||||
{
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
/* Sanity checks */
|
||||
ASSERT(handle != NULL, return(-1));
|
||||
ASSERT(miss != NULL, return(-1));
|
||||
|
||||
return miss->type;
|
||||
@ -797,76 +795,80 @@ pmdepend_t SYMEXPORT *alpm_miss_get_dep(pmdepmissing_t *miss)
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
/* Sanity checks */
|
||||
ASSERT(handle != NULL, return(NULL));
|
||||
ASSERT(miss != NULL, return(NULL));
|
||||
|
||||
return &miss->depend;
|
||||
}
|
||||
|
||||
pmdepmod_t SYMEXPORT alpm_dep_get_mod(pmdepend_t *dep)
|
||||
pmdepmod_t SYMEXPORT alpm_dep_get_mod(const pmdepend_t *dep)
|
||||
{
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
/* Sanity checks */
|
||||
ASSERT(handle != NULL, return(-1));
|
||||
ASSERT(dep != NULL, return(-1));
|
||||
|
||||
return dep->mod;
|
||||
}
|
||||
|
||||
const char SYMEXPORT *alpm_dep_get_name(pmdepend_t *dep)
|
||||
const char SYMEXPORT *alpm_dep_get_name(const pmdepend_t *dep)
|
||||
{
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
/* Sanity checks */
|
||||
ASSERT(handle != NULL, return(NULL));
|
||||
ASSERT(dep != NULL, return(NULL));
|
||||
|
||||
return dep->name;
|
||||
}
|
||||
|
||||
const char SYMEXPORT *alpm_dep_get_version(pmdepend_t *dep)
|
||||
const char SYMEXPORT *alpm_dep_get_version(const pmdepend_t *dep)
|
||||
{
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
/* Sanity checks */
|
||||
ASSERT(handle != NULL, return(NULL));
|
||||
ASSERT(dep != NULL, return(NULL));
|
||||
|
||||
return dep->version;
|
||||
}
|
||||
|
||||
/* the return-string must be freed! */
|
||||
char SYMEXPORT *alpm_dep_get_string(pmdepend_t *dep)
|
||||
/** Reverse of splitdep; make a dep string from a pmdepend_t struct.
|
||||
* The string must be freed!
|
||||
* @param dep the depend to turn into a string
|
||||
* @return a string-formatted dependency with operator if necessary
|
||||
*/
|
||||
char SYMEXPORT *alpm_dep_get_string(const pmdepend_t *dep)
|
||||
{
|
||||
char *opr, *str = NULL;
|
||||
size_t len;
|
||||
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
/* Sanity checks */
|
||||
ASSERT(handle != NULL, return(NULL));
|
||||
ASSERT(dep != NULL, return(NULL));
|
||||
|
||||
/* TODO redo the sprintf, change to snprintf and
|
||||
* make it less hacky and dependent on sizeof, etc */
|
||||
char *ptr;
|
||||
char *depstring;
|
||||
MALLOC(depstring, sizeof(pmdepend_t), RET_ERR(PM_ERR_MEMORY, 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);
|
||||
opr = "";
|
||||
break;
|
||||
case PM_DEP_MOD_GE:
|
||||
sprintf(ptr, ">=%s", dep->version);
|
||||
opr = ">=";
|
||||
break;
|
||||
case PM_DEP_MOD_LE:
|
||||
sprintf(ptr, "<=%s", dep->version);
|
||||
opr = "<=";
|
||||
break;
|
||||
case PM_DEP_MOD_EQ:
|
||||
opr = "=";
|
||||
break;
|
||||
default:
|
||||
opr = "";
|
||||
break;
|
||||
}
|
||||
|
||||
return(depstring);
|
||||
/* we can always compute len and print the string like this because opr
|
||||
* and ver will be empty when PM_DEP_MOD_ANY is the depend type */
|
||||
len = strlen(dep->name) + strlen(opr) + strlen(dep->version) + 1;
|
||||
MALLOC(str, len, RET_ERR(PM_ERR_MEMORY, NULL));
|
||||
snprintf(str, len, "%s%s%s", dep->name, opr, dep->version);
|
||||
|
||||
return(str);
|
||||
}
|
||||
/* vim: set ts=2 sw=2 noet: */
|
||||
|
Loading…
Reference in New Issue
Block a user