-
Notifications
You must be signed in to change notification settings - Fork 1
/
0001-mx-create-image-cache-Use-GDir-instead-of-opendir.patch
73 lines (66 loc) · 2.19 KB
/
0001-mx-create-image-cache-Use-GDir-instead-of-opendir.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
From 3856e8890223c523dd01371c041ce0c682343680 Mon Sep 17 00:00:00 2001
From: Neil Roberts <[email protected]>
Date: Wed, 3 Aug 2011 14:36:23 +0100
Subject: [PATCH 1/3] mx-create-image-cache: Use GDir instead of opendir
Instead of using opendir in libc directly, it now uses GDir. The
contents of struct dirent aren't guarenteed so this makes it easier to
compile on systems such as Windows which don't have the d_type member.
---
mx/mx-create-image-cache.c | 36 +++++++++++++++++++-----------------
1 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/mx/mx-create-image-cache.c b/mx/mx-create-image-cache.c
index 0983a06..cd682ca 100644
--- a/mx/mx-create-image-cache.c
+++ b/mx/mx-create-image-cache.c
@@ -379,34 +379,36 @@ static int make_final_image(char *filename)
static void makecache(char *directory,
int recurse)
{
- DIR *dir;
+ GDir *dir;
+ GError *error = NULL;
- struct dirent *entry;
-
- dir = opendir(directory);
+ dir = g_dir_open (directory, 0, &error);
if (!dir) {
- printf("Directory %s not found!\n", directory);
+ printf("Error opening %s: %s\n", directory, error->message);
+ g_clear_error (&error);
return;
}
- do {
- entry = readdir(dir);
- if (!entry)
+
+ while (TRUE) {
+ const char *name = g_dir_read_name (dir);
+ char *fullpath = g_build_filename (directory, name, NULL);
+
+ if (!name)
break;
- if (entry->d_name[0] == '.')
+ if (name[0] == '.')
continue;
- if (entry->d_type == DT_DIR && recurse) {
- char newdir[2*PATH_MAX];
- sprintf(newdir, "%s/%s", directory, entry->d_name);
- makecache(newdir, recurse);
+ if (recurse && g_file_test (fullpath, G_FILE_TEST_IS_DIR)) {
+ makecache(fullpath, recurse);
}
- if (entry->d_type == DT_REG) {
- char fullpath[2*PATH_MAX];
- sprintf(fullpath, "%s/%s", directory, entry->d_name);
+ if (recurse && g_file_test (fullpath, G_FILE_TEST_IS_REGULAR)) {
do_one_file(fullpath);
}
- } while (entry);
+ g_free (fullpath);
+ }
+
+ g_dir_close (dir);
images = g_list_sort(images, sort_by_size);
}
--
1.7.3.16.g9464b