#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef __sun__
#include <alloca.h>
#endif
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <dirent.h>
#include <time.h>
#include <syslog.h>
#include <sys/wait.h>
#if defined(__APPLE__) || defined(__OpenBSD__)
#include <sys/syslimits.h>
#endif
#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__sun__)
#include <sys/stat.h>
#endif
#include <libintl.h>
#ifdef CYGWIN
#include <limits.h>
#endif
#include <sys/statvfs.h>
#ifndef __sun__
#include <mntent.h>
#endif
#include "util.h"
#include "alpm_list.h"
#include "log.h"
#include "trans.h"
#include "sync.h"
#include "error.h"
#include "package.h"
#include "alpm.h"
#ifdef __sun__
char* strsep(char** str, const char* delims)
{
char* token;
if (*str==NULL) {
return NULL;
}
token=*str;
while (**str!='\0') {
if (strchr(delims,**str)!=NULL) {
**str='\0';
(*str)++;
return token;
}
(*str)++;
}
*str=NULL;
return token;
}
char *mkdtemp(char *template)
{
char *t = alloca(strlen(template) + 1);
char *r;
(void) strcpy(t, template);
for (; ; ) {
r = mktemp(template);
if (*r == '\0')
return (NULL);
if (mkdir(template, 0700) == 0)
return (r);
if (errno != EEXIST)
return (NULL);
(void) strcpy(template, t);
}
}
#endif
int _alpm_makepath(const char *path)
{
char *orig, *str, *ptr;
char full[PATH_MAX] = "";
mode_t oldmask;
oldmask = umask(0000);
orig = strdup(path);
str = orig;
while((ptr = strsep(&str, "/"))) {
if(strlen(ptr)) {
struct stat buf;
strcat(full, "/");
strcat(full, ptr);
if(stat(full, &buf)) {
if(mkdir(full, 0755)) {
FREE(orig);
umask(oldmask);
_alpm_log(PM_LOG_ERROR, _("failed to make path '%s' : %s"),
path, strerror(errno));
return(1);
}
}
|