More pacman side cleanup

* Cleaned up more of the header #includes, and got rid of a lot of stuff
  that was due to trying to make it compile on BSD/Darwin/CYGWIN. We can
  add it later but lets keep it simple for now and do it in seperate files
  if possible later.
* Removed a lot of #define MACROS. Some were not even used, and others were
  only used a few times.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2007-04-25 17:24:23 -04:00
parent da3286a80d
commit 97313ba316
9 changed files with 41 additions and 86 deletions

View File

@ -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);
}

View File

@ -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 */

View File

@ -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: */

View File

@ -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;

View File

@ -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;
}

View File

@ -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>

View File

@ -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;

View File

@ -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)) {

View File

@ -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