diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 35 | 
1 files changed, 25 insertions, 10 deletions
| @@ -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);      }    }    //----------------------------------------------- | 
