1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-23 00:08:50 -05:00

libalpm: consistently use int as return type for option setters

Currently the only error case then when handle == NULL.
However several handle functions return -1 on this error,
and a uniform API makes things simpler.

Signed-off-by: Rémy Oudompheng <remy@archlinux.org>
This commit is contained in:
Rémy Oudompheng 2011-04-10 00:04:54 +02:00 committed by Dan McGee
parent dff2d916ba
commit 4ffda3f05b
3 changed files with 76 additions and 68 deletions

View File

@ -99,16 +99,16 @@ typedef int (*alpm_cb_fetch)(const char *url, const char *localpath,
*/ */
alpm_cb_log alpm_option_get_logcb(void); alpm_cb_log alpm_option_get_logcb(void);
void alpm_option_set_logcb(alpm_cb_log cb); int alpm_option_set_logcb(alpm_cb_log cb);
alpm_cb_download alpm_option_get_dlcb(void); alpm_cb_download alpm_option_get_dlcb(void);
void alpm_option_set_dlcb(alpm_cb_download cb); int alpm_option_set_dlcb(alpm_cb_download cb);
alpm_cb_fetch alpm_option_get_fetchcb(void); alpm_cb_fetch alpm_option_get_fetchcb(void);
void alpm_option_set_fetchcb(alpm_cb_fetch cb); int alpm_option_set_fetchcb(alpm_cb_fetch cb);
alpm_cb_totaldl alpm_option_get_totaldlcb(void); alpm_cb_totaldl alpm_option_get_totaldlcb(void);
void alpm_option_set_totaldlcb(alpm_cb_totaldl cb); int alpm_option_set_totaldlcb(alpm_cb_totaldl cb);
const char *alpm_option_get_root(void); const char *alpm_option_get_root(void);
int alpm_option_set_root(const char *root); int alpm_option_set_root(const char *root);
@ -118,7 +118,7 @@ int alpm_option_set_dbpath(const char *dbpath);
alpm_list_t *alpm_option_get_cachedirs(void); alpm_list_t *alpm_option_get_cachedirs(void);
int alpm_option_add_cachedir(const char *cachedir); int alpm_option_add_cachedir(const char *cachedir);
void alpm_option_set_cachedirs(alpm_list_t *cachedirs); int alpm_option_set_cachedirs(alpm_list_t *cachedirs);
int alpm_option_remove_cachedir(const char *cachedir); int alpm_option_remove_cachedir(const char *cachedir);
const char *alpm_option_get_logfile(void); const char *alpm_option_get_logfile(void);
@ -131,36 +131,36 @@ const char *alpm_option_get_signaturedir(void);
int alpm_option_set_signaturedir(const char *signaturedir); int alpm_option_set_signaturedir(const char *signaturedir);
int alpm_option_get_usesyslog(void); int alpm_option_get_usesyslog(void);
void alpm_option_set_usesyslog(int usesyslog); int alpm_option_set_usesyslog(int usesyslog);
alpm_list_t *alpm_option_get_noupgrades(void); alpm_list_t *alpm_option_get_noupgrades(void);
void alpm_option_add_noupgrade(const char *pkg); int alpm_option_add_noupgrade(const char *pkg);
void alpm_option_set_noupgrades(alpm_list_t *noupgrade); int alpm_option_set_noupgrades(alpm_list_t *noupgrade);
int alpm_option_remove_noupgrade(const char *pkg); int alpm_option_remove_noupgrade(const char *pkg);
alpm_list_t *alpm_option_get_noextracts(void); alpm_list_t *alpm_option_get_noextracts(void);
void alpm_option_add_noextract(const char *pkg); int alpm_option_add_noextract(const char *pkg);
void alpm_option_set_noextracts(alpm_list_t *noextract); int alpm_option_set_noextracts(alpm_list_t *noextract);
int alpm_option_remove_noextract(const char *pkg); int alpm_option_remove_noextract(const char *pkg);
alpm_list_t *alpm_option_get_ignorepkgs(void); alpm_list_t *alpm_option_get_ignorepkgs(void);
void alpm_option_add_ignorepkg(const char *pkg); int alpm_option_add_ignorepkg(const char *pkg);
void alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs); int alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs);
int alpm_option_remove_ignorepkg(const char *pkg); int alpm_option_remove_ignorepkg(const char *pkg);
alpm_list_t *alpm_option_get_ignoregrps(void); alpm_list_t *alpm_option_get_ignoregrps(void);
void alpm_option_add_ignoregrp(const char *grp); int alpm_option_add_ignoregrp(const char *grp);
void alpm_option_set_ignoregrps(alpm_list_t *ignoregrps); int alpm_option_set_ignoregrps(alpm_list_t *ignoregrps);
int alpm_option_remove_ignoregrp(const char *grp); int alpm_option_remove_ignoregrp(const char *grp);
const char *alpm_option_get_arch(void); const char *alpm_option_get_arch(void);
void alpm_option_set_arch(const char *arch); int alpm_option_set_arch(const char *arch);
int alpm_option_get_usedelta(void); int alpm_option_get_usedelta(void);
void alpm_option_set_usedelta(int usedelta); int alpm_option_set_usedelta(int usedelta);
int alpm_option_get_checkspace(void); int alpm_option_get_checkspace(void);
void alpm_option_set_checkspace(int checkspace); int alpm_option_set_checkspace(int checkspace);
pmdb_t *alpm_option_get_localdb(void); pmdb_t *alpm_option_get_localdb(void);
alpm_list_t *alpm_option_get_syncdbs(void); alpm_list_t *alpm_option_get_syncdbs(void);

