]> Nishi Git Mirror - tewi.git/commitdiff
c89
authorNishi <nishi@nishi.boats>
Wed, 9 Oct 2024 10:49:15 +0000 (10:49 +0000)
committerNishi <nishi@nishi.boats>
Wed, 9 Oct 2024 10:49:15 +0000 (10:49 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@292 8739d7e6-ffea-ec47-b151-bdff447c6205

Common/dir.c

index 716f6e29ceb0f8fadd38c1042b7f2f7c6fd134c6..0a276874d237db85f1b3077b1d2f389fd8889ba1 100644 (file)
@@ -71,6 +71,9 @@ char** cm_scandir(const char* path) {
        if(dir != NULL) {
                char** r = malloc(sizeof(*r));
                struct dirent* d;
+               char** old;
+               int len;
+               int i;
                r[0] = NULL;
                while((d = readdir(dir)) != NULL) {
                        if(strcmp(d->d_name, ".") != 0 && strcmp(d->d_name, "..") != 0) {
@@ -79,8 +82,7 @@ char** cm_scandir(const char* path) {
                                stat(p, &s);
                                free(p);
 
-                               char** old = r;
-                               int i;
+                               old = r;
                                for(i = 0; old[i] != NULL; i++)
                                        ;
                                r = malloc(sizeof(*r) * (i + 2));
@@ -90,13 +92,11 @@ char** cm_scandir(const char* path) {
                                free(old);
                        }
                }
-               int len;
                for(len = 0; r[len] != NULL; len++)
                        ;
                qsort(r, len, sizeof(char*), cm_sort);
 
-               char** old = r;
-               int i;
+               old = r;
                for(i = 0; old[i] != NULL; i++)
                        ;
                r = malloc(sizeof(*r) * (i + 2));