solidc
Robust collection of general-purpose cross-platform C libraries and data structures designed for rapid and safe development in C
Loading...
Searching...
No Matches
filepath.h
Go to the documentation of this file.
1
13#ifndef DA20B33A_06DF_4AB0_8B0A_B8874A623312
14#define DA20B33A_06DF_4AB0_8B0A_B8874A623312
15
16#include "file.h"
17#include "macros.h"
18#include "platform.h"
19
20#include <stdbool.h>
21#include <stddef.h>
22#include <stdint.h>
23#include <stdio.h>
24
25#ifdef _WIN32
26#include "win32_dirent.h"
27
28#include <windows.h>
29
30#ifndef _WIN32_WINNT
31#define _WIN32_WINNT 0x0400 // Required for syncapi
32#endif
33#define PATH_SEP '\\'
34#define PATH_SEP_STR "\\"
35#else
36#include <dirent.h>
37#include <pwd.h>
38#include <sys/mman.h>
39#include <sys/random.h>
40#include <sys/stat.h>
41#include <unistd.h>
42
44#define PATH_SEP '/'
45
47#define PATH_SEP_STR "/"
48
49#ifndef MAX_PATH
50#define MAX_PATH 1024
51#endif
52#endif
53
54#ifdef __cplusplus
55extern "C" {
56#endif
57
64typedef struct {
65 char* path;
66#ifdef _WIN32
67 HANDLE handle;
68 WIN32_FIND_DATAW find_data;
69 char name_buf[MAX_PATH];
70#else
71 DIR* dir;
72#endif
73} Directory;
74
83WARN_UNUSED_RESULT Directory* dir_open(const char* path);
84
91void dir_close(Directory* dir);
92
103WARN_UNUSED_RESULT char* dir_next(Directory* dir);
104
114int dir_create(const char* path);
115
125int dir_remove(const char* path, bool recursive);
126
137int dir_rename(const char* oldpath, const char* newpath);
138
147int dir_chdir(const char* path);
148
159WARN_UNUSED_RESULT char** dir_list(const char* path, size_t* count);
160
169void dir_list_with_callback(const char* path, void (*callback)(const char* name));
170
179bool is_dir(const char* path);
180
189bool is_file(const char* path);
190
200bool is_symlink(const char* path);
201
210bool filepath_makedirs(const char* path);
211
221WARN_UNUSED_RESULT char* get_tempdir(void);
222
231WARN_UNUSED_RESULT char* make_tempfile(void);
232
241WARN_UNUSED_RESULT char* make_tempdir(void);
242
252
263typedef WalkDirOption (*WalkDirCallback)(const FileAttributes* attr, const char* path, const char* name, void* data);
264
276int dir_walk(const char* path, WalkDirCallback callback, void* data);
277
289int dir_walk_depth_first(const char* path, WalkDirCallback callback, void* data);
290
300ssize_t dir_size(const char* path);
301
310bool path_exists(const char* path);
311
319WARN_UNUSED_RESULT char* get_cwd(void);
320
331void filepath_basename(const char* path, char* basename, size_t size);
332
343void filepath_dirname(const char* path, char* dirname, size_t size);
344
355void filepath_extension(const char* path, char* ext, size_t size);
356
366void filepath_nameonly(const char* path, char* name, size_t size);
367
377WARN_UNUSED_RESULT char* filepath_absolute(const char* path);
378
387int filepath_remove(const char* path);
388
399int filepath_rename(const char* oldpath, const char* newpath);
400
410const char* user_home_dir(void);
411
422WARN_UNUSED_RESULT char* filepath_expanduser(const char* path);
423
433bool filepath_expanduser_buf(const char* path, char* expanded, size_t len);
434
445WARN_UNUSED_RESULT char* filepath_join(const char* path1, const char* path2);
446
457bool filepath_join_buf(const char* path1, const char* path2, char* abspath, size_t len);
458
470void filepath_split(const char* path, char* dir, char* name, size_t dir_size, size_t name_size);
471
472#ifdef __cplusplus
473}
474#endif
475
476#endif /* DA20B33A_06DF_4AB0_8B0A_B8874A623312 */
Cross-platform file handling API with synchronous and asynchronous I/O support.
bool is_dir(const char *path)
Definition filepath.c:583
WalkDirOption
Definition filepath.h:246
@ DirSkip
Definition filepath.h:249
@ DirError
Definition filepath.h:250
@ DirStop
Definition filepath.h:248
@ DirContinue
Definition filepath.h:247
void filepath_extension(const char *path, char *ext, size_t size)
Definition filepath.c:982
void filepath_dirname(const char *path, char *dirname, size_t size)
Definition filepath.c:963
bool is_file(const char *path)
Definition filepath.c:604
WalkDirOption(* WalkDirCallback)(const FileAttributes *attr, const char *path, const char *name, void *data)
Definition filepath.h:263
void filepath_nameonly(const char *path, char *name, size_t size)
Definition filepath.c:995
int filepath_rename(const char *oldpath, const char *newpath)
Definition filepath.c:1061
WARN_UNUSED_RESULT char * make_tempfile(void)
Definition filepath.c:844
int dir_create(const char *path)
Definition filepath.c:306
int dir_chdir(const char *path)
Definition filepath.c:498
WARN_UNUSED_RESULT Directory * dir_open(const char *path)
Definition filepath.c:118
bool filepath_join_buf(const char *path1, const char *path2, char *abspath, size_t len)
Definition filepath.c:1177
bool path_exists(const char *path)
Definition filepath.c:926
int filepath_remove(const char *path)
Definition filepath.c:1047
int dir_rename(const char *oldpath, const char *newpath)
Definition filepath.c:489
const char * user_home_dir(void)
Definition filepath.c:1070
void dir_list_with_callback(const char *path, void(*callback)(const char *name))
Definition filepath.c:563
WARN_UNUSED_RESULT char * filepath_absolute(const char *path)
Definition filepath.c:1015
WARN_UNUSED_RESULT char * get_cwd(void)
Definition filepath.c:1037
WARN_UNUSED_RESULT char ** dir_list(const char *path, size_t *count)
Definition filepath.c:507
void filepath_basename(const char *path, char *basename, size_t size)
Definition filepath.c:948
bool filepath_makedirs(const char *path)
Definition filepath.c:767
WARN_UNUSED_RESULT char * filepath_join(const char *path1, const char *path2)
Definition filepath.c:1156
ssize_t dir_size(const char *path)
Definition filepath.c:753
WARN_UNUSED_RESULT char * dir_next(Directory *dir)
Definition filepath.c:192
WARN_UNUSED_RESULT char * make_tempdir(void)
Definition filepath.c:887
void dir_close(Directory *dir)
Definition filepath.c:175
void filepath_split(const char *path, char *dir, char *name, size_t dir_size, size_t name_size)
Definition filepath.c:1204
bool is_symlink(const char *path)
Definition filepath.c:625
WARN_UNUSED_RESULT char * filepath_expanduser(const char *path)
Definition filepath.c:1079
int dir_walk(const char *path, WalkDirCallback callback, void *data)
Definition filepath.c:649
WARN_UNUSED_RESULT char * get_tempdir(void)
Definition filepath.c:809
int dir_walk_depth_first(const char *path, WalkDirCallback callback, void *data)
Definition filepath.c:398
bool filepath_expanduser_buf(const char *path, char *expanded, size_t len)
Definition filepath.c:1118
int dir_remove(const char *path, bool recursive)
Definition filepath.c:473
Collection of utility macros for assertions, memory management, math, and debugging.
Cross-platform compatibility definitions.
DIR * dir
Definition filepath.h:71
char * path
Definition filepath.h:65
Windows directory entry compatibility for POSIX dirent.h.