dump: add function to check whether file is link or not
[platform/core/uifw/libtbm.git] / src / tbm_surface_internal.c
index 09c298b..e03570d 100644 (file)
@@ -369,6 +369,29 @@ _tbm_surface_internal_destroy(tbm_surface_h surface)
        }
 }
 
+static int
+_tbm_surface_check_file_is_valid(const char* path, int del_link)
+{
+       char *real_path;
+
+       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);
+
+               return 0;
+       }
+
+       if (real_path)
+               free(real_path);
+
+       return 1;
+}
+
 int
 tbm_surface_internal_is_valid(tbm_surface_h surface)
 {
@@ -1502,10 +1525,15 @@ static void
 _tbm_surface_internal_dump_file_raw(const char *file, void *data1, int size1,
                                void *data2, int size2, void *data3, int size3)
 {
-       FILE *fp = fopen(file, "w+");
-       TBM_RETURN_IF_FAIL(fp != NULL);
+       FILE *fp;
        unsigned int *blocks;
 
+       if (!_tbm_surface_check_file_is_valid(file, 1))
+               TBM_LOG_E("%s is symbolic link\n", file);
+
+       fp = fopen(file, "w+");
+       TBM_RETURN_IF_FAIL(fp != NULL);
+
        blocks = (unsigned int *)data1;
        fwrite(blocks, 1, size1, fp);
 
@@ -1526,12 +1554,17 @@ static void
 _tbm_surface_internal_dump_file_png(const char *file, const void *data, int width, int height)
 {
        unsigned int *blocks = (unsigned int *)data;
-       FILE *fp = fopen(file, "wb");
-       TBM_RETURN_IF_FAIL(fp != NULL);
+       FILE *fp;
        const int pixel_size = 4;       // RGBA
        png_bytep *row_pointers;
        int depth = 8, y;
 
+       if (!_tbm_surface_check_file_is_valid(file, 1))
+               TBM_LOG_E("%s is symbolic link\n", file);
+
+       fp = fopen(file, "wb");
+       TBM_RETURN_IF_FAIL(fp != NULL);
+
        png_structp pPngStruct = png_create_write_struct(PNG_LIBPNG_VER_STRING,
                                                        NULL, NULL, NULL);
        if (!pPngStruct) {