Changeset 22 in Main for trunk/Common/dir.c
- Timestamp:
- Sep 14, 2024, 10:25:38 PM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/dir.c
r21 r22 10 10 #include <string.h> 11 11 12 int cm_sort(const void* _a, const void* _b) {12 int cm_sort(const void* _a, const void* _b) { 13 13 char* a = *(char**)_a; 14 14 char* b = *(char**)_b; … … 16 16 } 17 17 18 char** cm_scandir(const char* path) {18 char** cm_scandir(const char* path) { 19 19 DIR* dir = opendir(path); 20 if(dir != NULL) {20 if(dir != NULL) { 21 21 char** r = malloc(sizeof(*r)); 22 22 r[0] = NULL; 23 23 struct dirent* d; 24 while((d = readdir(dir)) != NULL) {25 if(strcmp(d->d_name, ".") != 0 ){24 while((d = readdir(dir)) != NULL) { 25 if(strcmp(d->d_name, ".") != 0 && strcmp(d->d_name, "..") != 0) { 26 26 struct stat s; 27 27 char* p = cm_strcat3(path, "/", d->d_name); … … 31 31 char** old = r; 32 32 int i; 33 for(i = 0; old[i] != NULL; i++); 33 for(i = 0; old[i] != NULL; i++) 34 ; 34 35 r = malloc(sizeof(*r) * (i + 2)); 35 36 for(i = 0; old[i] != NULL; i++) r[i] = old[i]; … … 40 41 } 41 42 int len; 42 for(len = 0; r[len] != NULL; len++); 43 for(len = 0; r[len] != NULL; len++) 44 ; 43 45 qsort(r, len, sizeof(char*), cm_sort); 46 47 char** old = r; 48 int i; 49 for(i = 0; old[i] != NULL; i++) 50 ; 51 r = malloc(sizeof(*r) * (i + 2)); 52 for(i = 0; old[i] != NULL; i++) r[i + 1] = old[i]; 53 r[0] = cm_strdup("../"); 54 r[i + 1] = NULL; 55 free(old); 56 44 57 return r; 45 } else{58 } else { 46 59 return NULL; 47 60 }
Note:
See TracChangeset
for help on using the changeset viewer.