Const correctness!

Add some 'const' keywords all over the code to make it a bit more strict on
what you can and can't do with data. This is especially important when we
return pointers to the pacman frontend- ideally this would always be
untouchable data.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2007-06-05 17:34:33 -04:00
parent 4906b76c85
commit f7912e9dc6
22 changed files with 146 additions and 137 deletions

View file

@ -284,7 +284,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
struct archive *archive; struct archive *archive;
struct archive_entry *entry; struct archive_entry *entry;
char cwd[PATH_MAX] = ""; char cwd[PATH_MAX] = "";
alpm_list_t *targ, *lp; alpm_list_t *targ;
const int archive_flags = ARCHIVE_EXTRACT_OWNER | const int archive_flags = ARCHIVE_EXTRACT_OWNER |
ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_PERM |
ARCHIVE_EXTRACT_TIME; ARCHIVE_EXTRACT_TIME;
@ -383,7 +383,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
/* copy the remove skiplist over */ /* copy the remove skiplist over */
tr->skip_remove = alpm_list_strdup(trans->skip_remove); tr->skip_remove = alpm_list_strdup(trans->skip_remove);
alpm_list_t *b; const alpm_list_t *b;
/* Add files in the NEW package's backup array to the noupgrade array /* Add files in the NEW package's backup array to the noupgrade array
* so this removal operation doesn't kill them */ * so this removal operation doesn't kill them */
@ -557,14 +557,17 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
hash_pkg = _alpm_SHAFile(tempfile); hash_pkg = _alpm_SHAFile(tempfile);
} }
/* append the new md5 or sha1 hash to it's respective entry in newpkg's backup /* append the new md5 or sha1 hash to it's respective entry
* (it will be the new orginal) */ * in newpkg's backup (it will be the new orginal) */
for(lp = alpm_pkg_get_backup(newpkg); lp; lp = lp->next) { alpm_list_t *backups;
if(!lp->data || strcmp(lp->data, entryname) != 0) { for(backups = alpm_pkg_get_backup(newpkg); backups;
backups = alpm_list_next(backups)) {
char *oldbackup = alpm_list_getdata(backups);
if(!oldbackup || strcmp(oldbackup, entryname) != 0) {
continue; continue;
} }
char *backup = NULL; char *backup = NULL;
int backup_len = strlen(lp->data) + 2; /* tab char and null byte */ int backup_len = strlen(oldbackup) + 2; /* tab char and null byte */
if(use_md5) { if(use_md5) {
backup_len += 32; /* MD5s are 32 chars in length */ backup_len += 32; /* MD5s are 32 chars in length */
@ -577,10 +580,10 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
RET_ERR(PM_ERR_MEMORY, -1); RET_ERR(PM_ERR_MEMORY, -1);
} }
sprintf(backup, "%s\t%s", (char *)lp->data, hash_pkg); sprintf(backup, "%s\t%s", oldbackup, hash_pkg);
backup[backup_len-1] = '\0'; backup[backup_len-1] = '\0';
FREE(lp->data); FREE(oldbackup);
lp->data = backup; backups->data = backup;
} }
if(use_md5) { if(use_md5) {
@ -698,11 +701,13 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
} }
/* calculate an hash if this is in newpkg's backup */ /* calculate an hash if this is in newpkg's backup */
for(lp = alpm_pkg_get_backup(newpkg); lp; lp = lp->next) { alpm_list_t *b;
for(b = alpm_pkg_get_backup(newpkg); b; b = b->next) {
char *backup = NULL, *hash = NULL; char *backup = NULL, *hash = NULL;
int backup_len = strlen(lp->data) + 2; /* tab char and null byte */ char *oldbackup = alpm_list_getdata(b);
int backup_len = strlen(oldbackup) + 2; /* tab char and null byte */
if(!lp->data || strcmp(lp->data, entryname) != 0) { if(!oldbackup || strcmp(oldbackup, entryname) != 0) {
continue; continue;
} }
_alpm_log(PM_LOG_DEBUG, _("appending backup entry for %s"), filename); _alpm_log(PM_LOG_DEBUG, _("appending backup entry for %s"), filename);
@ -720,11 +725,11 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
RET_ERR(PM_ERR_MEMORY, -1); RET_ERR(PM_ERR_MEMORY, -1);
} }
sprintf(backup, "%s\t%s", (char *)lp->data, hash); sprintf(backup, "%s\t%s", oldbackup, hash);
backup[backup_len-1] = '\0'; backup[backup_len-1] = '\0';
FREE(hash); FREE(hash);
FREE(lp->data); FREE(oldbackup);
lp->data = backup; b->data = backup;
} }
} }
} }

View file

