aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/main.c b/src/main.c
index 4aaafac..3fd58a6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,6 +3,7 @@
#include <time.h>
#include <assert.h>
#include <dirent.h>
+#include <sys/stat.h>
#include <string.h>
#include <raylib.h>
@@ -20,6 +21,18 @@
#define TRUE 1
//-----------------------------------------------
+// Is directory
+bool_t is_directory(char* dirname) {
+ struct stat st;
+ if (stat(dirname, &st) == 0) {
+ if (S_ISDIR(st.st_mode)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+//-----------------------------------------------
// List directory
char** lsdir(char* dirname) {
DIR *d;
@@ -145,18 +158,20 @@ int main(int argc, char** argv)
free(file_list);
}
if (argc > 1) {
- file_list = lsdir(argv[1]);
- if (file_list) {
- size_t index = 0;
- while (1) {
- char* fname = file_list[index];
- if (fname == NULL) {
- break;
+ if (is_directory(argv[1])) {
+ file_list = lsdir(argv[1]);
+ 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++]);
}
- printf("%s\n", fname);
- free(file_list[index++]);
+ free(file_list);
}
- free(file_list);
}
}
//-----------------------------------------------