summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pacman/conf.c18
-rw-r--r--src/pacman/package.c10
-rw-r--r--src/pacman/package.h2
-rw-r--r--src/pacman/pacman.c58
-rw-r--r--src/pacman/query.c3
-rw-r--r--src/pacman/sync.c6
-rw-r--r--src/pacman/trans.c1
-rw-r--r--src/pacman/util.c10
-rw-r--r--src/pacman/util.h19
9 files changed, 41 insertions, 86 deletions
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 8a438269..3409f8d3 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -24,21 +24,16 @@
#include <stdlib.h>
#include <stdio.h>
-#include <alpm.h>
-
/* pacman */
#include "conf.h"
-#include "pacman.h"
-#include "util.h"
-#include "log.h"
config_t *config_new(void)
{
- config_t *config;
-
- MALLOC(config, sizeof(config_t));
-
- memset(config, 0, sizeof(config_t));
+ config_t *config = calloc(1, sizeof(config_t));
+ if(!config) {
+ fprintf(stderr, "malloc failure: could not allocate %d bytes\n",
+ sizeof(config_t));
+ }
return(config);
}
@@ -49,8 +44,9 @@ int config_free(config_t *config)
return(-1);
}
- FREE(config->configfile);
+ free(config->configfile);
free(config);
+ config = NULL;
return(0);
}
diff --git a/src/pacman/package.c b/src/pacman/package.c
index d9b63088..c1617f4d 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -164,7 +164,7 @@ void dump_pkg_backups(pmpkg_t *pkg)
char *str = strdup(alpm_list_getdata(i));
char *ptr = index(str, '\t');
if(ptr == NULL) {
- FREE(str);
+ free(str);
continue;
}
*ptr = '\0';
@@ -178,7 +178,7 @@ void dump_pkg_backups(pmpkg_t *pkg)
if(md5sum == NULL || sha1sum == NULL) {
ERR(NL, _("error calculating checksums for %s\n"), path);
- FREE(str);
+ free(str);
continue;
}
/* TODO Is this a good way to check type of backup stored?
@@ -194,12 +194,12 @@ void dump_pkg_backups(pmpkg_t *pkg)
} else {
printf(_("Not Modified\t%s\n"), path);
}
- FREE(md5sum);
- FREE(sha1sum);
+ free(md5sum);
+ free(sha1sum);
} else {
printf(_("MISSING\t\t%s\n"), path);
}
- FREE(str);
+ free(str);
}
} else {
/* package had no backup files */
diff --git a/src/pacman/package.h b/src/pacman/package.h
index 965ecee5..be5368b4 100644
--- a/src/pacman/package.h
+++ b/src/pacman/package.h
@@ -30,8 +30,6 @@ void dump_pkg_backups(pmpkg_t *pkg);
void dump_pkg_files(pmpkg_t *pkg);
void dump_pkg_changelog(char *clfile, const char *pkgname);
-#define FREEPKG(p) { alpm_pkg_free(p); p = NULL; }
-
#endif /* _PM_PACKAGE_H */
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 9949dd62..9eef9dde 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -33,15 +33,7 @@
#include <sys/stat.h>
#include <libintl.h>
#include <locale.h>
-#if defined(__APPLE__)
-#include <malloc/malloc.h>
-#elif defined(__OpenBSD__) || defined(__APPLE__)
-#include <sys/malloc.h>
-#elif defined(CYGWIN)
-#include <libgen.h> /* basename */
-#else
-#include <mcheck.h> /* debug */
-#endif
+#include <mcheck.h> /* debug tracing (mtrace) */
#include <time.h>
/* alpm */
@@ -56,10 +48,6 @@
#include "conf.h"
#include "package.h"
-#if defined(__OpenBSD__) || defined(__APPLE__)
-#define BSD
-#endif
-
/* Operations */
enum {
PM_OP_MAIN = 1,
@@ -316,11 +304,7 @@ static int parseargs(int argc, char *argv[])
if(config->configfile) {
free(config->configfile);
}
- #if defined(__OpenBSD__) || defined(__APPLE__)
- config->configfile = strdup(optarg);
- #else
config->configfile = strndup(optarg, PATH_MAX);
- #endif
break;
case 1002: alpm_option_add_ignorepkg(strdup(optarg)); break;
case 1003:
@@ -459,14 +443,15 @@ static int parseargs(int argc, char *argv[])
int main(int argc, char *argv[])
{
int ret = 0;
-#ifndef CYGWIN
+ /* may not work with CYGWIN */
uid_t myuid;
-#endif
-#if defined(PACMAN_DEBUG) && !defined(CYGWIN) && !defined(BSD)
+#if defined(PACMAN_DEBUG)
+ /* need to ensure we have mcheck installed */
/*setenv("MALLOC_TRACE","pacman.mtrace", 0);*/
mtrace();
#endif
+
/* set signal handlers */
signal(SIGINT, cleanup);
signal(SIGTERM, cleanup);
@@ -478,6 +463,7 @@ int main(int argc, char *argv[])
/* init config data */
config = config_new();
config->op = PM_OP_MAIN;
+
/* disable progressbar if the output is redirected */
if(!isatty(1)) {
config->noprogressbar = 1;
@@ -496,15 +482,8 @@ int main(int argc, char *argv[])
exit(ret);
}
-#ifndef CYGWIN
/* see if we're root or not */
myuid = geteuid();
-#ifndef FAKEROOT
- if(!myuid && getenv("FAKEROOTKEY")) {
- /* fakeroot doesn't count, we're non-root */
- myuid = 99;
- }
-#endif
/* check if we have sufficient permission for the requested operation */
if(myuid > 0) {
@@ -524,7 +503,6 @@ int main(int argc, char *argv[])
}
}
}
-#endif
/* Setup logging as soon as possible, to print out maximum debugging info */
alpm_option_set_logcb(cb_log);
@@ -569,12 +547,24 @@ int main(int argc, char *argv[])
/* start the requested operation */
switch(config->op) {
- case PM_OP_ADD: ret = pacman_add(pm_targets); break;
- case PM_OP_REMOVE: ret = pacman_remove(pm_targets); break;
- case PM_OP_UPGRADE: ret = pacman_upgrade(pm_targets); break;
- case PM_OP_QUERY: ret = pacman_query(pm_targets); break;
- case PM_OP_SYNC: ret = pacman_sync(pm_targets); break;
- case PM_OP_DEPTEST: ret = pacman_deptest(pm_targets); break;
+ case PM_OP_ADD:
+ ret = pacman_add(pm_targets);
+ break;
+ case PM_OP_REMOVE:
+ ret = pacman_remove(pm_targets);
+ break;
+ case PM_OP_UPGRADE:
+ ret = pacman_upgrade(pm_targets);
+ break;
+ case PM_OP_QUERY:
+ ret = pacman_query(pm_targets);
+ break;
+ case PM_OP_SYNC:
+ ret = pacman_sync(pm_targets);
+ break;
+ case PM_OP_DEPTEST:
+ ret = pacman_deptest(pm_targets);
+ break;
default:
ERR(NL, _("no operation specified (use -h for help)\n"));
ret = 1;
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 02be63aa..caf1db28 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -244,7 +244,8 @@ int pacman_query(alpm_list_t *targets)
MSG(NL, "%s %s\n", alpm_pkg_get_name(info),
alpm_pkg_get_version(info));
}
- FREEPKG(info);
+ alpm_pkg_free(info);
+ info = NULL;
continue;
}
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index e8399625..5b20147c 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -25,14 +25,8 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
-#if defined(__APPLE__) || defined(__OpenBSD__)
-#include <sys/syslimits.h>
-#endif
#include <unistd.h>
#include <dirent.h>
-#ifdef CYGWIN
-#include <limits.h> /* PATH_MAX */
-#endif
#include <alpm.h>
#include <alpm_list.h>
diff --git a/src/pacman/trans.c b/src/pacman/trans.c
index 8efa6d07..e67d5607 100644
--- a/src/pacman/trans.c
+++ b/src/pacman/trans.c
@@ -37,6 +37,7 @@
#include "log.h"
#include "conf.h"
+/* TODO this should not have to be defined twice- trans.c & log.c */
#define LOG_STR_LEN 256
extern config_t *config;
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 1fb6ead9..a7259e25 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -21,10 +21,6 @@
#include "config.h"
-#if defined(__APPLE__) || defined(__OpenBSD__)
-#include <sys/syslimits.h>
-#include <sys/stat.h>
-#endif
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/time.h>
@@ -37,9 +33,6 @@
#include <ctype.h>
#include <dirent.h>
#include <unistd.h>
-#ifdef CYGWIN
-#include <limits.h> /* PATH_MAX */
-#endif
#include <alpm.h>
#include <alpm_list.h>
@@ -88,7 +81,7 @@ int getcols()
int makepath(char *path)
{
char *orig, *str, *ptr;
- char full[PATH_MAX] = "";
+ char full[PATH_MAX+1] = "";
mode_t oldmask;
oldmask = umask(0000);
@@ -99,6 +92,7 @@ int makepath(char *path)
if(strlen(ptr)) {
struct stat buf;
+ /* TODO we should use strncat */
strcat(full, "/");
strcat(full, ptr);
if(stat(full, &buf)) {
diff --git a/src/pacman/util.h b/src/pacman/util.h
index f12ec6f1..85ce6ede 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -27,25 +27,6 @@
#include <alpm_list.h>
-#define MALLOC(p, b) do { \
- if((b) > 0) { \
- p = malloc(b); \
- if (!(p)) { \
- fprintf(stderr, "malloc failure: could not allocate %d bytes\n", (int)b); \
- exit(EXIT_FAILURE); \
- } \
- } else { \
- p = NULL; \
- } \
-} while(0)
-
-#define FREE(p) do { if (p) { free(p); (p) = NULL; }} while(0)
-
-#define STRNCPY(s1, s2, len) do { \
- strncpy(s1, s2, (len)-1); \
- s1[(len)-1] = 0; \
-} while(0)
-
/* update speed for the fill_progress based functions */
#define UPDATE_SPEED_SEC 0.2f