Subversion Repositories Tewi

Rev

Rev 261 | Rev 315 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 261 Rev 292
Line 1... Line 1...
1
/* $Id: dir.c 261 2024-10-04 23:19:59Z nishi $ */
1
/* $Id: dir.c 292 2024-10-09 10:49:15Z nishi $ */
2
 
2
 
3
#include "cm_dir.h"
3
#include "cm_dir.h"
4
 
4
 
5
#include "cm_string.h"
5
#include "cm_string.h"
6
 
6
 
Line 69... Line 69...
69
#else
69
#else
70
	DIR* dir = opendir(path);
70
	DIR* dir = opendir(path);
71
	if(dir != NULL) {
71
	if(dir != NULL) {
72
		char** r = malloc(sizeof(*r));
72
		char** r = malloc(sizeof(*r));
73
		struct dirent* d;
73
		struct dirent* d;
-
 
74
		char** old;
-
 
75
		int len;
-
 
76
		int i;
74
		r[0] = NULL;
77
		r[0] = NULL;
75
		while((d = readdir(dir)) != NULL) {
78
		while((d = readdir(dir)) != NULL) {
76
			if(strcmp(d->d_name, ".") != 0 && strcmp(d->d_name, "..") != 0) {
79
			if(strcmp(d->d_name, ".") != 0 && strcmp(d->d_name, "..") != 0) {
77
				struct stat s;
80
				struct stat s;
78
				char* p = cm_strcat3(path, "/", d->d_name);
81
				char* p = cm_strcat3(path, "/", d->d_name);
79
				stat(p, &s);
82
				stat(p, &s);
80
				free(p);
83
				free(p);
81
 
84
 
82
				char** old = r;
85
				old = r;
83
				int i;
-
 
84
				for(i = 0; old[i] != NULL; i++)
86
				for(i = 0; old[i] != NULL; i++)
85
					;
87
					;
86
				r = malloc(sizeof(*r) * (i + 2));
88
				r = malloc(sizeof(*r) * (i + 2));
87
				for(i = 0; old[i] != NULL; i++) r[i] = old[i];
89
				for(i = 0; old[i] != NULL; i++) r[i] = old[i];
88
				r[i] = cm_strcat(d->d_name, S_ISDIR(s.st_mode) ? "/" : "");
90
				r[i] = cm_strcat(d->d_name, S_ISDIR(s.st_mode) ? "/" : "");
89
				r[i + 1] = NULL;
91
				r[i + 1] = NULL;
90
				free(old);
92
				free(old);
91
			}
93
			}
92
		}
94
		}
93
		int len;
-
 
94
		for(len = 0; r[len] != NULL; len++)
95
		for(len = 0; r[len] != NULL; len++)
95
			;
96
			;
96
		qsort(r, len, sizeof(char*), cm_sort);
97
		qsort(r, len, sizeof(char*), cm_sort);
97
 
98
 
98
		char** old = r;
99
		old = r;
99
		int i;
-
 
100
		for(i = 0; old[i] != NULL; i++)
100
		for(i = 0; old[i] != NULL; i++)
101
			;
101
			;
102
		r = malloc(sizeof(*r) * (i + 2));
102
		r = malloc(sizeof(*r) * (i + 2));
103
		for(i = 0; old[i] != NULL; i++) r[i + 1] = old[i];
103
		for(i = 0; old[i] != NULL; i++) r[i + 1] = old[i];
104
		r[0] = cm_strdup("../");
104
		r[0] = cm_strdup("../");