summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-06-05 17:34:33 -0400
committerDan McGee <dan@archlinux.org>2007-06-05 17:34:33 -0400
commitf7912e9dc6be71b177d546da0f8d005e7b4af9e8 (patch)
tree14f9c7be0757de98d2325b3623eac2a45a438a16 /src
parent4906b76c85bc93c4a86dfa8449d58b55ede30425 (diff)
downloadpacman-f7912e9dc6be71b177d546da0f8d005e7b4af9e8.tar.xz
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>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/query.c4
-rw-r--r--src/pacman/remove.c8
-rw-r--r--src/pacman/sync.c3
-rw-r--r--src/pacman/util.c8
-rw-r--r--src/pacman/util.h4
5 files changed, 14 insertions, 13 deletions
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 3e993bf0..3863572f 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -182,7 +182,7 @@ static int query_group(alpm_list_t *targets)
if(targets == NULL) {
for(j = alpm_db_getgrpcache(db_local); j; j = alpm_list_next(j)) {
pmgrp_t *grp = alpm_list_getdata(j);
- alpm_list_t *p, *pkgnames;
+ const alpm_list_t *p, *pkgnames;
const char *grpname;
grpname = alpm_grp_get_name(grp);
@@ -197,7 +197,7 @@ static int query_group(alpm_list_t *targets)
package = alpm_list_getdata(i);
pmgrp_t *grp = alpm_db_readgrp(db_local, package);
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)) {
printf("%s %s\n", package, (char *)alpm_list_getdata(p));
}
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index c76fc69a..9b4adce0 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -47,7 +47,7 @@ extern pmdb_t *db_local;
*/
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;
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));
if(grp) {
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));
list_display(" ", pkgnames);
all = yesno(_(" Remove whole content? [Y/n] "));
- for(j = pkgnames; j; j = alpm_list_next(j)) {
- char *pkg = alpm_list_getdata(j);
+ for(p = pkgnames; p; p = alpm_list_next(p)) {
+ char *pkg = alpm_list_getdata(p);
if(all || yesno(_(":: Remove %s from group %s? [Y/n] "), pkg, (char *)alpm_list_getdata(i))) {
finaltargs = alpm_list_add(finaltargs, strdup(pkg));
}
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 92a1607a..fa99797c 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -572,7 +572,8 @@ int pacman_sync(alpm_list_t *targets)
found++;
printf(_(":: group %s:\n"), targ);
/* 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);
if(yesno(_(":: Install whole content? [Y/n] "))) {
for(k = pkgs; k; k = alpm_list_next(k)) {
diff --git a/src/pacman/util.c b/src/pacman/util.c
index e88001ac..eda32524 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -280,9 +280,9 @@ char *strreplace(const char *str, const char *needle, const char *replace)
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;
len = strlen(title);
@@ -315,10 +315,10 @@ void list_display(const char *title, alpm_list_t *list)
* retrieved from a transaction object
*/
/* 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;
- alpm_list_t *i, *j;
+ const alpm_list_t *i, *j;
alpm_list_t *targets = NULL, *to_remove = NULL;
/* TODO these are some messy variable names */
unsigned long size = 0, isize = 0, rsize = 0, dispsize = 0;
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 80d1b02c..065f9531 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -44,8 +44,8 @@ void indentprint(const char *str, int indent);
char *strtoupper(char *str);
char *strtrim(char *str);
char *strreplace(const char *str, const char *needle, const char *replace);
-void list_display(const char *title, alpm_list_t *list);
-void display_targets(alpm_list_t *syncpkgs);
+void list_display(const char *title, const alpm_list_t *list);
+void display_targets(const alpm_list_t *syncpkgs);
int yesno(char *fmt, ...);
#endif /* _PM_UTIL_H */