From a85c08286ddf9b224cbca72125b72d103196e666 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Mon, 12 Feb 2018 17:45:11 +0900 Subject: [PATCH] use stat() to check if symbolic link Change-Id: Ie1355c5e54cb7d09a8e9309b2878030ab2f11af3 --- src/tbm_surface_internal.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/tbm_surface_internal.c b/src/tbm_surface_internal.c index a18ed01..685e55e 100644 --- a/src/tbm_surface_internal.c +++ b/src/tbm_surface_internal.c @@ -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"); -- 2.7.4