use stat() to check if symbolic link 52/170452/2
authorBoram Park <boram1288.park@samsung.com>
Mon, 12 Feb 2018 08:45:11 +0000 (17:45 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Tue, 20 Feb 2018 06:09:34 +0000 (06:09 +0000)
Change-Id: Ie1355c5e54cb7d09a8e9309b2878030ab2f11af3

src/tbm_surface_internal.c

index a18ed01..685e55e 100644 (file)
@@ -371,26 +371,20 @@ _tbm_surface_internal_destroy(tbm_surface_h surface)
 
 /* LCOV_EXCL_START */
 static int
-_tbm_surface_check_file_is_valid(const char* path, int del_link)
+_tbm_surface_check_file_is_symbolic_link(const char* path)
 {
-       char *real_path;
+       struct stat sb;
 
        if (!path)
                return 0;
 
-       real_path = realpath(path, NULL);
-       if (real_path && strncmp(path, real_path, strlen(path))) {
-               if (del_link)
-                       unlink(path);
-               free(real_path);
-
+       if (stat(path, &sb) != 0)
                return 0;
-       }
 
-       if (real_path)
-               free(real_path);
+       if (S_ISLNK(sb.st_mode))
+               return 1;
 
-       return 1;
+       return 0;
 }
 /* LCOV_EXCL_STOP */
 
@@ -1544,7 +1538,7 @@ _tbm_surface_internal_dump_file_raw(const char *file, void *data1, int size1,
        FILE *fp;
        unsigned int *blocks;
 
-       if (!_tbm_surface_check_file_is_valid(file, 1))
+       if (_tbm_surface_check_file_is_symbolic_link(file))
                TBM_LOG_E("%s is symbolic link\n", file);
 
        fp = fopen(file, "w+");
@@ -1575,7 +1569,7 @@ _tbm_surface_internal_dump_file_png(const char *file, const void *data, int widt
        png_bytep *row_pointers;
        int depth = 8, y;
 
-       if (!_tbm_surface_check_file_is_valid(file, 1))
+       if (_tbm_surface_check_file_is_symbolic_link(file))
                TBM_LOG_E("%s is symbolic link\n", file);
 
        fp = fopen(file, "wb");