Go to the documentation of this file.
32 #define DIRECTORY_SEPARATOR '\\'
34 #define DIRECTORY_SEPARATOR '/'
47 if (strlen(path) > 1 && path[0] ==
'/') {
51 #if (defined OS_WIN32 || defined __CYGWIN__)
52 if (strlen(path) > 2) {
53 if (isalpha((
unsigned char)path[0]) && path[1] ==
':') {
75 int PathMerge(
char *out_buf,
size_t buf_size,
const char *
const dir,
const char *
const fname)
78 if (dir == NULL || strlen(dir) == 0)
81 size_t r =
strlcpy(path, dir,
sizeof(path));
82 if (r >=
sizeof(path)) {
86 #if defined OS_WIN32 || defined __CYGWIN__
87 if (path[strlen(path) - 1] !=
'\\')
88 r =
strlcat(path,
"\\\\",
sizeof(path));
90 if (path[strlen(path) - 1] !=
'/')
91 r =
strlcat(path,
"/",
sizeof(path));
93 if (r >=
sizeof(path)) {
96 r =
strlcat(path, fname,
sizeof(path));
97 if (r >=
sizeof(path)) {
100 r =
strlcpy(out_buf, path, buf_size);
111 if (
PathMerge(path,
sizeof(path), dir, fname) != 0)
126 return SCMkDir(path, S_IRWXU | S_IRGRP | S_IXGRP);
140 char pathbuf[PATH_MAX];
142 size_t len = strlen(path);
144 if (
len > PATH_MAX - 1) {
148 strlcpy(pathbuf, path,
sizeof(pathbuf));
150 for (
p = pathbuf + 1; *
p;
p++) {
156 if (errno != EEXIST) {
167 if (errno != EEXIST) {
187 return stat(path, &sb) == 0;
200 #if !defined(OS_WIN32) && !defined(__sun)
201 if ((dir_entry->d_type == DT_DIR) &&
202 (strcmp(dir_entry->d_name,
".") != 0) &&
203 (strcmp(dir_entry->d_name,
"..") != 0)) {
219 return dir_entry->d_type == DT_REG;
235 return _fullpath(resolved_path, path, PATH_MAX);
237 return realpath(path, resolved_path);
249 if (!path || strlen(path) == 0)
256 if (*(
final + 1) ==
'\0')
273 return strstr(path,
"../") != NULL || strstr(path,
"..\\") != NULL;
275 return strstr(path,
"../") != NULL;
293 if (strcmp(mode,
"a") != 0 && strcmp(mode,
"w") != 0) {
301 return fopen(path, mode);
312 if (path == NULL || path[0] ==
'\0') {
318 ub.actime = ub.modtime = time(NULL);
319 if (utime(path, &ub) == 0)
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 SCTouchFile(const char *path)
Update access and modification time of an existing file to 'now'.
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.
FILE * SCFopenLogFile(const char *path, const char *mode)
Open a text log file for append or truncate.
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.
FILE * SCWin32Fopen(const char *path, const char *mode)
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.