alpm_list : change the alpm_list_find* to return the matching item.

alpm_list_find and alpm_list_find_ptr will now return a void *, and
alpm_list_find_str will return a char *, instead of an int.

Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Chantry Xavier 2007-12-02 23:48:12 +01:00 committed by Dan McGee
parent 94aa8b1f16
commit 594f1fbbb1
4 changed files with 16 additions and 14 deletions

View File

@ -412,7 +412,9 @@ static int extract_single_file(struct archive *archive,
} else { } else {
/* go to the backup array and see if our conflict is there */ /* go to the backup array and see if our conflict is there */
/* check newpkg first, so that adding backup files is retroactive */ /* check newpkg first, so that adding backup files is retroactive */
needbackup = alpm_list_find_str(alpm_pkg_get_backup(newpkg), entryname); if(alpm_list_find_str(alpm_pkg_get_backup(newpkg), entryname) != NULL) {
needbackup = 1;
}
/* check oldpkg for a backup entry, store the hash if available */ /* check oldpkg for a backup entry, store the hash if available */
if(oldpkg) { if(oldpkg) {

View File

@ -580,19 +580,19 @@ int SYMEXPORT alpm_list_count(const alpm_list_t *list)
* @param haystack the list * @param haystack the list
* @param fn the comparison function for searching (!= NULL) * @param fn the comparison function for searching (!= NULL)
* *
* @return 1 if `needle` is found, 0 otherwise * @return `needle` if found, NULL otherwise
*/ */
int SYMEXPORT alpm_list_find(const alpm_list_t *haystack, const void *needle, void SYMEXPORT *alpm_list_find(const alpm_list_t *haystack, const void *needle,
alpm_list_fn_cmp fn) alpm_list_fn_cmp fn)
{ {
const alpm_list_t *lp = haystack; const alpm_list_t *lp = haystack;
while(lp) { while(lp) {
if(lp->data && fn(lp->data, needle) == 0) { if(lp->data && fn(lp->data, needle) == 0) {
return(1); return(lp->data);
} }
lp = lp->next; lp = lp->next;
} }
return(0); return(NULL);
} }
/* trivial helper function for alpm_list_find_ptr */ /* trivial helper function for alpm_list_find_ptr */
@ -609,9 +609,9 @@ static int ptrcmp(const void *p, const void *q)
* @param needle the data to search for (== comparison) * @param needle the data to search for (== comparison)
* @param haystack the list * @param haystack the list
* *
* @return 1 if `needle` is found, 0 otherwise * @return `needle` if found, NULL otherwise
*/ */
int SYMEXPORT alpm_list_find_ptr(const alpm_list_t *haystack, const void *needle) void SYMEXPORT *alpm_list_find_ptr(const alpm_list_t *haystack, const void *needle)
{ {
return(alpm_list_find(haystack, needle, ptrcmp)); return(alpm_list_find(haystack, needle, ptrcmp));
} }
@ -622,11 +622,11 @@ int SYMEXPORT alpm_list_find_ptr(const alpm_list_t *haystack, const void *needle
* @param needle the string to search for * @param needle the string to search for
* @param haystack the list * @param haystack the list
* *
* @return 1 if `needle` is found, 0 otherwise * @return `needle` if found, NULL otherwise
*/ */
int SYMEXPORT alpm_list_find_str(const alpm_list_t *haystack, const char *needle) char SYMEXPORT *alpm_list_find_str(const alpm_list_t *haystack, const char *needle)
{ {
return(alpm_list_find(haystack, (const void*)needle, (alpm_list_fn_cmp)strcmp)); return((char *)alpm_list_find(haystack, (const void*)needle, (alpm_list_fn_cmp)strcmp));
} }
/** /**

View File

@ -73,9 +73,9 @@ void *alpm_list_getdata(const alpm_list_t *entry);
/* misc */ /* misc */
int alpm_list_count(const alpm_list_t *list); int alpm_list_count(const alpm_list_t *list);
int alpm_list_find(const alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn); void *alpm_list_find(const alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn);
int alpm_list_find_ptr(const alpm_list_t *haystack, const void *needle); void *alpm_list_find_ptr(const alpm_list_t *haystack, const void *needle);
int alpm_list_find_str(const alpm_list_t *haystack, const char *needle); char *alpm_list_find_str(const alpm_list_t *haystack, const char *needle);
alpm_list_t *alpm_list_diff(const alpm_list_t *lhs, const alpm_list_t *rhs, alpm_list_fn_cmp fn); alpm_list_t *alpm_list_diff(const alpm_list_t *lhs, const alpm_list_t *rhs, alpm_list_fn_cmp fn);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -532,7 +532,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
conflict->package1); conflict->package1);
if(!local) { if(!local) {
char *rmpkg = NULL; char *rmpkg = NULL;
int target, depend; void *target, *depend;
/* hmmm, package2 isn't installed, so it must be conflicting /* hmmm, package2 isn't installed, so it must be conflicting
* with another package in our final list. For example: * with another package in our final list. For example:
* *