int length = g_list_length(*query_list);
char *sql = NULL;
char query_bundle[MEDIA_SVC_QUERY_LEN_MAX] = {0, };
- int query_len = 0;
- int total_len = 0;
+ unsigned int query_len = 0;
+ unsigned int total_len = 0;
media_svc_debug("query list length : [%d]", length);
query_len = strlen(sql);
if (query_len >= (sizeof(query_bundle) - 1)) {
- media_svc_error("NEED TO CHECK FILE : A single query size exceeds 8k [%d]", query_len);
+ media_svc_error("NEED TO CHECK FILE : A single query size exceeds 8k [%u]", query_len);
SQLITE3_SAFE_FREE(sql);
continue;
}
static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
+ struct statfs fs;
+ char *thumb_path = NULL;
+ long bsize_kbytes = 0;
+ GError *error = NULL;
+ media_svc_retvm_if(!image || size == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid image");
media_svc_sec_debug("start save image, path [%s] image size [%d]", image_path, size);
- if (!image) {
- media_svc_error("invalid image..");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- struct statfs fs;
- char *thumb_path = NULL;
ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
-
- if (-1 == statfs(thumb_path, &fs)) {
- media_svc_error("error in statfs");
- g_free(thumb_path);
- return MS_MEDIA_ERR_INTERNAL;
- }
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path error");
+ ret = statfs(thumb_path, &fs);
g_free(thumb_path);
+ media_svc_retvm_if(ret == -1, MS_MEDIA_ERR_INTERNAL, "statfs failed");
- long bsize_kbytes = fs.f_bsize >> 10;
+ bsize_kbytes = fs.f_bsize >> 10;
+ media_svc_retvm_if((bsize_kbytes * fs.f_bavail) < 1024, MS_MEDIA_ERR_NOT_ENOUGH_SPACE, "Not enough space");
- if ((bsize_kbytes * fs.f_bavail) < 1024) {
- media_svc_error("not enought space...");
- return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
- }
-
- FILE *fp = NULL;
- int nwrite = -1;
- if (image != NULL && size > 0) {
- fp = fopen(image_path, "w");
-
- if (fp == NULL) {
- media_svc_error("failed to open file");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- nwrite = fwrite(image, 1, size, fp);
- if (nwrite != size) {
- media_svc_error("failed to write thumbnail");
- fclose(fp);
- return MS_MEDIA_ERR_INTERNAL;
- }
- fclose(fp);
+ if (!g_file_set_contents(image_path, (const gchar *)image, (gssize)size, &error)) {
+ media_svc_error("g_file_set_contents faild:%s", error->message);
+ g_error_free(error);
+ return MS_MEDIA_ERR_INTERNAL;
}
return MS_MEDIA_ERR_NONE;