Changeset 255 in Main for trunk/Common/dir.c
- Timestamp:
- Oct 4, 2024, 1:08:58 PM (6 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/dir.c
r219 r255 22 22 char** cm_scandir(const char* path) { 23 23 #if defined(_MSC_VER) || defined(__BORLANDC__) 24 return NULL; 24 WIN32_FIND_DATA ffd; 25 HANDLE hfind; 26 char** r = malloc(sizeof(*r)); 27 int len; 28 char** old; 29 int i; 30 char* p; 31 r[0] = NULL; 32 33 p = cm_strcat(path, "/*"); 34 hfind = FindFirstFile(p, &ffd); 35 if(INVALID_HANDLE_VALUE == hfind) { 36 return NULL; 37 } 38 do { 39 if(strcmp(ffd.cFileName, ".") != 0 && strcmp(ffd.cFileName, "..") != 0) { 40 old = r; 41 for(i = 0; old[i] != NULL; i++) 42 ; 43 r = malloc(sizeof(*r) * (i + 2)); 44 for(i = 0; old[i] != NULL; i++) r[i] = old[i]; 45 r[i] = cm_strcat(ffd.cFileName, (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? "/" : ""); 46 r[i + 1] = NULL; 47 free(old); 48 } 49 } while(FindNextFile(hfind, &ffd) != 0); 50 FindClose(hfind); 51 free(p); 52 for(len = 0; r[len] != NULL; len++) 53 ; 54 qsort(r, len, sizeof(char*), cm_sort); 55 56 old = r; 57 for(i = 0; old[i] != NULL; i++) 58 ; 59 r = malloc(sizeof(*r) * (i + 2)); 60 for(i = 0; old[i] != NULL; i++) r[i + 1] = old[i]; 61 r[0] = cm_strdup("../"); 62 r[i + 1] = NULL; 63 free(old); 64 65 return r; 25 66 #else 26 67 DIR* dir = opendir(path);
Note:
See TracChangeset
for help on using the changeset viewer.