Go to the documentation of this file.
31 #define DIRECTORY_SEPARATOR '\\'
33 #define DIRECTORY_SEPARATOR '/'
46 if (strlen(path) > 1 && path[0] ==
'/') {
50 #if (defined OS_WIN32 || defined __CYGWIN__)
51 if (strlen(path) > 2) {
52 if (isalpha((
unsigned char)path[0]) && path[1] ==
':') {
74 int PathMerge(
char *out_buf,
size_t buf_size,
const char *
const dir,
const char *
const fname)
77 if (dir == NULL || strlen(dir) == 0)
80 size_t r =
strlcpy(path, dir,
sizeof(path));
81 if (r >=
sizeof(path)) {
85 #if defined OS_WIN32 || defined __CYGWIN__
86 if (path[strlen(path) - 1] !=
'\\')
87 r =
strlcat(path,
"\\\\",
sizeof(path));
89 if (path[strlen(path) - 1] !=
'/')
90 r =
strlcat(path,
"/",
sizeof(path));
92 if (r >=
sizeof(path)) {
95 r =
strlcat(path, fname,
sizeof(path));
96 if (r >=
sizeof(path)) {
99 r =
strlcpy(out_buf, path, buf_size);
110 if (
PathMerge(path,
sizeof(path), dir, fname) != 0)
125 return SCMkDir(path, S_IRWXU | S_IRGRP | S_IXGRP);
139 char pathbuf[PATH_MAX];
141 size_t len = strlen(path);
143 if (
len > PATH_MAX - 1) {
147 strlcpy(pathbuf, path,
sizeof(pathbuf));
149 for (p = pathbuf + 1; *p; p++) {
155 if (errno != EEXIST) {
166 if (errno != EEXIST) {
186 if (stat(path, &sb) == 0) {
203 if ((dir_entry->d_type == DT_DIR) &&
204 (strcmp(dir_entry->d_name,
".") != 0) &&
205 (strcmp(dir_entry->d_name,
"..") != 0)) {
221 return dir_entry->d_type == DT_REG;
237 return _fullpath(resolved_path, path, PATH_MAX);
239 return realpath(path, resolved_path);
251 if (!path || strlen(path) == 0)
258 if (*(
final + 1) ==
'\0')
274 const char *pattern =
"..\\";
276 const char *pattern =
"../";
278 return strstr(path, pattern) != NULL;
char * PathMergeAlloc(const char *const dir, const char *const fname)
int PathMerge(char *out_buf, size_t buf_size, const char *const dir, const char *const fname)
int SCDefaultMkDir(const char *path)
Wrapper around SCMkDir with default mode arguments.
size_t strlcpy(char *dst, const char *src, size_t siz)
bool SCPathContainsTraversal(const char *path)
Check for directory traversal.
bool SCIsRegularDirectory(const struct dirent *const dir_entry)
OS independent wrapper for directory check.
size_t strlcat(char *, const char *src, size_t siz)
#define DIRECTORY_SEPARATOR
const char * SCBasename(const char *path)
bool SCPathExists(const char *path)
Check if a path exists.
int PathIsAbsolute(const char *path)
Check if a path is absolute.
char * SCRealPath(const char *path, char *resolved_path)
OS independent wrapper for realpath.
int PathIsRelative(const char *path)
Check if a path is relative.
bool SCIsRegularFile(const struct dirent *const dir_entry)
OS independent to check for regular file.
int SCCreateDirectoryTree(const char *path, const bool final)
Recursively create a directory.