int safe_open_ex(int at_fd, char* pathname, int flags) {
if (pathname != NULL && strlen(pathname) == 0) {
int safe_open_ex(int at_fd, char* pathname, int flags) {
if (pathname != NULL && strlen(pathname) == 0) {
openat() opens only the next directory (and doesn't recurse). */
*firstslash = '\0';
int fd = safe_open_ex(at_fd, pathname, flags);
openat() opens only the next directory (and doesn't recurse). */
*firstslash = '\0';
int fd = safe_open_ex(at_fd, pathname, flags);
}
/* The ++ is safe because there needs to be at least a null byte
after the first slash, even if it's the last real character in
the string. */
int result = safe_open_ex(fd, firstslash+1, flags);
}
/* The ++ is safe because there needs to be at least a null byte
after the first slash, even if it's the last real character in
the string. */
int result = safe_open_ex(fd, firstslash+1, flags);
int safe_open(const char* pathname, int flags) {
if (pathname == NULL || strlen(pathname) == 0 || pathname[0] == '\0') {
/* error? */
int safe_open(const char* pathname, int flags) {
if (pathname == NULL || strlen(pathname) == 0 || pathname[0] == '\0') {
/* error? */
}
char abs_cwd[PATH_MAX];
if (realpath(cwd, abs_cwd) == NULL) {
perror("safe_open (realpath)");
free(cwd);
}
char abs_cwd[PATH_MAX];
if (realpath(cwd, abs_cwd) == NULL) {
perror("safe_open (realpath)");
free(cwd);
}
snprintf_result = snprintf(abspath, PATH_MAX, "%s/%s", abs_cwd, pathname);
free(cwd);
}
}
snprintf_result = snprintf(abspath, PATH_MAX, "%s/%s", abs_cwd, pathname);
free(cwd);
}
char* parent = dirname(path_copy);
fd = safe_open(path, O_NOFOLLOW);
char* parent = dirname(path_copy);
fd = safe_open(path, O_NOFOLLOW);