diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 51 |
1 files changed, 51 insertions, 0 deletions
@@ -2,6 +2,8 @@ #include <stdlib.h> #include <time.h> #include <assert.h> +#include <dirent.h> +#include <string.h> #include <raylib.h> @@ -18,6 +20,37 @@ #define TRUE 1 //----------------------------------------------- +// List directory +char** lsdir(char* dirname) { + DIR *d; + struct dirent *dir; + d = opendir(dirname); + char** file_names = (char**)malloc(sizeof(char*)); + if (!file_names) { + return NULL; + } + file_names[0] = NULL; + size_t file_count = 0; + if (d) { + while ((dir = readdir(d)) != NULL) { + if (dir->d_type == DT_REG) { + // When a regular file is reached + /// Create space for it in the list + file_names = realloc(file_names, (file_count+1+1)*sizeof(char*)); + /// Create space for the name + file_names[file_count] = calloc(strlen(dir->d_name)+1, sizeof(char)); + /// Copy the name + strcpy(file_names[file_count], dir->d_name); + /// Mark the end of the file list with a NULL entry + file_names[++file_count] = NULL; + } + } + return file_names; + } + return NULL; +} + +//----------------------------------------------- // Difference in Time // Compute the difference between timespec structs double diff_timespec(struct timespec *time1, struct timespec *time0) { @@ -96,6 +129,24 @@ bool_t flood(uint8_t* image, uint16_t* mask, size_t width, size_t height, size_t int main() { //----------------------------------------------- + //-LIST-FILES-IN-DIRECTORY----------------------- + //----------------------------------------------- + char** file_list = lsdir("data/"); + if (file_list) { + size_t index = 0; + while (1) { + char* fname = file_list[index]; + if (fname == NULL) { + break; + } + printf("%s\n", fname); + free(file_list[index++]); + } + free(file_list); + } + //----------------------------------------------- + + //----------------------------------------------- //-RAYLIB-INIT //----------------------------------------------- SetTraceLogLevel(LOG_ERROR); |