summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pacman/Makefile.am2
-rw-r--r--src/pacman/callback.c2
-rw-r--r--src/pacman/conf.c8
-rw-r--r--src/pacman/conf.h4
-rw-r--r--src/pacman/database.c10
-rw-r--r--src/pacman/deptest.c4
-rw-r--r--src/pacman/package.c4
-rw-r--r--src/pacman/pacman.c155
-rw-r--r--src/pacman/query.c60
-rw-r--r--src/pacman/remove.c16
-rw-r--r--src/pacman/sync.c86
-rw-r--r--src/pacman/upgrade.c22
-rw-r--r--src/pacman/util.c143
-rw-r--r--src/util/cleanupdelta.c2
-rw-r--r--src/util/pactree.c18
-rw-r--r--src/util/testdb.c20
-rw-r--r--src/util/testpkg.c6
-rw-r--r--src/util/vercmp.c6
18 files changed, 318 insertions, 250 deletions
diff --git a/src/pacman/Makefile.am b/src/pacman/Makefile.am
index 31e8b134..333b8193 100644
--- a/src/pacman/Makefile.am
+++ b/src/pacman/Makefile.am
@@ -1,6 +1,7 @@
# paths set at make time
conffile = ${sysconfdir}/pacman.conf
dbpath = ${localstatedir}/lib/pacman/
+gpgdir = ${sysconfdir}/pacman.d/gnupg/
cachedir = ${localstatedir}/cache/pacman/pkg/
logfile = ${localstatedir}/log/pacman.log
@@ -10,6 +11,7 @@ DEFS = -DLOCALEDIR=\"@localedir@\" \
-DCONFFILE=\"$(conffile)\" \
-DROOTDIR=\"$(ROOTDIR)\" \
-DDBPATH=\"$(dbpath)\" \
+ -DGPGDIR=\"$(gpgdir)\" \
-DCACHEDIR=\"$(cachedir)\" \
-DLOGFILE=\"$(logfile)\" \
@DEFS@
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 5edcc966..08c1cf3f 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -81,7 +81,7 @@ static double get_update_timediff(int first_call)
}
}
- return(retval);
+ return retval;
}
/* refactored from cb_trans_progress */
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index e2a168ee..69110ab9 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -38,7 +38,7 @@ config_t *config_new(void)
pm_fprintf(stderr, PM_LOG_ERROR,
_("malloc failure: could not allocate %zd bytes\n"),
sizeof(config_t));
- return(NULL);
+ return NULL;
}
/* defaults which may get overridden later */
newconfig->op = PM_OP_MAIN;
@@ -46,13 +46,13 @@ config_t *config_new(void)
/* CONFFILE is defined at compile-time */
newconfig->configfile = strdup(CONFFILE);
- return(newconfig);
+ return newconfig;
}
int config_free(config_t *oldconfig)
{
if(oldconfig == NULL) {
- return(-1);
+ return -1;
}
FREELIST(oldconfig->holdpkg);
@@ -66,7 +66,7 @@ int config_free(config_t *oldconfig)
free(oldconfig);
oldconfig = NULL;
- return(0);
+ return 0;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 92c379fc..bb11bab2 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -40,6 +40,7 @@ typedef struct __config_t {
char *rootdir;
char *dbpath;
char *logfile;
+ char *gpgdir;
/* TODO how to handle cachedirs? */
unsigned short op_q_isfile;
@@ -106,7 +107,8 @@ enum {
OP_NEEDED,
OP_ASEXPLICIT,
OP_ARCH,
- OP_PRINTFORMAT
+ OP_PRINTFORMAT,
+ OP_GPGDIR
};
/* clean method */
diff --git a/src/pacman/database.c b/src/pacman/database.c
index 36433f33..9d6edab5 100644
--- a/src/pacman/database.c
+++ b/src/pacman/database.c
@@ -47,7 +47,7 @@ int pacman_database(alpm_list_t *targets)
if(targets == NULL) {
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
- return(1);
+ return 1;
}
if(config->flags & PM_TRANS_FLAG_ALLDEPS) { /* --asdeps */
@@ -56,12 +56,12 @@ int pacman_database(alpm_list_t *targets)
reason = PM_PKG_REASON_EXPLICIT;
} else {
pm_printf(PM_LOG_ERROR, _("no install reason specified (use -h for help)\n"));
- return(1);
+ return 1;
}
/* Lock database */
if(trans_init(0) == -1) {
- return(1);
+ return 1;
}
db_local = alpm_option_get_localdb();
@@ -82,9 +82,9 @@ int pacman_database(alpm_list_t *targets)
/* Unlock database */
if(trans_release() == -1) {
- return(1);
+ return 1;
}
- return(retval);
+ return retval;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c
index 8895b487..cc1e565b 100644
--- a/src/pacman/deptest.c
+++ b/src/pacman/deptest.c
@@ -47,7 +47,7 @@ int pacman_deptest(alpm_list_t *targets)
}
if(deps == NULL) {
- return(0);
+ return 0;
}
for(i = deps; i; i = alpm_list_next(i)) {
@@ -56,7 +56,7 @@ int pacman_deptest(alpm_list_t *targets)
printf("%s\n", dep);
}
alpm_list_free(deps);
- return(127);
+ return 127;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 77a5ee72..d8dde695 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -173,7 +173,7 @@ static const char *get_backup_file_status(const char *root,
if(md5sum == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR,
_("could not calculate checksums for %s\n"), path);
- return(NULL);
+ return NULL;
}
/* if checksums don't match, file has been modified */
@@ -195,7 +195,7 @@ static const char *get_backup_file_status(const char *root,
ret = "UNKNOWN";
}
}
- return(ret);
+ return ret;
}
/* Display list of backup files and their modification states
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 0ad03540..c5c83d77 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -66,9 +66,9 @@ static int options_cmp(const void *p1, const void *p2)
const char *s1 = p1;
const char *s2 = p2;
- if(s1 == s2) return(0);
- if(!s1) return(-1);
- if(!s2) return(1);
+ if(s1 == s2) return 0;
+ if(!s1) return -1;
+ if(!s2) return 1;
/* First skip all spaces in both strings */
while(isspace((unsigned char)*s1)) {
s1++;
@@ -87,15 +87,15 @@ static int options_cmp(const void *p1, const void *p2)
s2++;
} else if(*s2 == '-') {
/* s1 short, s2 long */
- return(-1);
+ return -1;
} else if(*s1 == '-') {
/* s1 long, s2 short */
- return(1);
+ return 1;
}
/* two short -> strcmp */
}
- return(strcmp(s1, s2));
+ return strcmp(s1, s2);
}
/** Display usage/syntax for the specified operation.
@@ -207,6 +207,7 @@ static void usage(int op, const char * const myname)
addlist(_(" --cachedir <dir> set an alternate package cache location\n"));
addlist(_(" --config <path> set an alternate configuration file\n"));
addlist(_(" --debug display debug messages\n"));
+ addlist(_(" --gpgdir <path> set an alternate home directory for GnuPG\n"));
addlist(_(" --logfile <path> set an alternate log file\n"));
addlist(_(" --noconfirm do not ask for any confirmation\n"));
}
@@ -302,7 +303,7 @@ static ssize_t xwrite(int fd, const void *buf, size_t count)
do {
ret = write(fd, buf, count);
} while(ret == -1 && errno == EINTR);
- return(ret);
+ return ret;
}
/** Catches thrown signals. Performs necessary cleanup to ensure database is
@@ -321,7 +322,7 @@ static void handler(int signum)
xwrite(out, msg1, strlen(msg1));
xwrite(err, msg2, strlen(msg2));
exit(signum);
- } else if((signum == SIGINT)) {
+ } else if(signum == SIGINT) {
const char *msg = "\nInterrupt signal received\n";
xwrite(err, msg, strlen(msg));
if(alpm_trans_interrupt() == 0) {
@@ -390,6 +391,17 @@ static void setlibpaths(void)
}
}
+ /* Set GnuPG's home directory. This is not relative to rootdir, even if
+ * rootdir is defined. Reasoning: gpgdir contains configuration data. */
+ if(config->gpgdir) {
+ ret = alpm_option_set_signaturedir(config->gpgdir);
+ if(ret != 0) {
+ pm_printf(PM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)\n"),
+ config->gpgdir, alpm_strerrorlast());
+ cleanup(ret);
+ }
+ }
+
/* add a default cachedir if one wasn't specified */
if(alpm_option_get_cachedirs() == NULL) {
alpm_option_add_cachedir(CACHEDIR);
@@ -398,9 +410,9 @@ 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)
{
@@ -412,7 +424,7 @@ static int parsearg_util_addlist(fn_add fn)
fn((char *)alpm_list_getdata(item));
}
FREELIST(list);
- return(0);
+ return 0;
}
/** Helper function for parsing operation from command-line arguments.
@@ -449,9 +461,9 @@ static int parsearg_op(int opt, int dryrun)
if(dryrun) break;
config->help = 1; break;
default:
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
/** Helper functions for parsing command-line arguments.
@@ -472,7 +484,7 @@ static int parsearg_global(int opt)
if(alpm_option_add_cachedir(optarg) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
optarg, alpm_strerrorlast());
- return(1);
+ return 1;
}
break;
case OP_CONFIG:
@@ -497,7 +509,7 @@ static int parsearg_global(int opt)
default:
pm_printf(PM_LOG_ERROR, _("'%s' is not a valid debug level\n"),
optarg);
- return(1);
+ return 1;
}
} else {
config->logmask |= PM_LOG_DEBUG;
@@ -505,6 +517,9 @@ static int parsearg_global(int opt)
/* progress bars get wonky with debug on, shut them off */
config->noprogressbar = 1;
break;
+ case OP_GPGDIR:
+ config->gpgdir = strdup(optarg);
+ break;
case OP_LOGFILE:
check_optarg();
config->logfile = strndup(optarg, PATH_MAX);
@@ -516,9 +531,9 @@ static int parsearg_global(int opt)
break;
case 'r': check_optarg(); config->rootdir = strdup(optarg); break;
case 'v': (config->verbose)++; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
static int parsearg_database(int opt)
@@ -526,9 +541,9 @@ static int parsearg_database(int opt)
switch(opt) {
case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break;
case OP_ASEXPLICIT: config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
static int parsearg_query(int opt)
@@ -548,9 +563,9 @@ static int parsearg_query(int opt)
case 's': config->op_q_search = 1; break;
case 't': config->op_q_unrequired = 1; break;
case 'u': config->op_q_upgrade = 1; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
/* options common to -S -R -U */
@@ -572,15 +587,15 @@ static int parsearg_trans(int opt)
check_optarg();
config->print_format = strdup(optarg);
break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
static int parsearg_remove(int opt)
{
if (parsearg_trans(opt) == 0)
- return(0);
+ return 0;
switch(opt) {
case 'c': config->flags |= PM_TRANS_FLAG_CASCADE; break;
case 'n': config->flags |= PM_TRANS_FLAG_NOSAVE; break;
@@ -592,16 +607,16 @@ static int parsearg_remove(int opt)
}
break;
case 'u': config->flags |= PM_TRANS_FLAG_UNNEEDED; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
/* options common to -S -U */
static int parsearg_upgrade(int opt)
{
if (parsearg_trans(opt) == 0)
- return(0);
+ return 0;
switch(opt) {
case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break;
case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break;
@@ -612,15 +627,15 @@ static int parsearg_upgrade(int opt)
case OP_IGNOREGROUP:
parsearg_util_addlist(alpm_option_add_ignoregrp);
break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
static int parsearg_sync(int opt)
{
if (parsearg_upgrade(opt) == 0)
- return(0);
+ return 0;
switch(opt) {
case OP_NEEDED: config->flags |= PM_TRANS_FLAG_NEEDED; break;
case 'c': (config->op_s_clean)++; break;
@@ -636,9 +651,9 @@ static int parsearg_sync(int opt)
config->flags |= PM_TRANS_FLAG_NOCONFLICTS;
break;
case 'y': (config->op_s_sync)++; break;
- default: return(1);
+ default: return 1;
}
- return(0);
+ return 0;
}
/** Parse command-line arguments for each operation.
@@ -706,6 +721,7 @@ static int parseargs(int argc, char *argv[])
{"asexplicit", no_argument, 0, OP_ASEXPLICIT},
{"arch", required_argument, 0, OP_ARCH},
{"print-format", required_argument, 0, OP_PRINTFORMAT},
+ {"gpgdir", required_argument, 0, OP_GPGDIR},
{0, 0, 0, 0}
};
@@ -717,22 +733,22 @@ static int parseargs(int argc, char *argv[])
continue;
} else if(opt == '?') {
/* unknown option, getopt printed an error */
- return(1);
+ return 1;
}
parsearg_op(opt, 0);
}
if(config->op == 0) {
pm_printf(PM_LOG_ERROR, _("only one operation may be used at a time\n"));
- return(1);
+ return 1;
}
if(config->help) {
usage(config->op, mbasename(argv[0]));
- return(2);
+ return 2;
}
if(config->version) {
version();
- return(2);
+ return 2;
}
/* parse all other options */
@@ -744,7 +760,7 @@ static int parseargs(int argc, char *argv[])
continue;
} else if(opt == '?') {
/* this should have failed during first pass already */
- return(1);
+ return 1;
} else if(parsearg_op(opt, 1) == 0) {
/* opt is an operation */
continue;
@@ -780,7 +796,7 @@ static int parseargs(int argc, char *argv[])
if(result != 0) {
/* global option parsing failed, abort */
pm_printf(PM_LOG_ERROR, _("invalid option\n"));
- return(result);
+ return result;
}
}
@@ -790,21 +806,23 @@ static int parseargs(int argc, char *argv[])
optind++;
}
- return(0);
+ return 0;
}
/* 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));
+ return 0;
}
/* 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));
+ return 0;
}
/* 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) {
config->cleanmethod |= PM_CLEAN_KEEPINST;
} else if (strcmp(value, "KeepCurrent") == 0) {
@@ -813,6 +831,7 @@ static void option_add_cleanmethod(const char *value) {
pm_printf(PM_LOG_ERROR, _("invalid value for 'CleanMethod' : '%s'\n"),
value);
}
+ return 0;
}
/** Add repeating options such as NoExtract, NoUpgrade, etc to libalpm
@@ -823,7 +842,7 @@ static void option_add_cleanmethod(const char *value) {
* @param optionfunc a function pointer to an alpm_option_add_* function
*/
static void setrepeatingoption(char *ptr, const char *option,
- void (*optionfunc)(const char*))
+ int (*optionfunc)(const char*))
{
char *q;
@@ -843,7 +862,7 @@ static char *get_filename(const char *url) {
if(filename != NULL) {
filename++;
}
- return(filename);
+ return filename;
}
static char *get_destfile(const char *path, const char *filename) {
@@ -853,7 +872,7 @@ static char *get_destfile(const char *path, const char *filename) {
destfile = calloc(len, sizeof(char));
snprintf(destfile, len, "%s%s", path, filename);
- return(destfile);
+ return destfile;
}
static char *get_tempfile(const char *path, const char *filename) {
@@ -863,7 +882,7 @@ static char *get_tempfile(const char *path, const char *filename) {
tempfile = calloc(len, sizeof(char));
snprintf(tempfile, len, "%s%s.part", path, filename);
- return(tempfile);
+ return tempfile;
}
/** External fetch callback */
@@ -955,7 +974,7 @@ cleanup:
free(tempfile);
free(parsedcmd);
- return(ret);
+ return ret;
}
static int _parse_options(const char *key, char *value,
@@ -1013,7 +1032,7 @@ static int _parse_options(const char *key, char *value,
if(alpm_option_add_cachedir(value) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
value, alpm_strerrorlast());
- return(1);
+ return 1;
}
pm_printf(PM_LOG_DEBUG, "config: cachedir: %s\n", value);
} else if(strcmp(key, "RootDir") == 0) {
@@ -1022,6 +1041,11 @@ static int _parse_options(const char *key, char *value,
config->rootdir = strdup(value);
pm_printf(PM_LOG_DEBUG, "config: rootdir: %s\n", value);
}
+ } else if (strcmp(key, "GPGDir") == 0) {
+ if(!config->gpgdir) {
+ config->gpgdir = strdup(value);
+ pm_printf(PM_LOG_DEBUG, "config: gpgdir: %s\n", value);
+ }
} else if (strcmp(key, "LogFile") == 0) {
if(!config->logfile) {
config->logfile = strdup(value);
@@ -1041,7 +1065,7 @@ static int _parse_options(const char *key, char *value,
}
}
- return(0);
+ return 0;
}
static int _add_mirror(pmdb_t *db, char *value)
@@ -1060,7 +1084,7 @@ static int _add_mirror(pmdb_t *db, char *value)
free(temp);
pm_printf(PM_LOG_ERROR, _("The mirror '%s' contains the $arch"
" variable, but no Architecture is defined.\n"), value);
- return(1);
+ return 1;
}
server = temp;
}
@@ -1070,11 +1094,11 @@ static int _add_mirror(pmdb_t *db, char *value)
pm_printf(PM_LOG_ERROR, _("could not add server URL to database '%s': %s (%s)\n"),
dbname, server, alpm_strerrorlast());
free(server);
- return(1);
+ return 1;
}
free(server);
- return(0);
+ return 0;
}
/* The real parseconfig. Called with a null section argument by the publicly
@@ -1093,7 +1117,7 @@ static int _parseconfig(const char *file, const char *givensection,
fp = fopen(file, "r");
if(fp == NULL) {
pm_printf(PM_LOG_ERROR, _("config file %s could not be read.\n"), file);
- return(1);
+ return 1;
}
/* if we are passed a section, use it as our starting point */
@@ -1225,6 +1249,24 @@ static int _parseconfig(const char *file, const char *givensection,
ret = 1;
goto cleanup;
}
+ } else if(strcmp(key, "VerifySig") == 0) {
+ if (strcmp(value, "Always") == 0) {
+ ret = alpm_db_set_pgp_verify(db,PM_PGP_VERIFY_ALWAYS);
+ } else if (strcmp(value, "Optional") == 0) {
+ ret = alpm_db_set_pgp_verify(db,PM_PGP_VERIFY_OPTIONAL);
+ } else if (strcmp(value, "Never") == 0) {
+ ret = alpm_db_set_pgp_verify(db,PM_PGP_VERIFY_NEVER);
+ } else {
+ pm_printf(PM_LOG_ERROR, _("invalid value for 'VerifySig' : '%s'\n"), value);
+ ret = 1;
+ goto cleanup;
+ }
+ if (ret != 0) {
+ pm_printf(PM_LOG_ERROR, _("could not add pgp verify option to database '%s': %s (%s)\n"),
+ alpm_db_get_name(db), value, alpm_strerrorlast());
+ goto cleanup;
+ }
+ pm_printf(PM_LOG_DEBUG, "config: VerifySig for %s: %s\n",alpm_db_get_name(db), value);
} else {
pm_printf(PM_LOG_WARNING,
_("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
@@ -1242,7 +1284,7 @@ cleanup:
/* call setlibpaths here to ensure we have called it at least once */
setlibpaths();
pm_printf(PM_LOG_DEBUG, "config: finished parsing %s\n", file);
- return(ret);
+ return ret;
}
/** Parse a configuration file.
@@ -1252,7 +1294,7 @@ cleanup:
static int parseconfig(const char *file)
{
/* call the real parseconfig function with a null section & db argument */
- return(_parseconfig(file, NULL, NULL));
+ return _parseconfig(file, NULL, NULL);
}
/** print commandline to logfile
@@ -1345,6 +1387,7 @@ int main(int argc, char *argv[])
/* define paths to reasonable defaults */
alpm_option_set_root(ROOTDIR);
alpm_option_set_dbpath(DBPATH);
+ alpm_option_set_signaturedir(GPGDIR);
alpm_option_set_logfile(LOGFILE);
/* Priority of options:
@@ -1479,7 +1522,7 @@ int main(int argc, char *argv[])
cleanup(ret);
/* not reached */
- return(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 5d036881..d27044eb 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -43,15 +43,15 @@ static char *resolve_path(const char *file)
str = calloc(PATH_MAX + 1, sizeof(char));
if(!str) {
- return(NULL);
+ return NULL;
}
if(!realpath(file, str)) {
free(str);
- return(NULL);
+ return NULL;
}
- return(str);
+ return str;
}
/* check if filename exists in PATH */
@@ -61,10 +61,10 @@ static int search_path(char **filename, struct stat *bufptr)
size_t flen;
if ((envpath = getenv("PATH")) == NULL) {
- return(-1);
+ return -1;
}
if ((envpath = envpathsplit = strdup(envpath)) == NULL) {
- return(-1);
+ return -1;
}
flen = strlen(*filename);
@@ -84,12 +84,12 @@ static int search_path(char **filename, struct stat *bufptr)
free(*filename);
*filename = fullname;
free(envpath);
- return(0);
+ return 0;
}
free(fullname);
}
free(envpath);
- return(-1);
+ return -1;
}
static void print_query_fileowner(const char *filename, pmpkg_t *info)
@@ -115,7 +115,7 @@ static int query_fileowner(alpm_list_t *targets)
/* This code is here for safety only */
if(targets == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR, _("no file was specified for --owns\n"));
- return(1);
+ return 1;
}
/* Set up our root path buffer. We only need to copy the location of root in
@@ -248,7 +248,7 @@ static int query_search(alpm_list_t *targets)
freelist = 0;
}
if(searchlist == NULL) {
- return(1);
+ return 1;
}
for(i = searchlist; i; i = alpm_list_next(i)) {
@@ -296,7 +296,7 @@ static int query_search(alpm_list_t *targets)
if(freelist) {
alpm_list_free(searchlist);
}
- return(0);
+ return 0;
}
static int query_group(alpm_list_t *targets)
@@ -359,19 +359,19 @@ static int is_foreign(pmpkg_t *pkg)
}
}
if(match == 0) {
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
static int is_unrequired(pmpkg_t *pkg)
{
alpm_list_t *requiredby = alpm_pkg_compute_requiredby(pkg);
if(requiredby == NULL) {
- return(1);
+ return 1;
}
FREELIST(requiredby);
- return(0);
+ return 0;
}
static int filter(pmpkg_t *pkg)
@@ -379,26 +379,26 @@ static int filter(pmpkg_t *pkg)
/* check if this package was explicitly installed */
if(config->op_q_explicit &&
alpm_pkg_get_reason(pkg) != PM_PKG_REASON_EXPLICIT) {
- return(0);
+ return 0;
}
/* check if this package was installed as a dependency */
if(config->op_q_deps &&
alpm_pkg_get_reason(pkg) != PM_PKG_REASON_DEPEND) {
- return(0);
+ return 0;
}
/* check if this pkg isn't in a sync DB */
if(config->op_q_foreign && !is_foreign(pkg)) {
- return(0);
+ return 0;
}
/* check if this pkg is unrequired */
if(config->op_q_unrequired && !is_unrequired(pkg)) {
- return(0);
+ return 0;
}
/* check if this pkg is outdated */
if(config->op_q_upgrade && (alpm_sync_newversion(pkg, alpm_option_get_syncdbs()) == NULL)) {
- return(0);
+ return 0;
}
- return(1);
+ return 1;
}
/* Loop through the packages. For each package,
@@ -416,7 +416,7 @@ static int check(pmpkg_t *pkg)
if(rootlen + 1 > PATH_MAX) {
/* we are in trouble here */
pm_fprintf(stderr, PM_LOG_ERROR, _("path too long: %s%s\n"), root, "");
- return(1);
+ return 1;
}
strcpy(f, root);
@@ -450,7 +450,7 @@ static int check(pmpkg_t *pkg)
(unsigned long)errors), errors);
}
- return(errors != 0 ? 1 : 0);
+ return (errors != 0 ? 1 : 0);
}
static int display(pmpkg_t *pkg)
@@ -482,7 +482,7 @@ static int display(pmpkg_t *pkg)
printf("%s\n", alpm_pkg_get_name(pkg));
}
}
- return(ret);
+ return ret;
}
int pacman_query(alpm_list_t *targets)
@@ -498,13 +498,13 @@ int pacman_query(alpm_list_t *targets)
/* search for a package */
if(config->op_q_search) {
ret = query_search(targets);
- return(ret);
+ return ret;
}
/* looking for groups */
if(config->group) {
ret = query_group(targets);
- return(ret);
+ return ret;
}
if(config->op_q_foreign) {
@@ -512,7 +512,7 @@ int pacman_query(alpm_list_t *targets)
alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
- return(1);
+ return 1;
}
}
@@ -524,7 +524,7 @@ int pacman_query(alpm_list_t *targets)
if(targets == NULL) {
if(config->op_q_isfile || config->op_q_owns) {
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
- return(1);
+ return 1;
}
for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) {
@@ -540,7 +540,7 @@ int pacman_query(alpm_list_t *targets)
if(!match) {
ret = 1;
}
- return(ret);
+ return ret;
}
/* Second: operations that require target(s) */
@@ -548,7 +548,7 @@ int pacman_query(alpm_list_t *targets)
/* determine the owner of a file */
if(config->op_q_owns) {
ret = query_fileowner(targets);
- return(ret);
+ return ret;
}
/* operations on named packages in the local DB
@@ -586,7 +586,7 @@ int pacman_query(alpm_list_t *targets)
ret = 1;
}
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index fb02e242..58e6edd5 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -40,25 +40,25 @@ static int remove_target(char *target)
if((info = alpm_db_get_pkg(db_local, target)) != NULL) {
if(alpm_remove_pkg(info) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast());
- return(-1);
+ return -1;
}
- return(0);
+ return 0;
}
/* fallback to group */
pmgrp_t *grp = alpm_db_readgrp(db_local, target);
if(grp == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': target not found\n", target);
- return(-1);
+ return -1;
}
for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
pmpkg_t *pkg = alpm_list_getdata(p);
if(alpm_remove_pkg(pkg) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast());
- return(-1);
+ return -1;
}
}
- return(0);
+ return 0;
}
/**
@@ -75,12 +75,12 @@ int pacman_remove(alpm_list_t *targets)
if(targets == NULL) {
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
- return(1);
+ return 1;
}
/* Step 0: create a new transaction */
if(trans_init(config->flags) == -1) {
- return(1);
+ return 1;
}
/* Step 1: add targets to the created transaction */
@@ -173,7 +173,7 @@ cleanup:
if(trans_release() == -1) {
retval = 1;
}
- return(retval);
+ return retval;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index c56934b6..0b34f045 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -47,7 +47,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
dir = opendir(dbpath);
if(dir == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR, _("could not access database directory\n"));
- return(1);
+ return 1;
}
syncdbs = alpm_option_get_syncdbs();
@@ -84,7 +84,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
pm_fprintf(stderr, PM_LOG_ERROR,
_("could not remove %s\n"), path);
closedir(dir);
- return(1);
+ return 1;
}
continue;
}
@@ -110,12 +110,12 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
pm_fprintf(stderr, PM_LOG_ERROR,
_("could not remove %s\n"), path);
closedir(dir);
- return(1);
+ return 1;
}
}
}
closedir(dir);
- return(0);
+ return 0;
}
static int sync_cleandb_all(void) {
@@ -126,7 +126,7 @@ static int sync_cleandb_all(void) {
dbpath = alpm_option_get_dbpath();
printf(_("Database directory: %s\n"), dbpath);
if(!yesno(_("Do you want to remove unused repositories?"))) {
- return(0);
+ return 0;
}
/* The sync dbs were previously put in dbpath/ but are now in dbpath/sync/.
* We will clean everything in dbpath/ except local/, sync/ and db.lck, and
@@ -137,7 +137,7 @@ static int sync_cleandb_all(void) {
ret += sync_cleandb(newdbpath, 1);
printf(_("Database directory cleaned up\n"));
- return(ret);
+ return ret;
}
static int sync_cleancache(int level)
@@ -165,12 +165,12 @@ static int sync_cleancache(int level)
printf(_(" All current sync database packages\n"));
}
if(!yesno(_("Do you want to remove all other packages from cache?"))) {
- return(0);
+ return 0;
}
printf(_("removing old packages from cache...\n"));
} else {
if(!noyes(_("Do you want to remove ALL files from cache?"))) {
- return(0);
+ return 0;
}
printf(_("removing all files from cache...\n"));
}
@@ -258,7 +258,7 @@ static int sync_cleancache(int level)
closedir(dir);
}
- return(ret);
+ return ret;
}
static int sync_synctree(int level, alpm_list_t *syncs)
@@ -267,7 +267,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
int success = 0, ret;
if(trans_init(0) == -1) {
- return(0);
+ return 0;
}
for(i = syncs; i; i = alpm_list_next(i)) {
@@ -286,7 +286,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
}
if(trans_release() == -1) {
- return(0);
+ return 0;
}
/* We should always succeed if at least one DB was upgraded - we may possibly
* fail later with unresolved deps, but that should be rare, and would be
@@ -295,7 +295,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
if(!success) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to synchronize any databases\n"));
}
- return(success > 0);
+ return (success > 0);
}
static void print_installed(pmdb_t *db_local, pmpkg_t *pkg)
@@ -384,7 +384,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
}
}
- return(!found);
+ return !found;
}
static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
@@ -432,7 +432,7 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
}
}
- return(0);
+ return 0;
}
static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
@@ -466,7 +466,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
if(!db) {
pm_fprintf(stderr, PM_LOG_ERROR,
_("repository '%s' does not exist\n"), repo);
- return(1);
+ return 1;
}
for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) {
@@ -517,7 +517,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
}
}
- return(ret);
+ return ret;
}
static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
@@ -543,7 +543,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
pm_fprintf(stderr, PM_LOG_ERROR,
_("repository \"%s\" was not found.\n"),repo);
alpm_list_free(ls);
- return(1);
+ return 1;
}
ls = alpm_list_add(ls, db);
@@ -573,7 +573,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
alpm_list_free(ls);
}
- return(0);
+ return 0;
}
static alpm_list_t *syncfirst(void) {
@@ -592,7 +592,7 @@ static alpm_list_t *syncfirst(void) {
}
}
- return(res);
+ return res;
}
static pmdb_t *get_db(const char *dbname)
@@ -601,10 +601,10 @@ static pmdb_t *get_db(const char *dbname)
for(i = alpm_option_get_syncdbs(); i; i = i->next) {
pmdb_t *db = i->data;
if(strcmp(alpm_db_get_name(db), dbname) == 0) {
- return(db);
+ return db;
}
}
- return(NULL);
+ return NULL;
}
static int process_pkg(pmpkg_t *pkg)
@@ -616,14 +616,14 @@ static int process_pkg(pmpkg_t *pkg)
|| pm_errno == PM_ERR_PKG_IGNORED) {
/* just skip duplicate or ignored targets */
pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), alpm_pkg_get_name(pkg));
- return(0);
+ return 0;
} else {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", alpm_pkg_get_name(pkg),
alpm_strerrorlast());
- return(1);
+ return 1;
}
}
- return(0);
+ return 0;
}
static int process_group(alpm_list_t *dbs, char *group)
@@ -635,7 +635,7 @@ static int process_group(alpm_list_t *dbs, char *group)
if(!count) {
pm_fprintf(stderr, PM_LOG_ERROR, _("target not found: %s\n"), group);
- return(1);
+ return 1;
}
@@ -669,7 +669,7 @@ static int process_group(alpm_list_t *dbs, char *group)
}
cleanup:
alpm_list_free(pkgs);
- return(ret);
+ return ret;
}
static int process_targname(alpm_list_t *dblist, char *targname)
@@ -680,14 +680,14 @@ static int process_targname(alpm_list_t *dblist, char *targname)
if(pm_errno == PM_ERR_PKG_IGNORED) {
pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targname);
pm_errno = 0;
- return(0);
+ return 0;
}
if(pkg) {
- return(process_pkg(pkg));
+ return process_pkg(pkg);
}
/* fallback on group */
- return(process_group(dblist, targname));
+ return process_group(dblist, targname);
}
static int process_target(char *target)
@@ -722,7 +722,7 @@ static int process_target(char *target)
}
cleanup:
free(targstring);
- return(ret);
+ return ret;
}
static int sync_trans(alpm_list_t *targets)
@@ -734,7 +734,7 @@ static int sync_trans(alpm_list_t *targets)
/* Step 1: create a new transaction... */
if(trans_init(config->flags) == -1) {
- return(1);
+ return 1;
}
/* process targets */
@@ -874,7 +874,7 @@ cleanup:
retval = 1;
}
- return(retval);
+ return retval;
}
int pacman_sync(alpm_list_t *targets)
@@ -886,7 +886,7 @@ int pacman_sync(alpm_list_t *targets)
int ret = 0;
if(trans_init(0) == -1) {
- return(1);
+ return 1;
}
ret += sync_cleancache(config->op_s_clean);
@@ -897,14 +897,14 @@ int pacman_sync(alpm_list_t *targets)
ret++;
}
- return(ret);
+ return ret;
}
/* ensure we have at least one valid sync db set up */
sync_dbs = alpm_option_get_syncdbs();
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
- return(1);
+ return 1;
}
if(config->op_s_sync) {
@@ -912,40 +912,40 @@ int pacman_sync(alpm_list_t *targets)
printf(_(":: Synchronizing package databases...\n"));
alpm_logaction("synchronizing package lists\n");
if(!sync_synctree(config->op_s_sync, sync_dbs)) {
- return(1);
+ return 1;
}
}
/* search for a package */
if(config->op_s_search) {
- return(sync_search(sync_dbs, targets));
+ return sync_search(sync_dbs, targets);
}
/* look for groups */
if(config->group) {
- return(sync_group(config->group, sync_dbs, targets));
+ return sync_group(config->group, sync_dbs, targets);
}
/* get package info */
if(config->op_s_info) {
- return(sync_info(sync_dbs, targets));
+ return sync_info(sync_dbs, targets);
}
/* get a listing of files in sync DBs */
if(config->op_q_list) {
- return(sync_list(sync_dbs, targets));
+ return sync_list(sync_dbs, targets);
}
if(targets == NULL) {
if(config->op_s_upgrade) {
/* proceed */
} else if(config->op_s_sync) {
- return(0);
+ return 0;
} else {
/* don't proceed here unless we have an operation that doesn't require a
* target list */
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
- return(1);
+ return 1;
}
}
@@ -980,7 +980,7 @@ int pacman_sync(alpm_list_t *targets)
int ret = sync_trans(targs);
FREELIST(targs);
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index 8cd29da0..5b894001 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -46,7 +46,7 @@ int pacman_upgrade(alpm_list_t *targets)
if(targets == NULL) {
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
- return(1);
+ return 1;
}
/* Check for URL targets and process them
@@ -57,7 +57,7 @@ int pacman_upgrade(alpm_list_t *targets)
if(str == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
(char *)i->data, alpm_strerrorlast());
- return(1);
+ return 1;
} else {
free(i->data);
i->data = str;
@@ -67,7 +67,7 @@ int pacman_upgrade(alpm_list_t *targets)
/* Step 1: create a new transaction */
if(trans_init(config->flags) == -1) {
- return(1);
+ return 1;
}
/* add targets to the created transaction */
@@ -79,14 +79,14 @@ int pacman_upgrade(alpm_list_t *targets)
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
targ, alpm_strerrorlast());
trans_release();
- return(1);
+ return 1;
}
if(alpm_add_pkg(pkg) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
targ, alpm_strerrorlast());
alpm_pkg_free(pkg);
trans_release();
- return(1);
+ return 1;
}
}
@@ -135,7 +135,7 @@ int pacman_upgrade(alpm_list_t *targets)
}
trans_release();
FREELIST(data);
- return(1);
+ return 1;
}
/* Step 3: perform the installation */
@@ -143,7 +143,7 @@ int pacman_upgrade(alpm_list_t *targets)
if(config->print) {
print_packages(alpm_trans_get_add());
trans_release();
- return(0);
+ return 0;
}
/* print targets and ask user confirmation */
@@ -151,7 +151,7 @@ int pacman_upgrade(alpm_list_t *targets)
if(packages == NULL) { /* we are done */
printf(_(" there is nothing to do\n"));
trans_release();
- return(retval);
+ return retval;
}
display_targets(alpm_trans_get_remove(), 0);
display_targets(alpm_trans_get_add(), 1);
@@ -159,7 +159,7 @@ int pacman_upgrade(alpm_list_t *targets)
int confirm = yesno(_("Proceed with installation?"));
if(!confirm) {
trans_release();
- return(retval);
+ return retval;
}
if(alpm_trans_commit(&data) == -1) {
@@ -197,13 +197,13 @@ int pacman_upgrade(alpm_list_t *targets)
}
FREELIST(data);
trans_release();
- return(1);
+ return 1;
}
if(trans_release() == -1) {
retval = 1;
}
- return(retval);
+ return retval;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 3d268031..c4773481 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -37,6 +37,9 @@
#include <unistd.h>
#include <limits.h>
#include <wchar.h>
+#ifdef HAVE_TERMIOS_H
+#include <termios.h> /* tcflush */
+#endif
#include <alpm.h>
#include <alpm_list.h>
@@ -68,9 +71,9 @@ int trans_init(pmtransflag_t flags)
fprintf(stderr, _(" try running pacman-db-upgrade\n"));
}
- return(-1);
+ return -1;
}
- return(0);
+ return 0;
}
int trans_release(void)
@@ -78,28 +81,40 @@ int trans_release(void)
if(alpm_trans_release() == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"),
alpm_strerrorlast());
- return(-1);
+ return -1;
}
- return(0);
+ return 0;
}
int needs_root(void)
{
switch(config->op) {
case PM_OP_DATABASE:
- return(1);
+ return 1;
case PM_OP_UPGRADE:
case PM_OP_REMOVE:
- return(!config->print);
+ return !config->print;
case PM_OP_SYNC:
- return(config->op_s_clean || config->op_s_sync ||
+ return (config->op_s_clean || config->op_s_sync ||
(!config->group && !config->op_s_info && !config->op_q_list &&
!config->op_s_search && !config->print));
default:
- return(0);
+ return 0;
}
}
+/* discard unhandled input on the terminal's input buffer */
+static int flush_term_input(void) {
+#ifdef HAVE_TCFLUSH
+ if(isatty(fileno(stdin))) {
+ return(tcflush(fileno(stdin), TCIFLUSH));
+ }
+#endif
+
+ /* fail silently */
+ return 0;
+}
+
/* gets the current screen column width */
int getcols(void)
{
@@ -125,24 +140,24 @@ int rmrf(const char *path)
DIR *dirp;
if(!unlink(path)) {
- return(0);
+ return 0;
} else {
if(errno == ENOENT) {
- return(0);
+ return 0;
} else if(errno == EPERM) {
/* fallthrough */
} else if(errno == EISDIR) {
/* fallthrough */
} else if(errno == ENOTDIR) {
- return(1);
+ return 1;
} else {
/* not a directory */
- return(1);
+ return 1;
}
dirp = opendir(path);
if(!dirp) {
- return(1);
+ return 1;
}
for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
if(dp->d_ino) {
@@ -157,7 +172,7 @@ int rmrf(const char *path)
if(rmdir(path)) {
errflag++;
}
- return(errflag);
+ return errflag;
}
}
@@ -170,9 +185,9 @@ const char *mbasename(const char *path)
{
const char *last = strrchr(path, '/');
if(last) {
- return(last + 1);
+ return last + 1;
}
- return(path);
+ return path;
}
/** Parse the dirname of a program from a path.
@@ -187,7 +202,7 @@ char *mdirname(const char *path)
/* null or empty path */
if(path == NULL || path == '\0') {
- return(strdup("."));
+ return strdup(".");
}
ret = strdup(path);
@@ -196,11 +211,11 @@ char *mdirname(const char *path)
if(last != NULL) {
/* we found a '/', so terminate our string */
*last = '\0';
- return(ret);
+ return ret;
}
/* no slash found */
free(ret);
- return(strdup("."));
+ return strdup(".");
}
/* output a string, but wrap words properly with a specified indentation
@@ -286,7 +301,7 @@ char *strtrim(char *str)
if(str == NULL || *str == '\0') {
/* string is empty, so we're done. */
- return(str);
+ return str;
}
while(isspace((unsigned char)*pch)) {
@@ -298,7 +313,7 @@ char *strtrim(char *str)
/* check if there wasn't anything but whitespace in the string. */
if(*str == '\0') {
- return(str);
+ return str;
}
pch = (str + (strlen(str) - 1));
@@ -307,7 +322,7 @@ char *strtrim(char *str)
}
*++pch = '\0';
- return(str);
+ return str;
}
/* Replace all occurances of 'needle' with 'replace' in 'str', returning
@@ -321,7 +336,7 @@ char *strreplace(const char *str, const char *needle, const char *replace)
size_t newsz;
if(!str) {
- return(NULL);
+ return NULL;
}
p = str;
@@ -334,7 +349,7 @@ char *strreplace(const char *str, const char *needle, const char *replace)
/* no occurences of needle found */
if(!list) {
- return(strdup(str));
+ return strdup(str);
}
/* size of new string = size of old string + "number of occurences of needle"
* x "size difference between replace and needle" */
@@ -342,7 +357,7 @@ char *strreplace(const char *str, const char *needle, const char *replace)
alpm_list_count(list) * (replacesz - needlesz);
newstr = malloc(newsz);
if(!newstr) {
- return(NULL);
+ return NULL;
}
*newstr = '\0';
@@ -368,7 +383,7 @@ char *strreplace(const char *str, const char *needle, const char *replace)
}
*newp = '\0';
- return(newstr);
+ return newstr;
}
/** Splits a string into a list of strings using the chosen character as
@@ -388,7 +403,7 @@ alpm_list_t *strsplit(const char *str, const char splitchar)
while((str = strchr(str, splitchar))) {
dup = strndup(prev, (size_t)(str - prev));
if(dup == NULL) {
- return(NULL);
+ return NULL;
}
list = alpm_list_add(list, dup);
@@ -398,11 +413,11 @@ alpm_list_t *strsplit(const char *str, const char splitchar)
dup = strdup(prev);
if(dup == NULL) {
- return(NULL);
+ return NULL;
}
list = alpm_list_add(list, dup);
- return(list);
+ return list;
}
static int string_length(const char *s)
@@ -411,7 +426,7 @@ static int string_length(const char *s)
wchar_t *wcstr;
if(!s) {
- return(0);
+ return 0;
}
/* len goes from # bytes -> # chars -> # cols */
len = strlen(s) + 1;
@@ -420,7 +435,7 @@ static int string_length(const char *s)
len = wcswidth(wcstr, len);
free(wcstr);
- return(len);
+ return len;
}
void string_display(const char *title, const char *string)
@@ -568,11 +583,11 @@ static off_t pkg_get_size(pmpkg_t *pkg)
{
switch(config->op) {
case PM_OP_SYNC:
- return(alpm_pkg_download_size(pkg));
+ return alpm_pkg_download_size(pkg);
case PM_OP_UPGRADE:
- return(alpm_pkg_get_size(pkg));
+ return alpm_pkg_get_size(pkg);
default:
- return(alpm_pkg_get_isize(pkg));
+ return alpm_pkg_get_isize(pkg);
}
}
@@ -588,14 +603,14 @@ static char *pkg_get_location(pmpkg_t *pkg)
if(dburl) {
char *pkgurl = NULL;
pm_asprintf(&pkgurl, "%s/%s", dburl, alpm_pkg_get_filename(pkg));
- return(pkgurl);
+ return pkgurl;
}
case PM_OP_UPGRADE:
- return(strdup(alpm_pkg_get_filename(pkg)));
+ return strdup(alpm_pkg_get_filename(pkg));
default:
string = NULL;
pm_asprintf(&string, "%s-%s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
- return(string);
+ return string;
}
}
@@ -657,7 +672,7 @@ void print_packages(const alpm_list_t *packages)
* alpm "compare func" signature */
int str_cmp(const void *s1, const void *s2)
{
- return(strcmp(s1, s2));
+ return strcmp(s1, s2);
}
void display_new_optdepends(pmpkg_t *oldpkg, pmpkg_t *newpkg)
@@ -726,13 +741,13 @@ static int parseindex(char *s, int *val, int min, int max)
if(n < min || n > max) {
fprintf(stderr, _("Invalid value: %d is not between %d and %d\n"),
n, min, max);
- return(-1);
+ return -1;
}
*val = n;
- return(0);
+ return 0;
} else {
fprintf(stderr, _("Invalid number: %s\n"), s);
- return(-1);
+ return -1;
}
}
@@ -773,14 +788,14 @@ static int multiselect_parse(char *array, int count, char *response)
}
if(parseindex(starts, &start, 1, count) != 0)
- return(-1);
+ return -1;
if(!ends) {
array[start-1] = include;
} else {
int d;
if(parseindex(ends, &end, start, count) != 0) {
- return(-1);
+ return -1;
}
for(d = start; d <= end; d++) {
array[d-1] = include;
@@ -788,7 +803,7 @@ static int multiselect_parse(char *array, int count, char *response)
}
}
- return(0);
+ return 0;
}
int multiselect_question(char *array, int count)
@@ -815,6 +830,8 @@ int multiselect_question(char *array, int count)
break;
}
+ flush_term_input();
+
if(fgets(response, sizeof(response), stdin)) {
strtrim(response);
if(strlen(response) > 0) {
@@ -826,7 +843,7 @@ int multiselect_question(char *array, int count)
}
break;
}
- return(0);
+ return 0;
}
int select_question(int count)
@@ -852,19 +869,21 @@ int select_question(int count)
break;
}
+ flush_term_input();
+
if(fgets(response, sizeof(response), stdin)) {
strtrim(response);
if(strlen(response) > 0) {
int n;
if(parseindex(response, &n, 1, count) != 0)
continue;
- return(n-1);
+ return (n - 1);
}
}
break;
}
- return(preset-1);
+ return (preset - 1);
}
@@ -895,23 +914,25 @@ static int question(short preset, char *fmt, va_list args)
if(config->noconfirm) {
fprintf(stream, "\n");
- return(preset);
+ return preset;
}
fflush(stream);
+ flush_term_input();
+
if(fgets(response, sizeof(response), stdin)) {
strtrim(response);
if(strlen(response) == 0) {
- return(preset);
+ return preset;
}
if(strcasecmp(response, _("Y")) == 0 || strcasecmp(response, _("YES")) == 0) {
- return(1);
+ return 1;
} else if (strcasecmp(response, _("N")) == 0 || strcasecmp(response, _("NO")) == 0) {
- return(0);
+ return 0;
}
}
- return(0);
+ return 0;
}
int yesno(char *fmt, ...)
@@ -923,7 +944,7 @@ int yesno(char *fmt, ...)
ret = question(1, fmt, args);
va_end(args);
- return(ret);
+ return ret;
}
int noyes(char *fmt, ...)
@@ -935,7 +956,7 @@ int noyes(char *fmt, ...)
ret = question(0, fmt, args);
va_end(args);
- return(ret);
+ return ret;
}
int pm_printf(pmloglevel_t level, const char *format, ...)
@@ -948,7 +969,7 @@ int pm_printf(pmloglevel_t level, const char *format, ...)
ret = pm_vfprintf(stdout, level, format, args);
va_end(args);
- return(ret);
+ return ret;
}
int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...)
@@ -961,7 +982,7 @@ int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...)
ret = pm_vfprintf(stream, level, format, args);
va_end(args);
- return(ret);
+ return ret;
}
int pm_asprintf(char **string, const char *format, ...)
@@ -977,7 +998,7 @@ int pm_asprintf(char **string, const char *format, ...)
}
va_end(args);
- return(ret);
+ return ret;
}
int pm_vasprintf(char **string, pmloglevel_t level, const char *format, va_list args)
@@ -1013,7 +1034,7 @@ int pm_vasprintf(char **string, pmloglevel_t level, const char *format, va_list
}
free(msg);
- return(ret);
+ return ret;
}
int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args)
@@ -1061,7 +1082,7 @@ int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list ar
/* print the message using va_arg list */
ret = vfprintf(stream, format, args);
- return(ret);
+ return ret;
}
#ifndef HAVE_STRNDUP
@@ -1070,7 +1091,7 @@ static size_t strnlen(const char *s, size_t max)
{
register const char *p;
for(p = s; *p && max--; ++p);
- return(p - s);
+ return (p - s);
}
char *strndup(const char *s, size_t n)
@@ -1082,7 +1103,7 @@ char *strndup(const char *s, size_t n)
return NULL;
new[len] = '\0';
- return (char *) memcpy(new, s, len);
+ return (char *)memcpy(new, s, len);
}
#endif
diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c
index 71ba3a47..6388e840 100644
--- a/src/util/cleanupdelta.c
+++ b/src/util/cleanupdelta.c
@@ -119,7 +119,7 @@ int main(int argc, char *argv[])
if(alpm_initialize() == -1) {
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
- return(1);
+ return 1;
}
/* let us get log messages from libalpm */
diff --git a/src/util/pactree.c b/src/util/pactree.c
index 6a10006f..94e628b6 100644
--- a/src/util/pactree.c
+++ b/src/util/pactree.c
@@ -60,12 +60,12 @@ static int alpm_local_init(void)
ret = alpm_initialize();
if(ret != 0) {
- return(ret);
+ return ret;
}
ret = alpm_option_set_root(ROOTDIR);
if(ret != 0) {
- return(ret);
+ return ret;
}
if(dbpath) {
@@ -74,15 +74,15 @@ static int alpm_local_init(void)
ret = alpm_option_set_dbpath(DBPATH);
}
if(ret != 0) {
- return(ret);
+ return ret;
}
db_local = alpm_option_get_localdb();
if(!db_local) {
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
static int parse_options(int argc, char *argv[])
@@ -137,12 +137,12 @@ static int parse_options(int argc, char *argv[])
case 'h':
case '?':
default:
- return(1);
+ return 1;
}
}
if(!argv[optind]) {
- return(1);
+ return 1;
}
if(!color) {
@@ -159,7 +159,7 @@ static int parse_options(int argc, char *argv[])
indent_size = 0;
}
- return(0);
+ return 0;
}
static void usage(void)
@@ -366,7 +366,7 @@ int main(int argc, char *argv[])
finish:
cleanup();
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/util/testdb.c b/src/util/testdb.c
index 0436a23f..3d4fa6ae 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -63,7 +63,7 @@ static int check_localdb_files(void)
snprintf(path, sizeof(path), "%slocal", dbpath);
if(!(dir = opendir(path))) {
fprintf(stderr, "error : %s : %s\n", path, strerror(errno));
- return(1);
+ return 1;
}
while ((ent = readdir(dir)) != NULL) {
@@ -85,10 +85,10 @@ static int check_localdb_files(void)
}
if(closedir(dir)) {
fprintf(stderr, "error closing dbpath : %s\n", strerror(errno));
- return(1);
+ return 1;
}
- return(ret);
+ return ret;
}
static int checkdeps(alpm_list_t *pkglist)
@@ -107,7 +107,7 @@ static int checkdeps(alpm_list_t *pkglist)
ret++;
}
FREELIST(data);
- return(ret);
+ return ret;
}
static int checkconflicts(alpm_list_t *pkglist)
@@ -123,7 +123,7 @@ static int checkconflicts(alpm_list_t *pkglist)
ret++;
}
FREELIST(data);
- return(ret);
+ return ret;
}
static int check_localdb(void) {
@@ -133,7 +133,7 @@ static int check_localdb(void) {
ret = check_localdb_files();
if(ret) {
- return(ret);
+ return ret;
}
db = alpm_option_get_localdb();
@@ -145,7 +145,7 @@ static int check_localdb(void) {
pkglist = alpm_db_get_pkgcache(db);
ret += checkdeps(pkglist);
ret += checkconflicts(pkglist);
- return(ret);
+ return ret;
}
static int check_syncdbs(alpm_list_t *dbnames) {
@@ -169,7 +169,7 @@ static int check_syncdbs(alpm_list_t *dbnames) {
cleanup:
alpm_list_free(syncpkglist);
- return(ret);
+ return ret;
}
static void usage(void) {
@@ -206,7 +206,7 @@ int main(int argc, char *argv[])
if(alpm_initialize() == -1) {
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
- return(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
/* let us get log messages from libalpm */
@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
if(alpm_option_set_dbpath(dbpath) != 0) {
fprintf(stderr, "cannot set dbpath: %s\n", alpm_strerrorlast());
- return(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
if(!dbnames) {
diff --git a/src/util/testpkg.c b/src/util/testpkg.c
index d0d9cac1..e562dde2 100644
--- a/src/util/testpkg.c
+++ b/src/util/testpkg.c
@@ -44,12 +44,12 @@ int main(int argc, char *argv[])
if(argc != 2) {
fprintf(stderr, "usage: %s <package file>\n", BASENAME);
- return(1);
+ return 1;
}
if(alpm_initialize() == -1) {
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
- return(1);
+ return 1;
}
/* let us get log messages from libalpm */
@@ -79,5 +79,5 @@ int main(int argc, char *argv[])
fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
}
- return(retval);
+ return retval;
}
diff --git a/src/util/vercmp.c b/src/util/vercmp.c
index adb5a42a..88cf49a6 100644
--- a/src/util/vercmp.c
+++ b/src/util/vercmp.c
@@ -45,13 +45,13 @@ int main(int argc, char *argv[])
if(argc == 1) {
usage();
- return(2);
+ return 2;
}
if(argc > 1 &&
(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0
|| strcmp(argv[1], "--usage") == 0)) {
usage();
- return(0);
+ return 0;
}
if(argc > 2) {
s2 = argv[2];
@@ -62,5 +62,5 @@ int main(int argc, char *argv[])
ret = alpm_pkg_vercmp(s1, s2);
printf("%d\n", ret);
- return(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
}