#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <alpm.h>
#include <alpm_list.h>
#include "pacman.h"
#include "package.h"
#include "conf.h"
#include "util.h"
static char *resolve_path(const char *file)
{
char *str = NULL;
str = calloc(PATH_MAX, sizeof(char));
if(!str) {
return NULL;
}
if(!realpath(file, str)) {
free(str);
return NULL;
}
return str;
}
static int search_path(char **filename, struct stat *bufptr)
{
char *envpath, *envpathsplit, *path, *fullname;
size_t flen;
if((envpath = getenv("PATH")) == NULL) {
return -1;
}
if((envpath = envpathsplit = strdup(envpath)) == NULL) {
return -1;
}
flen = strlen(*filename);
while((path = strsep(&envpathsplit, ":")) != NULL) {
size_t plen = strlen(path);
while(path[plen - 1] == '/') {
path[--plen] = '\0';
}
fullname = malloc(plen + flen + 2);
if(!fullname) {
free(envpath);
return -1;
}
sprintf(fullname, "%s/%s", path, *filename);
if(lstat(fullname, bufptr) == 0) {
free(*filename);
*filename = fullname;
free(envpath);
return 0;
}
free(fullname);
}
free(envpath);
return -1;
|