From: jiyong.min Date: Thu, 31 Oct 2019 01:28:43 +0000 (+0900) Subject: Replace open(system call) to access(std.) X-Git-Tag: submit/tizen/20191110.224221^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4745bc0a920bc246763267866e25db6702e659ca;p=platform%2Fcore%2Fapi%2Fimage-util.git Replace open(system call) to access(std.) - When open() without O_CREAT, executable program can't create file due to 'Permission Denied'. Just it happened in shell enviroment. - The access() is standard function to check path permission. Change-Id: I5f4f2bf00c0e6a21b36c1c39261008e5035113fe --- diff --git a/include/image_util_private.h b/include/image_util_private.h index 67277c8..066e5e4 100644 --- a/include/image_util_private.h +++ b/include/image_util_private.h @@ -210,7 +210,7 @@ unsigned int _get_number_of_colorspace(void); int _convert_type_of_colorspace(const image_util_colorspace_e colorspace); int _convert_type_of_colorspace_with_image_type(const image_util_colorspace_e colorspace, const image_util_type_e type); -int _check_valid_file(const char *path, int mode); +int _check_encode_path(const char *path); int _image_error_capi(int error_code); int _image_util_image_to_packet(image_util_image_h image, media_packet_h *packet); diff --git a/src/image_util_encode.c b/src/image_util_encode.c index dc9d6b4..9bf4924 100644 --- a/src/image_util_encode.c +++ b/src/image_util_encode.c @@ -365,7 +365,7 @@ static int __image_util_encode_run_to_file(image_util_encode_h handle, image_uti image_util_retvm_if(!_handle, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle"); image_util_retvm_if(!image, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image"); - ret = _check_valid_file(file_path, O_WRONLY); + ret = _check_encode_path(file_path); image_util_retvm_if(ret != IMAGE_UTIL_ERROR_NONE, ret, "_check_valid_file failed (%d)", ret); image_util_sec_debug("Image type [%d]. Save to file_path [%s]", _handle->image_type, file_path); @@ -575,7 +575,7 @@ int image_util_encode_run_async_to_file(image_util_encode_h handle, image_util_i image_util_retvm_if(!_handle, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle"); image_util_retvm_if(!image, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image"); image_util_retvm_if(!completed_cb, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid completed_cb"); - ret = _check_valid_file(file_path, O_WRONLY); + ret = _check_encode_path(file_path); image_util_retvm_if(ret != IMAGE_UTIL_ERROR_NONE, ret, "_check_valid_file failed (%d)", ret); image_util_fenter(); diff --git a/src/image_util_private.c b/src/image_util_private.c index 1d5f883..9435e0c 100755 --- a/src/image_util_private.c +++ b/src/image_util_private.c @@ -214,27 +214,27 @@ int _convert_type_of_colorspace_with_image_type(const image_util_colorspace_e co return new_colorspace; } -int _check_valid_file(const char *path, int mode) +int _check_encode_path(const char *path) { - int ret = IMAGE_UTIL_ERROR_NONE; - int fd = 0; + int ret = 0; + char *dirname = NULL; image_util_retvm_if(!path, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid path"); - fd = open(path, mode); + dirname = g_path_get_dirname(path); + image_util_retvm_if(!dirname, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid path"); - if (fd < 0) { + if (access(dirname, W_OK) != 0) { if (errno == EACCES || errno == EPERM) { - image_util_error("Fail to open path[%s]: Permission Denied", path); + image_util_error("Fail to access path[%s]: Permission Denied", path); ret = IMAGE_UTIL_ERROR_PERMISSION_DENIED; } else { - image_util_error("Fail to open path[%s]: Invalid Path", path); + image_util_error("Fail to access path[%s]: Invalid Path", path); ret = IMAGE_UTIL_ERROR_INVALID_PARAMETER; } - } else { - close(fd); } + g_free(dirname); return ret; }