diff options
Diffstat (limited to 'filesystem/include')
-rw-r--r-- | filesystem/include/filesystem.h | 6 | ||||
-rw-r--r-- | filesystem/include/path.h | 38 |
2 files changed, 38 insertions, 6 deletions
diff --git a/filesystem/include/filesystem.h b/filesystem/include/filesystem.h index 3dce87f..1c354b7 100644 --- a/filesystem/include/filesystem.h +++ b/filesystem/include/filesystem.h | |||
@@ -3,7 +3,6 @@ | |||
3 | */ | 3 | */ |
4 | #pragma once | 4 | #pragma once |
5 | 5 | ||
6 | #include <stdbool.h> | ||
7 | #include <stddef.h> | 6 | #include <stddef.h> |
8 | #include <stdio.h> | 7 | #include <stdio.h> |
9 | 8 | ||
@@ -12,8 +11,3 @@ size_t get_file_size(FILE* file); | |||
12 | 11 | ||
13 | /// Read the entire contents of the file into memory. | 12 | /// Read the entire contents of the file into memory. |
14 | void* read_file(const char* filepath); | 13 | void* read_file(const char* filepath); |
15 | |||
16 | /// Make a path relative to the parent directory of a file. | ||
17 | bool make_relative_path( | ||
18 | const char* filepath, const char* path, char* relative, | ||
19 | size_t relative_length); | ||
diff --git a/filesystem/include/path.h b/filesystem/include/path.h new file mode 100644 index 0000000..8ad885d --- /dev/null +++ b/filesystem/include/path.h | |||
@@ -0,0 +1,38 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <assert.h> | ||
4 | #include <stdbool.h> | ||
5 | #include <stddef.h> | ||
6 | |||
7 | typedef struct path { | ||
8 | char* data; | ||
9 | size_t size; // Does not include null terminator. 0 if data is null. | ||
10 | } path; | ||
11 | |||
12 | /// Create a new path. | ||
13 | path path_new(const char*); | ||
14 | |||
15 | /// Free the path's memory. | ||
16 | void path_del(path*); | ||
17 | |||
18 | /// Return a C string from the path. | ||
19 | static inline const char* path_cstr(path p) { return p.data; } | ||
20 | |||
21 | /// Return true if the path is empty, false otherwise. | ||
22 | static inline bool path_empty(path p) { | ||
23 | assert((p.data != 0) || (p.size == 0)); // null data -> 0 size | ||
24 | return p.data != 0; | ||
25 | } | ||
26 | |||
27 | /// Returns the parent directory, or empty path if the given path has no parent. | ||
28 | /// The returned path is a slice of the input path; this function does not | ||
29 | /// allocate. | ||
30 | path path_parent_dir(path); | ||
31 | |||
32 | /// Concatenate two paths. | ||
33 | path path_concat(path left, path right); | ||
34 | |||
35 | /// Make a path relative to the parent directory of a file. | ||
36 | bool path_make_relative( | ||
37 | const char* filepath, const char* path, char* relative, | ||
38 | size_t relative_length); | ||