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);
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);
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();
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;
}