summaryrefslogtreecommitdiff
path: root/filesystem.h
blob: 764f45a1ca64b14eaab6ade64e798c1bde6eddf4 (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
#ifndef FILESYSTEM_H_
#define FILESYSTEM_H_

typedef enum {
	FS_NON_EXISTENT,
	FS_FILE,
	FS_DIRECTORY,
	FS_LINK,
	FS_OTHER
} FsType;

// returns what kind of thing this is.
FsType fs_path_type(char const *path);
// Does this file exist? Returns false for directories.
bool fs_file_exists(char const *path);
// Returns a NULL-terminated array of the files/directories in this directory, or NULL if the directory does not exist.
// When you're done with the file names, call free on each one, then on the array.
// NOTE: The files aren't returned in any particular order!
char **fs_list_directory(char const *dirname);
// Create the directory specified by `path`
// Returns:
// 1  if the directory was created successfully
// 0  if the directory already exists
// -1 if the path already exists, but it's not a directory, or if there's another error (e.g. don't have permission to create directory).
int fs_mkdir(char const *path);
// Puts the current working directory into buf, including a null-terminator, writing at most buflen bytes.
// Returns:
// 1  if the working directory was inserted into buf successfully
// 0  if buf is too short to hold the cwd
// -1 if we can't get the cwd for whatever reason.
int fs_get_cwd(char *buf, size_t buflen);

#endif // FILESYSTEM_H_