@ -113,19 +113,19 @@ unsigned short alpm_option_get_usesyslog();
void alpm_option_set_usesyslog(unsigned short usesyslog); void alpm_option_set_usesyslog(unsigned short usesyslog);
alpm_list_t *alpm_option_get_noupgrades(); alpm_list_t *alpm_option_get_noupgrades();
void alpm_option_add_noupgrade(char *pkg); void alpm_option_add_noupgrade(const char *pkg);
void alpm_option_set_noupgrades(alpm_list_t *noupgrade); void alpm_option_set_noupgrades(alpm_list_t *noupgrade);
alpm_list_t *alpm_option_get_noextracts(); alpm_list_t *alpm_option_get_noextracts();
void alpm_option_add_noextract(char *pkg); void alpm_option_add_noextract(const char *pkg);
void alpm_option_set_noextracts(alpm_list_t *noextract); void alpm_option_set_noextracts(alpm_list_t *noextract);
alpm_list_t *alpm_option_get_ignorepkgs(); alpm_list_t *alpm_option_get_ignorepkgs();
void alpm_option_add_ignorepkg(char *pkg); void alpm_option_add_ignorepkg(const char *pkg);
void alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs); void alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs);
alpm_list_t *alpm_option_get_holdpkgs(); alpm_list_t *alpm_option_get_holdpkgs();
void alpm_option_add_holdpkg(char *pkg); void alpm_option_add_holdpkg(const char *pkg);
void alpm_option_set_holdpkgs(alpm_list_t *holdpkgs); void alpm_option_set_holdpkgs(alpm_list_t *holdpkgs);
time_t alpm_option_get_upgradedelay(); time_t alpm_option_get_upgradedelay();
@ -137,10 +137,6 @@ void alpm_option_set_xfercommand(const char *cmd);
unsigned short alpm_option_get_nopassiveftp(); unsigned short alpm_option_get_nopassiveftp();
void alpm_option_set_nopassiveftp(unsigned short nopasv); void alpm_option_set_nopassiveftp(unsigned short nopasv);
alpm_list_t *alpm_option_get_needles();
void alpm_option_add_needle(char *needle);
void alpm_option_set_needles(alpm_list_t *needles);
pmdb_t *alpm_option_get_localdb(); pmdb_t *alpm_option_get_localdb();
alpm_list_t *alpm_option_get_syncdbs(); alpm_list_t *alpm_option_get_syncdbs();
@ -151,8 +147,8 @@ alpm_list_t *alpm_option_get_syncdbs();
pmdb_t *alpm_db_register(const char *treename); pmdb_t *alpm_db_register(const char *treename);
int alpm_db_unregister(pmdb_t *db); int alpm_db_unregister(pmdb_t *db);
const char *alpm_db_get_name(pmdb_t *db); const char *alpm_db_get_name(const pmdb_t *db);
const char *alpm_db_get_url(pmdb_t *db); const char *alpm_db_get_url(const pmdb_t *db);
int alpm_db_setserver(pmdb_t *db, const char *url); int alpm_db_setserver(pmdb_t *db, const char *url);
@ -164,7 +160,7 @@ alpm_list_t *alpm_db_whatprovides(pmdb_t *db, const char *name);
pmgrp_t *alpm_db_readgrp(pmdb_t *db, const char *name); pmgrp_t *alpm_db_readgrp(pmdb_t *db, const char *name);
alpm_list_t *alpm_db_getgrpcache(pmdb_t *db); alpm_list_t *alpm_db_getgrpcache(pmdb_t *db);
alpm_list_t *alpm_db_search(pmdb_t *db, alpm_list_t* needles); alpm_list_t *alpm_db_search(pmdb_t *db, const alpm_list_t* needles);
alpm_list_t *alpm_db_get_upgrades(); alpm_list_t *alpm_db_get_upgrades();
@ -188,13 +184,13 @@ typedef enum _pmpkghasarch_t {
} pmpkghasarch_t; } pmpkghasarch_t;
*/ */
int alpm_pkg_load(char *filename, pmpkg_t **pkg); int alpm_pkg_load(const char *filename, pmpkg_t **pkg);
int alpm_pkg_free(pmpkg_t *pkg); int alpm_pkg_free(pmpkg_t *pkg);
int alpm_pkg_checkmd5sum(pmpkg_t *pkg); int alpm_pkg_checkmd5sum(pmpkg_t *pkg);
int alpm_pkg_checksha1sum(pmpkg_t *pkg); int alpm_pkg_checksha1sum(pmpkg_t *pkg);
char *alpm_fetch_pkgurl(char *url); char *alpm_fetch_pkgurl(const char *url);
int alpm_pkg_vercmp(const char *ver1, const char *ver2); int alpm_pkg_vercmp(const char *ver1, const char *ver2);
char *alpm_pkg_name_hasarch(char *pkgname); char *alpm_pkg_name_hasarch(const char *pkgname);
const char *alpm_pkg_get_filename(pmpkg_t *pkg); const char *alpm_pkg_get_filename(pmpkg_t *pkg);
const char *alpm_pkg_get_name(pmpkg_t *pkg); const char *alpm_pkg_get_name(pmpkg_t *pkg);
@ -225,8 +221,8 @@ unsigned short alpm_pkg_has_scriptlet(pmpkg_t *pkg);
/* /*
* Groups * Groups
*/ */
const char *alpm_grp_get_name(pmgrp_t *grp); const char *alpm_grp_get_name(const pmgrp_t *grp);
alpm_list_t *alpm_grp_get_pkgs(pmgrp_t *grp); const alpm_list_t *alpm_grp_get_pkgs(const pmgrp_t *grp);
/* /*
* Sync * Sync
@ -239,9 +235,9 @@ typedef enum _pmsynctype_t {
PM_SYNC_TYPE_DEPEND PM_SYNC_TYPE_DEPEND
} pmsynctype_t; } pmsynctype_t;
pmsynctype_t alpm_sync_get_type(pmsyncpkg_t *sync); pmsynctype_t alpm_sync_get_type(const pmsyncpkg_t *sync);
pmpkg_t *alpm_sync_get_pkg(pmsyncpkg_t *sync); pmpkg_t *alpm_sync_get_pkg(const pmsyncpkg_t *sync);
void *alpm_sync_get_data(pmsyncpkg_t *sync); void *alpm_sync_get_data(const pmsyncpkg_t *sync);
/* /*
* Transactions * Transactions
@ -383,7 +379,7 @@ const char *alpm_conflict_get_ctarget(pmconflict_t *conflict);
* Helpers * Helpers
*/ */
/* md5sums */ /* checksums */
char *alpm_get_md5sum(char *name); char *alpm_get_md5sum(char *name);
char *alpm_get_sha1sum(char *name); char *alpm_get_sha1sum(char *name);
@ -459,7 +455,7 @@ enum _pmerrno_t {
extern enum _pmerrno_t pm_errno; extern enum _pmerrno_t pm_errno;
char *alpm_strerror(int err); const char *alpm_strerror(int err);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -345,9 +345,10 @@ alpm_list_t *alpm_list_remove_node(alpm_list_t *node)
* *
* @return a new list containing non-duplicate items * @return a new list containing non-duplicate items
*/ */
alpm_list_t SYMEXPORT *alpm_list_remove_dupes(alpm_list_t *list) alpm_list_t SYMEXPORT *alpm_list_remove_dupes(const alpm_list_t *list)
{ /* TODO does removing the strdup here cause invalid free's anywhere? */ { /* TODO does removing the strdup here cause invalid free's anywhere? */
alpm_list_t *lp = list, *newlist = NULL; const alpm_list_t *lp = list;
alpm_list_t *newlist = NULL;
while(lp) { while(lp) {
if(!alpm_list_find(newlist, lp->data)) { if(!alpm_list_find(newlist, lp->data)) {
newlist = alpm_list_add(newlist, lp->data); newlist = alpm_list_add(newlist, lp->data);
@ -366,9 +367,10 @@ alpm_list_t SYMEXPORT *alpm_list_remove_dupes(alpm_list_t *list)
* *
* @return a copy of the original list * @return a copy of the original list
*/ */
alpm_list_t *alpm_list_strdup(alpm_list_t *list) alpm_list_t *alpm_list_strdup(const alpm_list_t *list)
{ {
alpm_list_t *lp = list, *newlist = NULL; const alpm_list_t *lp = list;
alpm_list_t *newlist = NULL;
while(lp) { while(lp) {
newlist = alpm_list_add(newlist, strdup(lp->data)); newlist = alpm_list_add(newlist, strdup(lp->data));
lp = lp->next; lp = lp->next;
@ -404,9 +406,9 @@ alpm_list_t *alpm_list_reverse(alpm_list_t *list)
* *
* @return the first element in the list * @return the first element in the list
*/ */
inline alpm_list_t SYMEXPORT *alpm_list_first(alpm_list_t *list) inline alpm_list_t SYMEXPORT *alpm_list_first(const alpm_list_t *list)
{ {
return(list); return((alpm_list_t*)list);
} }
/** /**
@ -417,13 +419,13 @@ inline alpm_list_t SYMEXPORT *alpm_list_first(alpm_list_t *list)
* *
* @return an alpm_list_t node for index `n` * @return an alpm_list_t node for index `n`
*/ */
alpm_list_t *alpm_list_nth(alpm_list_t *list, int n) alpm_list_t *alpm_list_nth(const alpm_list_t *list, int n)
{ {
alpm_list_t *i = list; const alpm_list_t *i = list;
while(n--) { while(n--) {
i = i->next; i = i->next;
} }
return(i); return((alpm_list_t*)i);
} }
/** /**
@ -433,7 +435,7 @@ alpm_list_t *alpm_list_nth(alpm_list_t *list, int n)
* *
* @return the next element, or NULL when no more elements exist * @return the next element, or NULL when no more elements exist
*/ */
inline alpm_list_t SYMEXPORT *alpm_list_next(alpm_list_t *node) inline alpm_list_t SYMEXPORT *alpm_list_next(const alpm_list_t *node)
{ {
return(node->next); return(node->next);
} }
@ -445,13 +447,13 @@ inline alpm_list_t SYMEXPORT *alpm_list_next(alpm_list_t *node)
* *
* @return the last element in the list * @return the last element in the list
*/ */
alpm_list_t *alpm_list_last(alpm_list_t *list) alpm_list_t *alpm_list_last(const alpm_list_t *list)
{ {
alpm_list_t *i = list; const alpm_list_t *i = list;
while(i && i->next) { while(i && i->next) {
i = i->next; i = i->next;
} }
return(i); return((alpm_list_t*)i);
} }
/** /**
@ -497,9 +499,9 @@ int SYMEXPORT alpm_list_count(const alpm_list_t *list)
* *
* @return 1 if `needle` is found, 0 otherwise * @return 1 if `needle` is found, 0 otherwise
*/ */
int SYMEXPORT alpm_list_find(alpm_list_t *haystack, const void *needle) int SYMEXPORT alpm_list_find(const alpm_list_t *haystack, const void *needle)
{ {
alpm_list_t *lp = haystack; const alpm_list_t *lp = haystack;
while(lp) { while(lp) {
if(lp->data == needle) { if(lp->data == needle) {
return(1); return(1);
@ -518,9 +520,9 @@ int SYMEXPORT alpm_list_find(alpm_list_t *haystack, const void *needle)
* *
* @return 1 if `needle` is found, 0 otherwise * @return 1 if `needle` is found, 0 otherwise
*/ */
int SYMEXPORT alpm_list_find_str(alpm_list_t *haystack, const char *needle) int SYMEXPORT alpm_list_find_str(const alpm_list_t *haystack, const char *needle)
{ {
alpm_list_t *lp = haystack; const alpm_list_t *lp = haystack;
while(lp) { while(lp) {
if(lp->data && strcmp((const char *)lp->data, needle) == 0) { if(lp->data && strcmp((const char *)lp->data, needle) == 0) {
return(1); return(1);
@ -543,9 +545,11 @@ int SYMEXPORT alpm_list_find_str(alpm_list_t *haystack, const char *needle)
* *
* @return a list containing all items in `lhs` not present in `rhs` * @return a list containing all items in `lhs` not present in `rhs`
*/ */
alpm_list_t *alpm_list_diff(alpm_list_t *lhs, 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)
{ {
alpm_list_t *i, *j, *ret = NULL; const alpm_list_t *i, *j;
alpm_list_t *ret = NULL;
for(i = lhs; i; i = i->next) { for(i = lhs; i; i = i->next) {
int found = 0; int found = 0;
for(j = rhs; j; j = j->next) { for(j = rhs; j; j = j->next) {

View file

@ -60,22 +60,22 @@ alpm_list_t *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, alpm_list_f
alpm_list_t *alpm_list_msort(alpm_list_t *list, int n, alpm_list_fn_cmp fn); alpm_list_t *alpm_list_msort(alpm_list_t *list, int n, alpm_list_fn_cmp fn);
alpm_list_t *alpm_list_remove(alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn, void **data); alpm_list_t *alpm_list_remove(alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn, void **data);
alpm_list_t *alpm_list_remove_node(alpm_list_t *node); alpm_list_t *alpm_list_remove_node(alpm_list_t *node);
alpm_list_t *alpm_list_remove_dupes(alpm_list_t *list); alpm_list_t *alpm_list_remove_dupes(const alpm_list_t *list);
alpm_list_t *alpm_list_strdup(alpm_list_t *list); alpm_list_t *alpm_list_strdup(const alpm_list_t *list);
alpm_list_t *alpm_list_reverse(alpm_list_t *list); alpm_list_t *alpm_list_reverse(alpm_list_t *list);
/* item accessors */ /* item accessors */
alpm_list_t *alpm_list_first(alpm_list_t *list); alpm_list_t *alpm_list_first(const alpm_list_t *list);
alpm_list_t *alpm_list_nth(alpm_list_t *list, int n); alpm_list_t *alpm_list_nth(const alpm_list_t *list, int n);
alpm_list_t *alpm_list_next(alpm_list_t *list); alpm_list_t *alpm_list_next(const alpm_list_t *list);
alpm_list_t *alpm_list_last(alpm_list_t *list); alpm_list_t *alpm_list_last(const alpm_list_t *list);
void *alpm_list_getdata(const alpm_list_t *entry); 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(alpm_list_t *haystack, const void *needle); int alpm_list_find(const alpm_list_t *haystack, const void *needle);
int alpm_list_find_str(alpm_list_t *haystack,const char *needle); int alpm_list_find_str(const alpm_list_t *haystack,const char *needle);
alpm_list_t *alpm_list_diff(alpm_list_t *lhs, 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

@ -36,9 +36,9 @@
/* Look for a filename in a pmpkg_t.backup list. If we find it, /* Look for a filename in a pmpkg_t.backup list. If we find it,
* then we return the md5 or sha1 hash (parsed from the same line) * then we return the md5 or sha1 hash (parsed from the same line)
*/ */
char *_alpm_needbackup(const char *file, alpm_list_t *backup) char *_alpm_needbackup(const char *file, const alpm_list_t *backup)
{ {
alpm_list_t *lp; const alpm_list_t *lp;
ALPM_LOG_FUNC; ALPM_LOG_FUNC;

View file

@ -23,7 +23,7 @@
#include "alpm_list.h" #include "alpm_list.h"
char *_alpm_needbackup(const char *file, alpm_list_t *backup); char *_alpm_needbackup(const char *file, const alpm_list_t *backup);
#endif /* _ALPM_BACKUP_H */ #endif /* _ALPM_BACKUP_H */

View file

@ -715,7 +715,7 @@ int _alpm_db_remove(pmdb_t *db, pmpkg_t *info)
* Returns 0 on success, 1 on error * Returns 0 on success, 1 on error
* *
*/ */
int _alpm_db_getlastupdate(pmdb_t *db, char *ts) int _alpm_db_getlastupdate(const pmdb_t *db, char *ts)
{ {
FILE *fp; FILE *fp;
char file[PATH_MAX]; char file[PATH_MAX];
@ -747,7 +747,7 @@ int _alpm_db_getlastupdate(pmdb_t *db, char *ts)
/* writes the dbpath/.lastupdate with the contents of *ts /* writes the dbpath/.lastupdate with the contents of *ts
*/ */
int _alpm_db_setlastupdate(pmdb_t *db, char *ts) int _alpm_db_setlastupdate(const pmdb_t *db, char *ts)
{ {
FILE *fp; FILE *fp;
char file[PATH_MAX]; char file[PATH_MAX];

View file

@ -204,7 +204,7 @@ int _alpm_db_load_grpcache(pmdb_t *db)
_alpm_log(PM_LOG_DEBUG, _("loading group cache for repository '%s'"), db->treename); _alpm_log(PM_LOG_DEBUG, _("loading group cache for repository '%s'"), db->treename);
for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) { for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
alpm_list_t *i; const alpm_list_t *i;
pmpkg_t *pkg = lp->data; pmpkg_t *pkg = lp->data;
for(i = alpm_pkg_get_groups(pkg); i; i = i->next) { for(i = alpm_pkg_get_groups(pkg); i; i = i->next) {

View file

@ -258,6 +258,35 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
return(0); return(0);
} }
const char SYMEXPORT *alpm_db_get_name(const pmdb_t *db)
{
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(handle != NULL, return(NULL));
ASSERT(db != NULL, return(NULL));
return db->treename;
}
const char SYMEXPORT *alpm_db_get_url(const pmdb_t *db)
{
char path[PATH_MAX];
pmserver_t *s;
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(handle != NULL, return(NULL));
ASSERT(db != NULL, return(NULL));
s = (pmserver_t*)db->servers->data;
snprintf(path, PATH_MAX, "%s://%s%s", s->s_url->scheme, s->s_url->host, s->s_url->doc);
return strdup(path);
}
/** Get a package entry from a package database /** Get a package entry from a package database
* @param db pointer to the package database to get the package from * @param db pointer to the package database to get the package from
* @param name of the package * @param name of the package
@ -344,7 +373,7 @@ alpm_list_t SYMEXPORT *alpm_db_getgrpcache(pmdb_t *db)
* @param needles the list of strings to search for * @param needles the list of strings to search for
* @return the list of packages on success, NULL on error * @return the list of packages on success, NULL on error
*/ */
alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, alpm_list_t* needles) alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, const alpm_list_t* needles)
{ {
ALPM_LOG_FUNC; ALPM_LOG_FUNC;
@ -361,7 +390,7 @@ alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, alpm_list_t* needles)
alpm_list_t SYMEXPORT *alpm_db_get_upgrades() alpm_list_t SYMEXPORT *alpm_db_get_upgrades()
{ {
alpm_list_t *syncpkgs = NULL; alpm_list_t *syncpkgs = NULL;
alpm_list_t *i, *j, *k, *m; const alpm_list_t *i, *j, *k, *m;
ALPM_LOG_FUNC; ALPM_LOG_FUNC;
@ -540,9 +569,10 @@ int _alpm_db_cmp(const void *db1, const void *db2)
return(strcmp(((pmdb_t *)db1)->treename, ((pmdb_t *)db2)->treename)); return(strcmp(((pmdb_t *)db1)->treename, ((pmdb_t *)db2)->treename));
} }
alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles) alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles)
{ {
alpm_list_t *i, *j, *k, *ret = NULL; const alpm_list_t *i, *j, *k;
alpm_list_t *ret = NULL;
ALPM_LOG_FUNC; ALPM_LOG_FUNC;
@ -659,32 +689,4 @@ pmdb_t *_alpm_db_register(const char *treename)
return(db); return(db);
} }
const char SYMEXPORT *alpm_db_get_name(pmdb_t *db)
{
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(handle != NULL, return(NULL));
ASSERT(db != NULL, return(NULL));
return db->treename;
}
const char *alpm_db_get_url(pmdb_t *db)
{
char path[PATH_MAX];
pmserver_t *s;
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(handle != NULL, return(NULL));
ASSERT(db != NULL, return(NULL));
s = (pmserver_t*)db->servers->data;
snprintf(path, PATH_MAX, "%s://%s%s", s->s_url->scheme, s->s_url->host, s->s_url->doc);
return strdup(path);
}
/* vim: set ts=2 sw=2 noet: */ /* vim: set ts=2 sw=2 noet: */

View file

@ -51,7 +51,7 @@ struct __pmdb_t {
pmdb_t *_alpm_db_new(const char *dbpath, const char *treename); pmdb_t *_alpm_db_new(const char *dbpath, const char *treename);
void _alpm_db_free(pmdb_t *db); void _alpm_db_free(pmdb_t *db);
int _alpm_db_cmp(const void *db1, const void *db2); int _alpm_db_cmp(const void *db1, const void *db2);
alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles); alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles);
pmdb_t *_alpm_db_register(const char *treename); pmdb_t *_alpm_db_register(const char *treename);
/* be.c, backend specific calls */ /* be.c, backend specific calls */
@ -63,8 +63,8 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target);
int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq); int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq); int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
int _alpm_db_remove(pmdb_t *db, pmpkg_t *info); int _alpm_db_remove(pmdb_t *db, pmpkg_t *info);
int _alpm_db_getlastupdate(pmdb_t *db, char *ts); int _alpm_db_getlastupdate(const pmdb_t *db, char *ts);
int _alpm_db_setlastupdate(pmdb_t *db, char *ts); int _alpm_db_setlastupdate(const pmdb_t *db, char *ts);
#endif /* _ALPM_DB_H */ #endif /* _ALPM_DB_H */

View file

@ -30,7 +30,7 @@
#include "alpm.h" #include "alpm.h"
/* TODO does this really need a file all on its own? */ /* TODO does this really need a file all on its own? */
char SYMEXPORT *alpm_strerror(int err) const char SYMEXPORT *alpm_strerror(int err)
{ {
switch(err) { switch(err) {
/* System */ /* System */

View file

@ -71,7 +71,7 @@ int _alpm_grp_cmp(const void *g1, const void *g2)
return(strcmp(grp1->name, grp2->name)); return(strcmp(grp1->name, grp2->name));
} }
const char SYMEXPORT *alpm_grp_get_name(pmgrp_t *grp) const char SYMEXPORT *alpm_grp_get_name(const pmgrp_t *grp)
{ {
ALPM_LOG_FUNC; ALPM_LOG_FUNC;
@ -81,7 +81,7 @@ const char SYMEXPORT *alpm_grp_get_name(pmgrp_t *grp)
return grp->name; return grp->name;
} }
alpm_list_t SYMEXPORT *alpm_grp_get_pkgs(pmgrp_t *grp) const alpm_list_t SYMEXPORT *alpm_grp_get_pkgs(const pmgrp_t *grp)
{ {
ALPM_LOG_FUNC; ALPM_LOG_FUNC;

View file

@ -242,7 +242,7 @@ void SYMEXPORT alpm_option_set_usesyslog(unsigned short usesyslog)
handle->usesyslog = usesyslog; handle->usesyslog = usesyslog;
} }
void SYMEXPORT alpm_option_add_noupgrade(char *pkg) void SYMEXPORT alpm_option_add_noupgrade(const char *pkg)
{ {
handle->noupgrade = alpm_list_add(handle->noupgrade, strdup(pkg)); handle->noupgrade = alpm_list_add(handle->noupgrade, strdup(pkg));
} }
@ -253,17 +253,18 @@ void SYMEXPORT alpm_option_set_noupgrades(alpm_list_t *noupgrade)
if(noupgrade) handle->noupgrade = noupgrade; if(noupgrade) handle->noupgrade = noupgrade;
} }
void SYMEXPORT alpm_option_add_noextract(char *pkg) void SYMEXPORT alpm_option_add_noextract(const char *pkg)
{ {
handle->noextract = alpm_list_add(handle->noextract, strdup(pkg)); handle->noextract = alpm_list_add(handle->noextract, strdup(pkg));
} }
void SYMEXPORT alpm_option_set_noextracts(alpm_list_t *noextract) void SYMEXPORT alpm_option_set_noextracts(alpm_list_t *noextract)
{ {
if(handle->noextract) FREELIST(handle->noextract); if(handle->noextract) FREELIST(handle->noextract);
if(noextract) handle->noextract = noextract; if(noextract) handle->noextract = noextract;
} }
void SYMEXPORT alpm_option_add_ignorepkg(char *pkg) void SYMEXPORT alpm_option_add_ignorepkg(const char *pkg)
{ {
handle->ignorepkg = alpm_list_add(handle->ignorepkg, strdup(pkg)); handle->ignorepkg = alpm_list_add(handle->ignorepkg, strdup(pkg));
} }
@ -273,7 +274,7 @@ void alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs)
if(ignorepkgs) handle->ignorepkg = ignorepkgs; if(ignorepkgs) handle->ignorepkg = ignorepkgs;
} }
void SYMEXPORT alpm_option_add_holdpkg(char *pkg) void SYMEXPORT alpm_option_add_holdpkg(const char *pkg)
{ {
handle->holdpkg = alpm_list_add(handle->holdpkg, strdup(pkg)); handle->holdpkg = alpm_list_add(handle->holdpkg, strdup(pkg));
} }

View file

@ -61,7 +61,7 @@
* @param pkg address of the package pointer * @param pkg address of the package pointer
* @return 0 on success, -1 on error (pm_errno is set accordingly) * @return 0 on success, -1 on error (pm_errno is set accordingly)
*/ */
int SYMEXPORT alpm_pkg_load(char *filename, pmpkg_t **pkg) int SYMEXPORT alpm_pkg_load(const char *filename, pmpkg_t **pkg)
{ {
_alpm_log(PM_LOG_FUNCTION, "enter alpm_pkg_load"); _alpm_log(PM_LOG_FUNCTION, "enter alpm_pkg_load");
@ -210,7 +210,7 @@ static char *_supported_archs[] = {
* *
* @return pointer to start of -ARCH text if it exists, else NULL * @return pointer to start of -ARCH text if it exists, else NULL
*/ */
char SYMEXPORT *alpm_pkg_name_hasarch(char *pkgname) char SYMEXPORT *alpm_pkg_name_hasarch(const char *pkgname)
{ {
/* TODO remove this when we transfer everything over to -ARCH /* TODO remove this when we transfer everything over to -ARCH
* *
@ -732,7 +732,7 @@ int _alpm_pkg_splitname(const char *target, char *name, char *version, int witha
* used when we want to install or add a package */ * used when we want to install or add a package */
void _alpm_pkg_update_requiredby(pmpkg_t *pkg) void _alpm_pkg_update_requiredby(pmpkg_t *pkg)
{ {
alpm_list_t *i, *j; const alpm_list_t *i, *j;
pmdb_t *localdb = alpm_option_get_localdb(); pmdb_t *localdb = alpm_option_get_localdb();
for(i = _alpm_db_get_pkgcache(localdb); i; i = i->next) { for(i = _alpm_db_get_pkgcache(localdb); i; i = i->next) {

View file

@ -47,7 +47,7 @@
* @return the downloaded filename on success, NULL on error * @return the downloaded filename on success, NULL on error
* @addtogroup alpm_misc * @addtogroup alpm_misc
*/ */
char SYMEXPORT *alpm_fetch_pkgurl(char *url) char SYMEXPORT *alpm_fetch_pkgurl(const char *url)
{ {
ALPM_LOG_FUNC; ALPM_LOG_FUNC;
@ -420,7 +420,7 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
return(done ? 0 : -1); return(done ? 0 : -1);
} }
char *_alpm_fetch_pkgurl(char *target) char *_alpm_fetch_pkgurl(const char *target)
{ {
pmserver_t *server; pmserver_t *server;
char *filename; char *filename;

View file

@ -41,7 +41,7 @@ int _alpm_downloadfiles(alpm_list_t *servers, const char *localpath, alpm_list_t
int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
alpm_list_t *files, const char *mtime1, char *mtime2); alpm_list_t *files, const char *mtime1, char *mtime2);
char *_alpm_fetch_pkgurl(char *target); char *_alpm_fetch_pkgurl(const char *target);
#endif /* _ALPM_SERVER_H */ #endif /* _ALPM_SERVER_H */

View file

@ -367,8 +367,8 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
*/ */
static int syncpkg_cmp(const void *s1, const void *s2) static int syncpkg_cmp(const void *s1, const void *s2)
{ {
pmsyncpkg_t *sp1 = (pmsyncpkg_t *)s1; const pmsyncpkg_t *sp1 = s1;
pmsyncpkg_t *sp2 = (pmsyncpkg_t *)s2; const pmsyncpkg_t *sp2 = s2;
pmpkg_t *p1, *p2; pmpkg_t *p1, *p2;
p1 = alpm_sync_get_pkg(sp1); p1 = alpm_sync_get_pkg(sp1);
@ -1085,7 +1085,7 @@ pmsyncpkg_t *_alpm_sync_find(alpm_list_t *syncpkgs, const char* pkgname)
return(NULL); /* not found */ return(NULL); /* not found */
} }
pmsynctype_t SYMEXPORT alpm_sync_get_type(pmsyncpkg_t *sync) pmsynctype_t SYMEXPORT alpm_sync_get_type(const pmsyncpkg_t *sync)
{ {
/* Sanity checks */ /* Sanity checks */
ASSERT(sync != NULL, return(-1)); ASSERT(sync != NULL, return(-1));
@ -1093,7 +1093,7 @@ pmsynctype_t SYMEXPORT alpm_sync_get_type(pmsyncpkg_t *sync)
return sync->type; return sync->type;
} }
pmpkg_t SYMEXPORT *alpm_sync_get_pkg(pmsyncpkg_t *sync) pmpkg_t SYMEXPORT *alpm_sync_get_pkg(const pmsyncpkg_t *sync)
{ {
/* Sanity checks */ /* Sanity checks */
ASSERT(sync != NULL, return(NULL)); ASSERT(sync != NULL, return(NULL));
@ -1101,7 +1101,7 @@ pmpkg_t SYMEXPORT *alpm_sync_get_pkg(pmsyncpkg_t *sync)
return sync->pkg; return sync->pkg;
} }
void SYMEXPORT *alpm_sync_get_data(pmsyncpkg_t *sync) void SYMEXPORT *alpm_sync_get_data(const pmsyncpkg_t *sync)
{ {
/* Sanity checks */ /* Sanity checks */
ASSERT(sync != NULL, return(NULL)); ASSERT(sync != NULL, return(NULL));

View file

@ -182,7 +182,7 @@ static int query_group(alpm_list_t *targets)
if(targets == NULL) { if(targets == NULL) {
for(j = alpm_db_getgrpcache(db_local); j; j = alpm_list_next(j)) { for(j = alpm_db_getgrpcache(db_local); j; j = alpm_list_next(j)) {
pmgrp_t *grp = alpm_list_getdata(j); pmgrp_t *grp = alpm_list_getdata(j);
alpm_list_t *p, *pkgnames; const alpm_list_t *p, *pkgnames;
const char *grpname; const char *grpname;
grpname = alpm_grp_get_name(grp); grpname = alpm_grp_get_name(grp);
@ -197,7 +197,7 @@ static int query_group(alpm_list_t *targets)
package = alpm_list_getdata(i); package = alpm_list_getdata(i);
pmgrp_t *grp = alpm_db_readgrp(db_local, package); pmgrp_t *grp = alpm_db_readgrp(db_local, package);
if(grp) { if(grp) {
alpm_list_t *p, *pkgnames = alpm_grp_get_pkgs(grp); const alpm_list_t *p, *pkgnames = alpm_grp_get_pkgs(grp);
for(p = pkgnames; p; p = alpm_list_next(p)) { for(p = pkgnames; p; p = alpm_list_next(p)) {
printf("%s %s\n", package, (char *)alpm_list_getdata(p)); printf("%s %s\n", package, (char *)alpm_list_getdata(p));
} }

View file

@ -47,7 +47,7 @@ extern pmdb_t *db_local;
*/ */
int pacman_remove(alpm_list_t *targets) int pacman_remove(alpm_list_t *targets)
{ {
alpm_list_t *i, *j, *data = NULL, *finaltargs = NULL; alpm_list_t *i, *data = NULL, *finaltargs = NULL;
int retval = 0; int retval = 0;
if(targets == NULL) { if(targets == NULL) {
@ -61,14 +61,14 @@ int pacman_remove(alpm_list_t *targets)
pmgrp_t *grp = alpm_db_readgrp(db_local, alpm_list_getdata(i)); pmgrp_t *grp = alpm_db_readgrp(db_local, alpm_list_getdata(i));
if(grp) { if(grp) {
int all; int all;
alpm_list_t *pkgnames = alpm_grp_get_pkgs(grp); const alpm_list_t *p, *pkgnames = alpm_grp_get_pkgs(grp);
printf(_(":: group %s:\n"), alpm_grp_get_name(grp)); printf(_(":: group %s:\n"), alpm_grp_get_name(grp));
list_display(" ", pkgnames); list_display(" ", pkgnames);
all = yesno(_(" Remove whole content? [Y/n] ")); all = yesno(_(" Remove whole content? [Y/n] "));
for(j = pkgnames; j; j = alpm_list_next(j)) { for(p = pkgnames; p; p = alpm_list_next(p)) {
char *pkg = alpm_list_getdata(j); char *pkg = alpm_list_getdata(p);
if(all || yesno(_(":: Remove %s from group %s? [Y/n] "), pkg, (char *)alpm_list_getdata(i))) { if(all || yesno(_(":: Remove %s from group %s? [Y/n] "), pkg, (char *)alpm_list_getdata(i))) {
finaltargs = alpm_list_add(finaltargs, strdup(pkg)); finaltargs = alpm_list_add(finaltargs, strdup(pkg));
} }

View file

@ -572,7 +572,8 @@ int pacman_sync(alpm_list_t *targets)
found++; found++;
printf(_(":: group %s:\n"), targ); printf(_(":: group %s:\n"), targ);
/* remove dupe entries in case a package exists in multiple repos */ /* remove dupe entries in case a package exists in multiple repos */
alpm_list_t *pkgs = alpm_list_remove_dupes(alpm_grp_get_pkgs(grp)); const alpm_list_t *grppkgs = alpm_grp_get_pkgs(grp);
alpm_list_t *pkgs = alpm_list_remove_dupes(grppkgs);
list_display(" ", pkgs); list_display(" ", pkgs);
if(yesno(_(":: Install whole content? [Y/n] "))) { if(yesno(_(":: Install whole content? [Y/n] "))) {
for(k = pkgs; k; k = alpm_list_next(k)) { for(k = pkgs; k; k = alpm_list_next(k)) {

View file

@ -280,9 +280,9 @@ char *strreplace(const char *str, const char *needle, const char *replace)
return newstr; return newstr;
} }
void list_display(const char *title, alpm_list_t *list) void list_display(const char *title, const alpm_list_t *list)
{ {
alpm_list_t *i; const alpm_list_t *i;
int cols, len; int cols, len;
len = strlen(title); len = strlen(title);
@ -315,10 +315,10 @@ void list_display(const char *title, alpm_list_t *list)
* retrieved from a transaction object * retrieved from a transaction object
*/ */
/* TODO move to output.c? or just combine util and output */ /* TODO move to output.c? or just combine util and output */
void display_targets(alpm_list_t *syncpkgs) void display_targets(const alpm_list_t *syncpkgs)
{ {
char *str; char *str;
alpm_list_t *i, *j; const alpm_list_t *i, *j;
alpm_list_t *targets = NULL, *to_remove = NULL; alpm_list_t *targets = NULL, *to_remove = NULL;
/* TODO these are some messy variable names */ /* TODO these are some messy variable names */
unsigned long size = 0, isize = 0, rsize = 0, dispsize = 0; unsigned long size = 0, isize = 0, rsize = 0, dispsize = 0;

View file

@ -44,8 +44,8 @@ void indentprint(const char *str, int indent);
char *strtoupper(char *str); char *strtoupper(char *str);
char *strtrim(char *str); char *strtrim(char *str);
char *strreplace(const char *str, const char *needle, const char *replace); char *strreplace(const char *str, const char *needle, const char *replace);
void list_display(const char *title, alpm_list_t *list); void list_display(const char *title, const alpm_list_t *list);
void display_targets(alpm_list_t *syncpkgs); void display_targets(const alpm_list_t *syncpkgs);
int yesno(char *fmt, ...); int yesno(char *fmt, ...);
#endif /* _PM_UTIL_H */ #endif /* _PM_UTIL_H */