#include "config.h"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <dirent.h>
#include <unistd.h>
#include <limits.h>
#include <wchar.h>
#include <alpm.h>
#include <alpm_list.h>
#include "util.h"
#include "conf.h"
int needs_transaction()
{
if(config->op != PM_OP_MAIN && config->op != PM_OP_QUERY && config->op != PM_OP_DEPTEST) {
if((config->op == PM_OP_SYNC && !config->op_s_sync &&
(config->op_s_search || config->group || config->op_q_list || config->op_q_info))
|| config->op == PM_OP_DEPTEST) {
return(0);
} else {
return(1);
}
}
return(0);
}
int getcols()
{
if(!isatty(1)) {
return 80;
} else {
#ifdef TIOCGSIZE
struct ttysize win;
if(ioctl(1, TIOCGSIZE, &win) == 0) {
return win.ts_cols;
}
#elif defined(TIOCGWINSZ)
struct winsize win;
if(ioctl(1, TIOCGWINSZ, &win) == 0) {
return win.ws_col;
}
#endif
TODO
return 80;
}
}
int makepath(const char *path)
{
char *orig, *str, *ptr;
char full[PATH_MAX+1] = "";
mode_t oldmask;
oldmask = umask(0000);
orig = strdup(path);
str = orig;
while((ptr = strsep(&str, "/"))) {
if(strlen(ptr)) {
struct stat buf;
TODO
strcat(full, "/");
strcat(full, ptr);
if(stat(full, &buf)) {
if(mkdir(full, 0755)) {
free(orig);
umask(oldmask);
return(1);
}
}
}
}
free(orig);
umask(oldmask);
return(0);
}
int rmrf(const char *path)
{
int errflag = 0;
struct dirent *dp;
DIR *dirp;
if(!unlink(path)) {
return(0);
} else {
if(errno == ENOENT) {
return(0);
} else if(errno == EPERM) {
} else if(errno == EISDIR) {
} else if(errno == ENOTDIR) {
return(1);
} else {
return(1);
}
if((dirp = opendir(path)) == (DIR *)-1) {
return(1);
}
for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
if(dp->d_ino) {
char name[PATH_MAX];
sprintf(name, "%s/%s", path, dp->d_name);
if(strcmp(dp->d_name, "..") && strcmp(dp->d_name, ".")) {
errflag += rmrf(name);
}
}
}
closedir(dirp);
if(rmdir(path)) {
errflag++;
}
return(errflag);
}
}
char *mbasename(const char *path)
{
const char *s;
const char *p;
p = s = path;
while (*s) {
if (*s++ == '/') {
p = s;
}
}
return (char *)p;
}
char *mdirname(const char *path)
{
char *ret, *last;
|