#include "sandbox.h" #include #include #include #include #include void find_fullpath(char **path, int _free) { char *result; char *cwd; cwd = get_current_dir_name(); asprintf(&result, "%s/%s", cwd, *path); if (_free) free(*path); free(cwd); *path = result; } int fileinfo_compare(const void *a, const void *b) { return strcmp(((t_fileinfo *)a)->filename, (char *)b) == 0; } int fileinfo_compare_fd(const void *a, const void *fd) { return sllist_find(((t_fileinfo *)a)->fds, sllist_cmp_int, fd) != -1; } t_fileinfo *get_fileinfo(const struct s_sandboxenv *env, const char * filename) { int i; i = sllist_find(env->filetable, fileinfo_compare, filename); if (i == -1) return NULL; return sllist_at(env->filetable, i); } t_fileinfo *get_fileinfo_fd(const struct s_sandboxenv *env, const int fd) { int i; REGISTER_TYPE _fd = (REGISTER_TYPE) fd; i = sllist_find(env->filetable, fileinfo_compare_fd, (void *)_fd); if (i == -1) return NULL; return sllist_at(env->filetable, i); } int file_exists(const char*path) { struct stat buf; if (stat(path, &buf) == -1 && errno == ENOENT) return 0; return 1; } unsigned long long int hash_path(const char *filename) { unsigned long long int result; for (result =0; *filename; ++filename) result = (result << 5) - result + *filename; return result; }