Subversion Repositories Tewi

Rev

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

Rev 150 Rev 212
Line 1... Line 1...
1
/* $Id: dir.c 150 2024-09-24 20:15:17Z nishi $ */
1
/* $Id: dir.c 212 2024-10-02 17:44:55Z 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
 
7
#include <sys/stat.h>
7
#include <sys/stat.h>
-
 
8
#ifndef _MSC_VER
8
#include <dirent.h>
9
#include <dirent.h>
-
 
10
#endif
9
#include <stdlib.h>
11
#include <stdlib.h>
10
#include <string.h>
12
#include <string.h>
11
 
13
 
12
int cm_sort(const void* _a, const void* _b) {
14
int cm_sort(const void* _a, const void* _b) {
13
	char* a = *(char**)_a;
15
	char* a = *(char**)_a;
14
	char* b = *(char**)_b;
16
	char* b = *(char**)_b;
15
	return strcmp(a, b);
17
	return strcmp(a, b);
16
}
18
}
17
 
19
 
18
char** cm_scandir(const char* path) {
20
char** cm_scandir(const char* path) {
-
 
21
#ifdef _MSC_VER
-
 
22
	return NULL;
-
 
23
#else
19
	DIR* dir = opendir(path);
24
	DIR* dir = opendir(path);
20
	if(dir != NULL) {
25
	if(dir != NULL) {
21
		char** r = malloc(sizeof(*r));
26
		char** r = malloc(sizeof(*r));
22
		r[0] = NULL;
-
 
23
		struct dirent* d;
27
		struct dirent* d;
-
 
28
		r[0] = NULL;
24
		while((d = readdir(dir)) != NULL) {
29
		while((d = readdir(dir)) != NULL) {
25
			if(strcmp(d->d_name, ".") != 0 && strcmp(d->d_name, "..") != 0) {
30
			if(strcmp(d->d_name, ".") != 0 && strcmp(d->d_name, "..") != 0) {
26
				struct stat s;
31
				struct stat s;
27
				char* p = cm_strcat3(path, "/", d->d_name);
32
				char* p = cm_strcat3(path, "/", d->d_name);
28
				stat(p, &s);
33
				stat(p, &s);
Line 58... Line 63...
58
 
63
 
59
		return r;
64
		return r;
60
	} else {
65
	} else {
61
		return NULL;
66
		return NULL;
62
	}
67
	}
-
 
68
#endif
63
}
69
}