X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Flocale-root.c;h=ece4456f6b82b8fad2a68a7a7e8427c583a135ed;hb=4a3d0c568ec5ee1296f4a50f269a1eadc4898e27;hp=ead820b4d4cad8b252b8c1423f11b2dbe8f2f2dd;hpb=335959621b8ffa33f66f55e0dea1c08aaea75775;p=src%2Fapp-framework-binder.git diff --git a/src/locale-root.c b/src/locale-root.c index ead820b4..ece4456f 100644 --- a/src/locale-root.c +++ b/src/locale-root.c @@ -214,7 +214,7 @@ static int init_container(struct locale_container *container, int dirfd) { int rc, sfd; DIR *dir; - struct dirent dent, *e; + struct dirent *dent; struct stat st; size_t i, j; struct locale_folder *f; @@ -239,23 +239,21 @@ static int init_container(struct locale_container *container, int dirfd) /* enumerate the entries */ for(;;) { /* next entry */ - rc = readdir_r(dir, &dent, &e); - if (rc < 0) { - /* error */ - closedir(dir); - return rc; - } - if (e == NULL) { + errno = 0; + dent = readdir(dir); + if (dent == NULL) { /* end of entries */ closedir(dir); + if (errno != 0) + return -1; break; } - if (dent.d_type == DT_DIR || (dent.d_type == DT_UNKNOWN && fstatat(sfd, dent.d_name, &st, 0) == 0 && S_ISDIR(st.st_mode))) { + if (dent->d_type == DT_DIR || (dent->d_type == DT_UNKNOWN && fstatat(sfd, dent->d_name, &st, 0) == 0 && S_ISDIR(st.st_mode))) { /* directory aka folder */ - if (dent.d_name[0] == '.' && (dent.d_name[1] == 0 || (dent.d_name[1] == '.' && dent.d_name[2] == 0))) { + if (dent->d_name[0] == '.' && (dent->d_name[1] == 0 || (dent->d_name[1] == '.' && dent->d_name[2] == 0))) { /* nothing to do for special directories, basic detection, improves if needed */ } else { - rc = add_folder(container, dent.d_name); + rc = add_folder(container, dent->d_name); if (rc < 0) { closedir(dir); return rc; @@ -333,7 +331,7 @@ struct locale_root *locale_root_create_at(int dirfd, const char *path) */ struct locale_root *locale_root_addref(struct locale_root *root) { - root->refcount++; + __atomic_add_fetch(&root->refcount, 1, __ATOMIC_RELAXED); return root; } @@ -343,7 +341,7 @@ struct locale_root *locale_root_addref(struct locale_root *root) */ static void internal_unref(struct locale_root *root) { - if (!--root->intcount) { + if (!__atomic_sub_fetch(&root->intcount, 1, __ATOMIC_RELAXED)) { clear_container(&root->container); close(root->rootfd); free(root); @@ -358,7 +356,7 @@ void locale_root_unref(struct locale_root *root) { size_t i; - if (root != NULL && !--root->refcount) { + if (root && !__atomic_sub_fetch(&root->refcount, 1, __ATOMIC_RELAXED)) { /* clear circular references through searchs */ for (i = 0 ; i < LRU_COUNT ; i++) locale_search_unref(root->lru[i]); @@ -422,7 +420,7 @@ static struct locale_search *create_search(struct locale_root *root, const char errno = ENOMEM; } else { /* init */ - root->intcount++; + __atomic_add_fetch(&root->intcount, 1, __ATOMIC_RELAXED); search->root = root; search->head = NULL; search->refcount = 1; @@ -543,7 +541,7 @@ struct locale_search *locale_root_search(struct locale_root *root, const char *d */ struct locale_search *locale_search_addref(struct locale_search *search) { - search->refcount++; + __atomic_add_fetch(&search->refcount, 1, __ATOMIC_RELAXED); return search; } @@ -554,7 +552,7 @@ void locale_search_unref(struct locale_search *search) { struct locale_search_node *it, *nx; - if (search && !--search->refcount) { + if (search && !__atomic_sub_fetch(&search->refcount, 1, __ATOMIC_RELAXED)) { it = search->head; while(it != NULL) { nx = it->next;