blob: 8ad885dea08fd76c20d320ccbf464dfc0898368d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#pragma once
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
typedef struct path {
char* data;
size_t size; // Does not include null terminator. 0 if data is null.
} path;
/// Create a new path.
path path_new(const char*);
/// Free the path's memory.
void path_del(path*);
/// Return a C string from the path.
static inline const char* path_cstr(path p) { return p.data; }
/// Return true if the path is empty, false otherwise.
static inline bool path_empty(path p) {
assert((p.data != 0) || (p.size == 0)); // null data -> 0 size
return p.data != 0;
}
/// Returns the parent directory, or empty path if the given path has no parent.
/// The returned path is a slice of the input path; this function does not
/// allocate.
path path_parent_dir(path);
/// Concatenate two paths.
path path_concat(path left, path right);
/// Make a path relative to the parent directory of a file.
bool path_make_relative(
const char* filepath, const char* path, char* relative,
size_t relative_length);
|