-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0001-src-filemanager-dir.c-refactored-growing-of-dir_list.patch
97 lines (88 loc) · 2.76 KB
/
0001-src-filemanager-dir.c-refactored-growing-of-dir_list.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
From 56be1a791643eedc47a7f62869223907b84cacd6 Mon Sep 17 00:00:00 2001
From: "Yury V. Zaytsev" <yury@shurup.com>
Date: Sun, 28 Oct 2012 12:05:27 +0100
Subject: [PATCH] src/filemanager/dir.c: refactored growing of dir_list into a
separate function
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
---
src/filemanager/dir.c | 51 ++++++++++++++++++++++++++++---------------------
1 file changed, 29 insertions(+), 22 deletions(-)
diff --git a/src/filemanager/dir.c b/src/filemanager/dir.c
index afc63d3..6406e6c 100644
--- a/src/filemanager/dir.c
+++ b/src/filemanager/dir.c
@@ -133,6 +133,27 @@ clean_sort_keys (dir_list * list, int start, int count)
/* --------------------------------------------------------------------------------------------- */
/**
+ * @returns FALSE = failure, TRUE = success
+ */
+
+static gboolean
+grow_list (dir_list * list)
+{
+ if (list == NULL)
+ return FALSE;
+
+ list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS));
+
+ if (list->list == NULL)
+ return FALSE;
+
+ list->size += RESIZE_STEPS;
+
+ return TRUE;
+}
+
+/* --------------------------------------------------------------------------------------------- */
+/**
* If you change handle_dirent then check also handle_path.
* @returns -1 = failure, 0 = don't add, 1 = add to the list
*/
@@ -183,13 +204,9 @@ handle_dirent (dir_list * list, const char *fltr, struct dirent *dp,
return 0;
/* Need to grow the *list? */
- if (next_free == list->size)
- {
- list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS));
- if (list->list == NULL)
- return -1;
- list->size += RESIZE_STEPS;
- }
+ if (next_free == list->size && !grow_list (list))
+ return -1;
+
return 1;
}
@@ -456,14 +473,8 @@ gboolean
set_zero_dir (dir_list * list)
{
/* Need to grow the *list? */
- if (list->size == 0)
- {
- list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS));
- if (list->list == NULL)
- return FALSE;
-
- list->size += RESIZE_STEPS;
- }
+ if (!list->size && !grow_list (list))
+ return FALSE;
memset (&(list->list)[0], 0, sizeof (file_entry));
list->list[0].fnamelen = 2;
@@ -521,13 +532,9 @@ handle_path (dir_list * list, const char *path,
vfs_path_free (vpath);
/* Need to grow the *list? */
- if (next_free == list->size)
- {
- list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS));
- if (list->list == NULL)
- return -1;
- list->size += RESIZE_STEPS;
- }
+ if (next_free == list->size && !grow_list (list))
+ return -1;
+
return 1;
}
--
1.7.10