summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefano Esposito <stefano.esposito87@gmail.com>2007-09-08 18:41:45 +0200
committerDan McGee <dan@archlinux.org>2007-09-11 20:58:27 -0500
commit27acdc2c94de558103eb29260c179a49c9b05c14 (patch)
tree969d73111d6a1943975fae23ac5ba5747bb6e0d2
parentf21c45c0ddf195a4dcfca08c19bfa23d1c7fb326 (diff)
downloadpacman-27acdc2c94de558103eb29260c179a49c9b05c14.tar.xz
make alpm_strerror binding friendly
I'm currently working on python bindings for alpm written in pyrex. While working i found that declaring alpm_strerror as char * alpm_strerror (void) instead of char * alpm_strerror (int err) and then using pm_errno in the implementation instead of err, could make it more bindings-friendly. Dan: cleaned up and added void to declaration. Instead of replacing existing function, add a new function called 'alpm_strerrorlast(void)'. Signed-off-by: Stefano Esposito <stefano.esposito87@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--lib/libalpm/alpm.h1
-rw-r--r--lib/libalpm/error.c5
-rw-r--r--lib/libalpm/error.h2
-rw-r--r--src/pacman/add.c10
-rw-r--r--src/pacman/pacman.c20
-rw-r--r--src/pacman/remove.c10
-rw-r--r--src/pacman/sync.c20
-rw-r--r--src/util/testpkg.c4
8 files changed, 39 insertions, 33 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 75c30987..1506e3d5 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -461,6 +461,7 @@ enum _pmerrno_t {
extern enum _pmerrno_t pm_errno;
const char *alpm_strerror(int err);
+const char *alpm_strerrorlast(void);
#ifdef __cplusplus
}
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index b5e301aa..f81d22da 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -30,6 +30,11 @@
#include "alpm.h"
/* TODO does this really need a file all on its own? */
+const char SYMEXPORT *alpm_strerrorlast(void)
+{
+ return alpm_strerror(pm_errno);
+}
+
const char SYMEXPORT *alpm_strerror(int err)
{
switch(err) {
diff --git a/lib/libalpm/error.h b/lib/libalpm/error.h
index e21a5f60..8e9e7c80 100644
--- a/lib/libalpm/error.h
+++ b/lib/libalpm/error.h
@@ -22,7 +22,7 @@
#define _ALPM_ERROR_H
#define RET_ERR(err, ret) do { pm_errno = (err); \
- _alpm_log(PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerror(err)); \
+ _alpm_log(PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerrorlast()); \
return(ret); } while(0)
#endif /* _ALPM_ERROR_H */
diff --git a/src/pacman/add.c b/src/pacman/add.c
index 67633e9c..0b59a236 100644
--- a/src/pacman/add.c
+++ b/src/pacman/add.c
@@ -42,7 +42,7 @@ static int add_cleanup(void)
int ret = alpm_trans_release();
if(ret != 0) {
pm_printf(PM_LOG_ERROR, _("failed to release transaction (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
ret = 1;
}
@@ -105,7 +105,7 @@ int pacman_add(alpm_list_t *targets)
if(alpm_trans_init(transtype, config->flags, cb_trans_evt,
cb_trans_conv, cb_trans_progress) == -1) {
/* TODO: error messages should be in the front end, not the back */
- fprintf(stderr, _("error: %s\n"), alpm_strerror(pm_errno));
+ fprintf(stderr, _("error: %s\n"), alpm_strerrorlast());
if(pm_errno == PM_ERR_HANDLE_LOCK) {
/* TODO this and the 2 other places should probably be on stderr */
printf(_(" if you're sure a package manager is not already\n"
@@ -120,7 +120,7 @@ int pacman_add(alpm_list_t *targets)
char *targ = alpm_list_getdata(i);
if(alpm_trans_addtarget(targ) == -1) {
fprintf(stderr, _("error: failed to add target '%s' (%s)"), targ,
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
add_cleanup();
return(1);
}
@@ -131,7 +131,7 @@ int pacman_add(alpm_list_t *targets)
/* TODO: No, compute nothing. This is stupid. */
if(alpm_trans_prepare(&data) == -1) {
fprintf(stderr, _("error: failed to prepare transaction (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
switch(pm_errno) {
case PM_ERR_UNSATISFIED_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
@@ -197,7 +197,7 @@ int pacman_add(alpm_list_t *targets)
/* Step 3: perform the installation */
if(alpm_trans_commit(NULL) == -1) {
- fprintf(stderr, _("error: failed to commit transaction (%s)\n"), alpm_strerror(pm_errno));
+ fprintf(stderr, _("error: failed to commit transaction (%s)\n"), alpm_strerrorlast());
add_cleanup();
return(1);
}
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index f62e588b..138389fa 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -215,7 +215,7 @@ static void cleanup(int signum)
/* free alpm library resources */
if(alpm_release() == -1) {
- pm_printf(PM_LOG_ERROR, alpm_strerror(pm_errno));
+ pm_printf(PM_LOG_ERROR, alpm_strerrorlast());
}
/* free memory */
@@ -331,7 +331,7 @@ static int parseargs(int argc, char *argv[])
case 1007:
if(alpm_option_add_cachedir(optarg) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
- optarg, alpm_strerror(pm_errno));
+ optarg, alpm_strerrorlast());
return(1);
}
break;
@@ -355,7 +355,7 @@ static int parseargs(int argc, char *argv[])
case 'b':
if(alpm_option_set_dbpath(optarg) != 0) {
pm_printf(PM_LOG_ERROR, _("problem setting dbpath '%s' (%s)\n"),
- optarg, alpm_strerror(pm_errno));
+ optarg, alpm_strerrorlast());
return(1);
}
config->have_dbpath = 1;
@@ -389,7 +389,7 @@ static int parseargs(int argc, char *argv[])
case 'r':
if(alpm_option_set_root(optarg) != 0) {
pm_printf(PM_LOG_ERROR, _("problem setting root '%s' (%s)\n"),
- optarg, alpm_strerror(pm_errno));
+ optarg, alpm_strerrorlast());
return(1);
}
config->have_root = 1;
@@ -614,7 +614,7 @@ static int _parseconfig(const char *file, const char *givensection,
if(!config->have_dbpath) {
if(alpm_option_set_dbpath(ptr) != 0) {
pm_printf(PM_LOG_ERROR, _("problem setting dbpath '%s' (%s)\n"),
- ptr, alpm_strerror(pm_errno));
+ ptr, alpm_strerrorlast());
return(1);
}
pm_printf(PM_LOG_DEBUG, "config: dbpath: %s\n", ptr);
@@ -622,7 +622,7 @@ static int _parseconfig(const char *file, const char *givensection,
} else if(strcmp(key, "CacheDir") == 0 || strcmp(upperkey, "CACHEDIR") == 0) {
if(alpm_option_add_cachedir(ptr) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
- ptr, alpm_strerror(pm_errno));
+ ptr, alpm_strerrorlast());
return(1);
}
pm_printf(PM_LOG_DEBUG, "config: cachedir: %s\n", ptr);
@@ -631,7 +631,7 @@ static int _parseconfig(const char *file, const char *givensection,
if(!config->have_root) {
if(alpm_option_set_root(ptr) != 0) {
pm_printf(PM_LOG_ERROR, _("problem setting root '%s' (%s)\n"),
- ptr, alpm_strerror(pm_errno));
+ ptr, alpm_strerrorlast());
return(1);
}
pm_printf(PM_LOG_DEBUG, "config: rootdir: %s\n", ptr);
@@ -640,7 +640,7 @@ static int _parseconfig(const char *file, const char *givensection,
if(!config->have_logfile) {
if(alpm_option_set_logfile(ptr) != 0) {
pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"),
- ptr, alpm_strerror(pm_errno));
+ ptr, alpm_strerrorlast());
return(1);
}
pm_printf(PM_LOG_DEBUG, "config: logfile: %s\n", ptr);
@@ -736,7 +736,7 @@ int main(int argc, char *argv[])
/* initialize library */
if(alpm_initialize() == -1) {
pm_printf(PM_LOG_ERROR, _("failed to initialize alpm library (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
cleanup(EXIT_FAILURE);
}
@@ -812,7 +812,7 @@ int main(int argc, char *argv[])
db_local = alpm_db_register_local();
if(db_local == NULL) {
pm_printf(PM_LOG_ERROR, _("could not register 'local' database (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
cleanup(EXIT_FAILURE);
}
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index e60d3e8c..860bf491 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -44,7 +44,7 @@ static int remove_cleanup(void)
int ret = alpm_trans_release();
if(ret != 0) {
pm_printf(PM_LOG_ERROR, _("failed to release transaction (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
ret = 1;
}
@@ -97,7 +97,7 @@ int pacman_remove(alpm_list_t *targets)
if(alpm_trans_init(PM_TRANS_TYPE_REMOVE, config->flags,
cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) {
fprintf(stderr, _("error: failed to init transaction (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
if(pm_errno == PM_ERR_HANDLE_LOCK) {
printf(_(" if you're sure a package manager is not already\n"
" running, you can remove %s.\n"), alpm_option_get_lockfile());
@@ -113,7 +113,7 @@ int pacman_remove(alpm_list_t *targets)
if(alpm_trans_addtarget(targ) == -1) {
printf("failed.\n");
fprintf(stderr, _("error: failed to add target '%s' (%s)\n"), targ,
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
remove_cleanup();
FREELIST(finaltargs);
return(1);
@@ -123,7 +123,7 @@ int pacman_remove(alpm_list_t *targets)
/* Step 2: prepare the transaction based on its type, targets and flags */
if(alpm_trans_prepare(&data) == -1) {
fprintf(stderr, _("error: failed to prepare transaction (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
switch(pm_errno) {
case PM_ERR_UNSATISFIED_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
@@ -167,7 +167,7 @@ int pacman_remove(alpm_list_t *targets)
/* Step 3: actually perform the removal */
if(alpm_trans_commit(NULL) == -1) {
fprintf(stderr, _("error: failed to commit transaction (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
remove_cleanup();
FREELIST(finaltargs);
return(1);
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 53ec41e9..3e599830 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -205,7 +205,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
alpm_db_get_name(db), downloadLastErrString);
} else {
fprintf(stderr, _("error: failed to update %s (%s)\n"),
- alpm_db_get_name(db), alpm_strerror(pm_errno));
+ alpm_db_get_name(db), alpm_strerrorlast());
}
} else if(ret == 1) {
printf(_(" %s is up to date\n"), alpm_db_get_name(db));
@@ -498,7 +498,7 @@ int pacman_sync(alpm_list_t *targets)
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt,
cb_trans_conv, cb_trans_progress) == -1) {
fprintf(stderr, _("error: failed to init transaction (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
if(pm_errno == PM_ERR_HANDLE_LOCK) {
printf(_(" if you're sure a package manager is not already\n"
" running, you can remove %s.\n"), alpm_option_get_lockfile());
@@ -522,7 +522,7 @@ int pacman_sync(alpm_list_t *targets)
printf(_(":: Starting full system upgrade...\n"));
alpm_logaction("starting full system upgrade");
if(alpm_trans_sysupgrade() == -1) {
- fprintf(stderr, _("error: %s\n"), alpm_strerror(pm_errno));
+ fprintf(stderr, _("error: %s\n"), alpm_strerrorlast());
retval = 1;
goto cleanup;
}
@@ -548,18 +548,18 @@ int pacman_sync(alpm_list_t *targets)
if(yesno(_(":: Cancel current operation? [Y/n] "))) {
if(alpm_trans_release() == -1) {
fprintf(stderr, _("error: failed to release transaction (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
retval = 1;
goto cleanup;
}
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags,
cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) {
fprintf(stderr, _("error: failed to init transaction (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
return(1);
}
if(alpm_trans_addtarget("pacman") == -1) {
- fprintf(stderr, _("error: pacman: %s\n"), alpm_strerror(pm_errno));
+ fprintf(stderr, _("error: pacman: %s\n"), alpm_strerrorlast());
retval = 1;
goto cleanup;
}
@@ -584,7 +584,7 @@ int pacman_sync(alpm_list_t *targets)
}
if(pm_errno != PM_ERR_PKG_NOT_FOUND) {
fprintf(stderr, _("'error: %s': %s\n"),
- (char *)i->data, alpm_strerror(pm_errno));
+ (char *)i->data, alpm_strerrorlast());
retval = 1;
goto cleanup;
}
@@ -646,7 +646,7 @@ int pacman_sync(alpm_list_t *targets)
alpm_list_t *data;
if(alpm_trans_prepare(&data) == -1) {
fprintf(stderr, _("error: failed to prepare transaction (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
switch(pm_errno) {
alpm_list_t *i;
case PM_ERR_UNSATISFIED_DEPS:
@@ -722,7 +722,7 @@ int pacman_sync(alpm_list_t *targets)
/* Step 3: actually perform the installation */
if(alpm_trans_commit(&data) == -1) {
fprintf(stderr, _("error: failed to commit transaction (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
switch(pm_errno) {
alpm_list_t *i;
case PM_ERR_FILE_CONFLICTS:
@@ -764,7 +764,7 @@ cleanup:
}
if(alpm_trans_release() == -1) {
fprintf(stderr, _("error: failed to release transaction (%s)\n"),
- alpm_strerror(pm_errno));
+ alpm_strerrorlast());
retval = 1;
}
diff --git a/src/util/testpkg.c b/src/util/testpkg.c
index 71993bdc..7da18ca6 100644
--- a/src/util/testpkg.c
+++ b/src/util/testpkg.c
@@ -50,7 +50,7 @@ int main(int argc, char **argv)
}
if(alpm_initialize() == -1) {
- fprintf(stderr, "cannot initilize alpm: %s\n", alpm_strerror(pm_errno));
+ fprintf(stderr, "cannot initilize alpm: %s\n", alpm_strerrorlast());
return(1);
}
@@ -65,7 +65,7 @@ int main(int argc, char **argv)
}
if(alpm_release() == -1) {
- fprintf(stderr, "error releasing alpm: %s\n", alpm_strerror(pm_errno));
+ fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
}
return(retval);