#if defined(__APPLE__) || defined(__OpenBSD__)
#include <sys/syslimits.h>
#endif
#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__sun__)
#include <sys/stat.h>
#endif
#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>
#include <libintl.h>
#ifdef CYGWIN
#include <limits.h>
#endif
#include <sys/statvfs.h>
#ifndef __sun__
#include <mntent.h>
#endif
#include "alpm_list.h"
#include "log.h"
#include "trans.h"
#include "sync.h"
#include "util.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(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);
return(1);
}
}
}
}
FREE(orig);
umask(oldmask);
return(0);
}
int _alpm_copyfile(char *src, char *dest)
{
FILE *in, *out;
size_t len;
char buf[4097];
in = fopen(src, "r");
if(in == NULL) {
return(1);
}
out = fopen(dest, "w");
if(out == NULL) {
fclose(in);
return(1);
}
while((len = fread(buf, 1, 4096, in))) {
fwrite(buf, 1, len, out);
}
fclose(in);
fclose(out);
return(0);
}
char *_alpm_strtoupper(char *str)
{
char *ptr = str;
while(*ptr) {
(*ptr) = toupper(*ptr);
ptr++;
}
return str;
}
char *_alpm_strtrim(char *str)
{
char *pch = str;
if(*str == '\0') {
return(str);
}
while(isspace((int)*pch)) {
pch++;
}
if(pch != str) {
memmove(str, pch, (strlen(pch) + 1));
}
if(*str == '\0') {
return(str);
}
pch = (char *)(str + (strlen(str) - 1));
|