haptic: Remove strerror, readdir usecase which are not thread-safe. 96/52396/2
authorpr.jung <pr.jung@samsung.com>
Fri, 20 Nov 2015 07:47:11 +0000 (16:47 +0900)
committerJung <pr.jung@samsung.com>
Wed, 25 Nov 2015 09:11:59 +0000 (01:11 -0800)
Change-Id: I99e6577fbb1ef095ad5437ca0ceeabb15b3918d4
Signed-off-by: pr.jung <pr.jung@samsung.com>
src/haptic/standard.c
src/libdeviced/haptic.c

index 4171ba1..c43b130 100644 (file)
@@ -158,6 +158,7 @@ static Eina_Bool timer_cb(void *data)
 static int ff_find_device(void)
 {
        DIR *dir;
+       struct dirent entry;
        struct dirent *dent;
        char ev_path[PATH_MAX];
        unsigned long features[1+FF_MAX/sizeof(unsigned long)];
@@ -167,7 +168,11 @@ static int ff_find_device(void)
        if (!dir)
                return -errno;
 
-       while ((dent = readdir(dir))) {
+       while (1) {
+               ret = readdir_r(dir, &entry, &dent);
+               if (ret != 0 || dent == NULL)
+                       break;
+
                if (dent->d_type == DT_DIR ||
                        !strstr(dent->d_name, "event"))
                        continue;
@@ -332,7 +337,7 @@ static int open_device(int device_index, int *device_handle)
                /* open ff driver */
                ff_fd = open(ff_path, O_RDWR);
                if (!ff_fd) {
-                       _E("Failed to open %s : %s", ff_path, strerror(errno));
+                       _E("Failed to open %s : %d", ff_path, errno);
                        return -errno;
                }
        }
@@ -340,7 +345,7 @@ static int open_device(int device_index, int *device_handle)
        /* allocate memory */
        info = calloc(sizeof(struct ff_info), 1);
        if (!info) {
-               _E("Failed to allocate memory : %s", strerror(errno));
+               _E("Failed to allocate memory : %d", errno);
                return -errno;
        }
 
index 528b5d1..255ae9d 100644 (file)
@@ -20,7 +20,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <string.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -60,7 +59,7 @@ static unsigned char *convert_file_to_buffer(const char *file_name, int *size)
        /* Get File Stream Pointer */
        pf = fopen(file_name, "rb");
        if (!pf) {
-               _E("fopen failed : %s", strerror(errno));
+               _E("fopen failed : %d", errno);
                return NULL;
        }
 
@@ -91,7 +90,7 @@ err_free:
 error:
        fclose(pf);
 
-       _E("failed to convert file to buffer (%s)", strerror(errno));
+       _E("failed to convert file to buffer (%d)", errno);
        return NULL;
 }
 
@@ -102,25 +101,25 @@ static int save_data(const unsigned char *data, int size, const char *file_path)
 
        file = fopen(file_path, "wb+");
        if (file == NULL) {
-               _E("To open file is failed : %s", strerror(errno));
+               _E("To open file is failed : %d", errno);
                return -1;
        }
 
        if (fwrite(data, 1, size, file) != size) {
-               _E("To write file is failed : %s", strerror(errno));
+               _E("To write file is failed : %d", errno);
                fclose(file);
                return -1;
        }
 
        fd = fileno(file);
        if (fd < 0) {
-               _E("To get file descriptor is failed : %s", strerror(errno));
+               _E("To get file descriptor is failed : %d", errno);
                fclose(file);
                return -1;
        }
 
        if (fsync(fd) < 0) {
-               _E("To be synchronized with the disk is failed : %s", strerror(errno));
+               _E("To be synchronized with the disk is failed : %d", errno);
                fclose(file);
                return -1;
        }