Skip to content

Commit

Permalink
gral_file_remove and gral_directory_remove
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Nov 20, 2023
1 parent 8865ca8 commit 70424d3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gral.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ size_t gral_file_get_size(struct gral_file *file);
void *gral_file_map(struct gral_file *file, size_t size);
void gral_file_unmap(void *address, size_t size);
void gral_file_rename(char const *old_path, char const *new_path);
void gral_file_remove(char const *path);
void gral_directory_iterate(char const *path, void (*callback)(char const *name, void *user_data), void *user_data);
void gral_directory_remove(char const *path);


/*=========
Expand Down
8 changes: 8 additions & 0 deletions gral_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@ void gral_file_rename(char const *old_path, char const *new_path) {
rename(old_path, new_path);
}

void gral_file_remove(char const *path) {
unlink(path);
}

void gral_directory_iterate(char const *path, void (*callback)(char const *name, void *user_data), void *user_data) {
DIR *directory = opendir(path);
struct dirent *entry;
Expand All @@ -756,6 +760,10 @@ void gral_directory_iterate(char const *path, void (*callback)(char const *name,
closedir(directory);
}

void gral_directory_remove(char const *path) {
rmdir(path);
}


/*=========
TIME
Expand Down
8 changes: 8 additions & 0 deletions gral_macos.m
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,10 @@ void gral_file_rename(char const *old_path, char const *new_path) {
rename(old_path, new_path);
}

void gral_file_remove(char const *path) {
unlink(path);
}

void gral_directory_iterate(char const *path, void (*callback)(char const *name, void *user_data), void *user_data) {
DIR *directory = opendir(path);
struct dirent *entry;
Expand All @@ -791,6 +795,10 @@ void gral_directory_iterate(char const *path, void (*callback)(char const *name,
closedir(directory);
}

void gral_directory_remove(char const *path) {
rmdir(path);
}


/*=========
TIME
Expand Down
8 changes: 8 additions & 0 deletions gral_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,10 @@ void gral_file_rename(char const *old_path, char const *new_path) {
MoveFileEx(utf8_to_utf16(old_path), utf8_to_utf16(new_path), MOVEFILE_REPLACE_EXISTING);
}

void gral_file_remove(char const *path) {
DeleteFile(utf8_to_utf16(path));
}

void gral_directory_iterate(char const *path_utf8, void (*callback)(char const *name, void *user_data), void *user_data) {
int length = MultiByteToWideChar(CP_UTF8, 0, path_utf8, -1, NULL, 0);
Buffer<wchar_t> path_utf16(length + 2);
Expand All @@ -1159,6 +1163,10 @@ void gral_directory_iterate(char const *path_utf8, void (*callback)(char const *
FindClose(handle);
}

void gral_directory_remove(char const *path) {
RemoveDirectory(utf8_to_utf16(path));
}


/*=========
TIME
Expand Down

0 comments on commit 70424d3

Please sign in to comment.