View File

@ -274,40 +274,32 @@ alpm_list_t SYMEXPORT *alpm_option_get_syncdbs()
return handle->dbs_sync; return handle->dbs_sync;
} }
void SYMEXPORT alpm_option_set_logcb(alpm_cb_log cb) int SYMEXPORT alpm_option_set_logcb(alpm_cb_log cb)
{ {
if (handle == NULL) { ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
pm_errno = PM_ERR_HANDLE_NULL;
return;
}
handle->logcb = cb; handle->logcb = cb;
return 0;
} }
void SYMEXPORT alpm_option_set_dlcb(alpm_cb_download cb) int SYMEXPORT alpm_option_set_dlcb(alpm_cb_download cb)
{ {
if (handle == NULL) { ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
pm_errno = PM_ERR_HANDLE_NULL;
return;
}
handle->dlcb = cb; handle->dlcb = cb;
return 0;
} }
void SYMEXPORT alpm_option_set_fetchcb(alpm_cb_fetch cb) int SYMEXPORT alpm_option_set_fetchcb(alpm_cb_fetch cb)
{ {
if (handle == NULL) { ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
pm_errno = PM_ERR_HANDLE_NULL;
return;
}
handle->fetchcb = cb; handle->fetchcb = cb;
return 0;
} }
void SYMEXPORT alpm_option_set_totaldlcb(alpm_cb_totaldl cb) int SYMEXPORT alpm_option_set_totaldlcb(alpm_cb_totaldl cb)
{ {
if (handle == NULL) { ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
pm_errno = PM_ERR_HANDLE_NULL;
return;
}
handle->totaldlcb = cb; handle->totaldlcb = cb;
return 0;
} }
int SYMEXPORT alpm_option_set_root(const char *root) int SYMEXPORT alpm_option_set_root(const char *root)
@ -420,11 +412,12 @@ int SYMEXPORT alpm_option_add_cachedir(const char *cachedir)
return 0; return 0;
} }
void SYMEXPORT alpm_option_set_cachedirs(alpm_list_t *cachedirs) int SYMEXPORT alpm_option_set_cachedirs(alpm_list_t *cachedirs)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
if(handle->cachedirs) FREELIST(handle->cachedirs); if(handle->cachedirs) FREELIST(handle->cachedirs);
if(cachedirs) handle->cachedirs = cachedirs; if(cachedirs) handle->cachedirs = cachedirs;
return 0;
} }
int SYMEXPORT alpm_option_remove_cachedir(const char *cachedir) int SYMEXPORT alpm_option_remove_cachedir(const char *cachedir)
@ -495,23 +488,26 @@ int SYMEXPORT alpm_option_set_signaturedir(const char *signaturedir)
return 0; return 0;
} }
void SYMEXPORT alpm_option_set_usesyslog(int usesyslog) int SYMEXPORT alpm_option_set_usesyslog(int usesyslog)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
handle->usesyslog = usesyslog; handle->usesyslog = usesyslog;
return 0;
} }
void SYMEXPORT alpm_option_add_noupgrade(const char *pkg) int SYMEXPORT alpm_option_add_noupgrade(const char *pkg)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
handle->noupgrade = alpm_list_add(handle->noupgrade, strdup(pkg)); handle->noupgrade = alpm_list_add(handle->noupgrade, strdup(pkg));
return 0;
} }
void SYMEXPORT alpm_option_set_noupgrades(alpm_list_t *noupgrade) int SYMEXPORT alpm_option_set_noupgrades(alpm_list_t *noupgrade)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
if(handle->noupgrade) FREELIST(handle->noupgrade); if(handle->noupgrade) FREELIST(handle->noupgrade);
if(noupgrade) handle->noupgrade = noupgrade; if(noupgrade) handle->noupgrade = noupgrade;
return 0;
} }
int SYMEXPORT alpm_option_remove_noupgrade(const char *pkg) int SYMEXPORT alpm_option_remove_noupgrade(const char *pkg)
@ -526,17 +522,19 @@ int SYMEXPORT alpm_option_remove_noupgrade(const char *pkg)
return 0; return 0;
} }
void SYMEXPORT alpm_option_add_noextract(const char *pkg) int SYMEXPORT alpm_option_add_noextract(const char *pkg)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
handle->noextract = alpm_list_add(handle->noextract, strdup(pkg)); handle->noextract = alpm_list_add(handle->noextract, strdup(pkg));
return 0;
} }
void SYMEXPORT alpm_option_set_noextracts(alpm_list_t *noextract) int SYMEXPORT alpm_option_set_noextracts(alpm_list_t *noextract)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
if(handle->noextract) FREELIST(handle->noextract); if(handle->noextract) FREELIST(handle->noextract);
if(noextract) handle->noextract = noextract; if(noextract) handle->noextract = noextract;
return 0;
} }
int SYMEXPORT alpm_option_remove_noextract(const char *pkg) int SYMEXPORT alpm_option_remove_noextract(const char *pkg)
@ -551,17 +549,19 @@ int SYMEXPORT alpm_option_remove_noextract(const char *pkg)
return 0; return 0;
} }
void SYMEXPORT alpm_option_add_ignorepkg(const char *pkg) int SYMEXPORT alpm_option_add_ignorepkg(const char *pkg)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
handle->ignorepkg = alpm_list_add(handle->ignorepkg, strdup(pkg)); handle->ignorepkg = alpm_list_add(handle->ignorepkg, strdup(pkg));
return 0;
} }
void SYMEXPORT alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs) int SYMEXPORT alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
if(handle->ignorepkg) FREELIST(handle->ignorepkg); if(handle->ignorepkg) FREELIST(handle->ignorepkg);
if(ignorepkgs) handle->ignorepkg = ignorepkgs; if(ignorepkgs) handle->ignorepkg = ignorepkgs;
return 0;
} }
int SYMEXPORT alpm_option_remove_ignorepkg(const char *pkg) int SYMEXPORT alpm_option_remove_ignorepkg(const char *pkg)
@ -576,17 +576,19 @@ int SYMEXPORT alpm_option_remove_ignorepkg(const char *pkg)
return 0; return 0;
} }
void SYMEXPORT alpm_option_add_ignoregrp(const char *grp) int SYMEXPORT alpm_option_add_ignoregrp(const char *grp)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
handle->ignoregrp = alpm_list_add(handle->ignoregrp, strdup(grp)); handle->ignoregrp = alpm_list_add(handle->ignoregrp, strdup(grp));
return 0;
} }
void SYMEXPORT alpm_option_set_ignoregrps(alpm_list_t *ignoregrps) int SYMEXPORT alpm_option_set_ignoregrps(alpm_list_t *ignoregrps)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
if(handle->ignoregrp) FREELIST(handle->ignoregrp); if(handle->ignoregrp) FREELIST(handle->ignoregrp);
if(ignoregrps) handle->ignoregrp = ignoregrps; if(ignoregrps) handle->ignoregrp = ignoregrps;
return 0;
} }
int SYMEXPORT alpm_option_remove_ignoregrp(const char *grp) int SYMEXPORT alpm_option_remove_ignoregrp(const char *grp)
@ -601,23 +603,26 @@ int SYMEXPORT alpm_option_remove_ignoregrp(const char *grp)
return 0; return 0;
} }
void SYMEXPORT alpm_option_set_arch(const char *arch) int SYMEXPORT alpm_option_set_arch(const char *arch)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
if(handle->arch) FREE(handle->arch); if(handle->arch) FREE(handle->arch);
if(arch) handle->arch = strdup(arch); if(arch) handle->arch = strdup(arch);
return 0;
} }
void SYMEXPORT alpm_option_set_usedelta(int usedelta) int SYMEXPORT alpm_option_set_usedelta(int usedelta)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
handle->usedelta = usedelta; handle->usedelta = usedelta;
return 0;
} }
void SYMEXPORT alpm_option_set_checkspace(int checkspace) int SYMEXPORT alpm_option_set_checkspace(int checkspace)
{ {
ASSERT(handle != NULL, RET_ERR_VOID(PM_ERR_HANDLE_NULL)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
handle->checkspace = checkspace; handle->checkspace = checkspace;
return 0;
} }
/* vim: set ts=2 sw=2 noet: */ /* vim: set ts=2 sw=2 noet: */

View File

@ -412,7 +412,7 @@ static void setlibpaths(void)
#define check_optarg() if(!optarg) { return 1; } #define check_optarg() if(!optarg) { return 1; }
typedef void (*fn_add) (const char *s); typedef int (*fn_add) (const char *s);
static int parsearg_util_addlist(fn_add fn) static int parsearg_util_addlist(fn_add fn)
{ {
@ -810,17 +810,19 @@ static int parseargs(int argc, char *argv[])
} }
/* helper for being used with setrepeatingoption */ /* helper for being used with setrepeatingoption */
static void option_add_holdpkg(const char *name) { static int option_add_holdpkg(const char *name) {
config->holdpkg = alpm_list_add(config->holdpkg, strdup(name)); config->holdpkg = alpm_list_add(config->holdpkg, strdup(name));
return 0;
} }
/* helper for being used with setrepeatingoption */ /* helper for being used with setrepeatingoption */
static void option_add_syncfirst(const char *name) { static int option_add_syncfirst(const char *name) {
config->syncfirst = alpm_list_add(config->syncfirst, strdup(name)); config->syncfirst = alpm_list_add(config->syncfirst, strdup(name));
return 0;
} }
/* helper for being used with setrepeatingoption */ /* helper for being used with setrepeatingoption */
static void option_add_cleanmethod(const char *value) { static int option_add_cleanmethod(const char *value) {
if (strcmp(value, "KeepInstalled") == 0) { if (strcmp(value, "KeepInstalled") == 0) {
config->cleanmethod |= PM_CLEAN_KEEPINST; config->cleanmethod |= PM_CLEAN_KEEPINST;
} else if (strcmp(value, "KeepCurrent") == 0) { } else if (strcmp(value, "KeepCurrent") == 0) {
@ -829,6 +831,7 @@ static void option_add_cleanmethod(const char *value) {
pm_printf(PM_LOG_ERROR, _("invalid value for 'CleanMethod' : '%s'\n"), pm_printf(PM_LOG_ERROR, _("invalid value for 'CleanMethod' : '%s'\n"),
value); value);
} }
return 0;
} }
/** Add repeating options such as NoExtract, NoUpgrade, etc to libalpm /** Add repeating options such as NoExtract, NoUpgrade, etc to libalpm
@ -839,7 +842,7 @@ static void option_add_cleanmethod(const char *value) {
* @param optionfunc a function pointer to an alpm_option_add_* function * @param optionfunc a function pointer to an alpm_option_add_* function
*/ */
static void setrepeatingoption(char *ptr, const char *option, static void setrepeatingoption(char *ptr, const char *option,
void (*optionfunc)(const char*)) int (*optionfunc)(const char*))
{ {
char *q; char *q;