chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8309648
)
util: use readdir_r() instead of readdir()
author
Lennart Poettering
<lennart@poettering.net>
Fri, 22 Jul 2011 02:25:25 +0000
(
04:25
+0200)
committer
Lennart Poettering
<lennart@poettering.net>
Fri, 22 Jul 2011 02:31:21 +0000
(
04:31
+0200)
src/util.c
patch
|
blob
|
history
diff --git
a/src/util.c
b/src/util.c
index 4e441a7dbe5310cc429ca079a0b765053fcada76..328a1ead922b7e37778e4b93941d09b12f83894f 100644
(file)
--- a/
src/util.c
+++ b/
src/util.c
@@
-4801,7
+4801,7
@@
static int file_is_conf(const struct dirent *d, const char *suffix) {
static int files_add(Hashmap *h, const char *path, const char *suffix) {
DIR *dir;
static int files_add(Hashmap *h, const char *path, const char *suffix) {
DIR *dir;
- struct dirent *de;
+ struct dirent
buffer,
*de;
int r = 0;
dir = opendir(path);
int r = 0;
dir = opendir(path);
@@
-4811,9
+4811,18
@@
static int files_add(Hashmap *h, const char *path, const char *suffix) {
return -errno;
}
return -errno;
}
- for (de = readdir(dir); de; de = readdir(dir)) {
+ for (;;) {
+ int k;
char *p, *f;
char *p, *f;
- const char *base;
+
+ k = readdir_r(dir, &buffer, &de);
+ if (k != 0) {
+ r = -k;
+ goto finish;
+ }
+
+ if (!de)
+ break;
if (!file_is_conf(de, suffix))
continue;
if (!file_is_conf(de, suffix))
continue;
@@
-4832,8
+4841,7
@@
static int files_add(Hashmap *h, const char *path, const char *suffix) {
free(p);
log_debug("found: %s\n", f);
free(p);
log_debug("found: %s\n", f);
- base = f + strlen(path) + 1;
- if (hashmap_put(h, base, f) <= 0)
+ if (hashmap_put(h, file_name_from_path(f), f) <= 0)
free(f);
}
free(f);
}