summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-10-02 15:56:24 +0200
committerAnton Kling <anton@kling.gg>2024-10-02 16:12:29 +0200
commit5a7640af235a2068c233ce47a56d74defd4c2f0e (patch)
tree5afbb84519a46dc1129d4de7d93f65b56e4cb7e2 /include
parent44848d566066dbea008eecf4c2b9916f051bad06 (diff)
libc: Add faster scandir function(scandir_sane).
This function is significantly faster due to not requiring memory allocations for each directory entry. Now they are instead just allocated as a large chunk. This function is not compatible with scandir since the cleanup of both function will be different. With this a new function scandir_sane_free has also been added. Besides having a function(like scandir) that forces the programmer to implement their own cleanup procedure that is anymore complicated than a simple free() call is absurd.
Diffstat (limited to 'include')
-rw-r--r--include/dirent.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/include/dirent.h b/include/dirent.h
index 53b3f70..b986ddb 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -7,7 +7,7 @@
#ifndef KERNEL
#include <fcntl.h>
#include <unistd.h>
-#endif
+#endif // KERNEL
struct dirent {
ino_t d_ino; // File serial number.
@@ -20,6 +20,7 @@ typedef struct {
int dir_num;
} DIR;
+#ifndef KERNEL
DIR *opendir(const char *dirname);
struct dirent *readdir(DIR *dir);
int closedir(DIR *dirp);
@@ -27,4 +28,10 @@ int alphasort(const struct dirent **d1, const struct dirent **d2);
int scandir(const char *dir, struct dirent ***namelist,
int (*sel)(const struct dirent *),
int (*compar)(const struct dirent **, const struct dirent **));
-#endif
+int scandir_sane(const char *dir, struct dirent ***namelist,
+ int (*sel)(const struct dirent *),
+ int (*compar)(const struct dirent **,
+ const struct dirent **));
+void scandir_sane_free(struct dirent **namelist);
+#endif // KERNEL
+#endif // DIRENT_H