summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkira TAGOH <akira@tagoh.org>2015-11-09 17:25:24 +0900
committerAkira TAGOH <akira@tagoh.org>2015-11-09 17:26:18 +0900
commitf1d53ff8daa8b95521528efc8aeb9ea796b606de (patch)
tree293c081b2c0c12e6282811c74bd526c4febbc53c
parentab8019a0f5d8089c3b1c916f3d22acc9b5ca61ec (diff)
Fix test fail on SunOS
(fixes issue#10)
-rw-r--r--liblangtag/lt-ext-module.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/liblangtag/lt-ext-module.c b/liblangtag/lt-ext-module.c
index 8108457..f77d565 100644
--- a/liblangtag/lt-ext-module.c
+++ b/liblangtag/lt-ext-module.c
@@ -24,6 +24,7 @@
#if HAVE_LIBGEN_H
#include <libgen.h>
#endif
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -32,6 +33,7 @@
#include "lt-ext-module-data.h"
#include "lt-ext-module.h"
#include "lt-ext-module-private.h"
+#include "lt-lock.h"
#include "lt-utils.h"
@@ -98,6 +100,7 @@ static const lt_ext_module_funcs_t __empty_and_wildcard_funcs = {
_lt_ext_eaw_get_tag,
_lt_ext_eaw_validate_tag,
};
+LT_LOCK_DEFINE_STATIC (extmod);
/*< private >*/
static void
@@ -604,20 +607,29 @@ lt_ext_modules_load(void)
dir = opendir(path);
if (dir) {
- struct dirent dent, *dresult;
- size_t len;
-
- while (1) {
- if (readdir_r(dir, &dent, &dresult) || dresult == NULL)
- break;
-
- len = strlen(dent.d_name);
+ struct dirent *dent, *p;
+
+ LT_LOCK (extmod);
+ while ((dent = readdir (dir))) {
+ size_t len = strlen (dent->d_name);
+ size_t dentlen = offsetof (struct dirent, d_name) + len + 1;
+
+ dentlen = ((dentlen + ALIGNOF_VOID_P - 1) & ~(ALIGNOF_VOID_P - 1));
+ p = (struct dirent *)malloc(dentlen);
+ if (!p) {
+ perror (__FUNCTION__);
+ LT_UNLOCK (extmod);
+ return;
+ }
+ memcpy(p, dent, dentlen);
if (len > suffix_len &&
- lt_strcmp0(&dent.d_name[len - suffix_len],
+ lt_strcmp0(&(p->d_name[len - suffix_len]),
"." LT_MODULE_SUFFIX) == 0) {
- lt_ext_module_new(dent.d_name);
+ lt_ext_module_new(p->d_name);
}
+ free(p);
}
+ LT_UNLOCK (extmod);
closedir(dir);
}
} while (1);