#define DEBUG_ERROR(frmt, args...) \
do { SLOG(LOG_ERROR,FONT_SERVICE_TAG, "[font_service] %s: "frmt"\n",\
__func__, ##args);} while (0)
+#define DEBUG_ERROR_ERRNO(frmt, args...) \
+ do { \
+ char error_string[255] = { 0 }; \
+ strerror_r(errno, error_string, sizeof(error_string)); \
+ SLOG(LOG_ERROR,FONT_SERVICE_TAG, "[font_service] %s: "frmt": %s\n",\
+ __func__, ##args, error_string);} while (0)
static const char *PARENT_PATH = "/opt/share/fonts";
static const char *DOWNLOAD_PATH = "/opt/share/fonts/download";
char tpk_path[MAX_FILE_LEN];
char wgt_path[MAX_FILE_LEN];
- sprintf(tpk_path, "%s/preloaded", app_root_path);
- sprintf(wgt_path, "%s/res/wgt/preloaded", app_root_path);
+ snprintf(tpk_path, sizeof(tpk_path), "%s/preloaded", app_root_path);
+ snprintf(wgt_path, sizeof(wgt_path), "%s/res/wgt/preloaded", app_root_path);
if ((access(tpk_path, F_OK) == 0) || (access(wgt_path, F_OK) == 0))
{
goto FAIL;
}
- sprintf(srcdir,"%s/%s",srcpath,(char *) e->d_name);
- sprintf(destdir,"%s/%s",destpath,(char *) e->d_name);
+ snprintf(srcdir, sizeof(srcdir), "%s/%s", srcpath, (char *)e->d_name);
+ snprintf(destdir, sizeof(destdir), "%s/%s", destpath, (char *)e->d_name);
if (stat (srcdir, &statb) == -1)
{
DEBUG_ERROR("stat %s is failed \n",srcdir);
#define COPY_BUF_SIZE 16777216
static int copy_file(const char *srcpath, const char *destpath) {
- FILE *in, *out;
- char *buf;
+ FILE *in = NULL, *out = NULL;
+ char *buf = NULL;
size_t len;
if (!srcpath || !destpath)
if ((in = fopen(srcpath, "rb")) == NULL)
{
- DEBUG_ERROR("copyfile is failed. The srcpath[%s] is not opened with read permission. fopen(): %s\n", srcpath, strerror(errno));
+ DEBUG_ERROR_ERRNO("copyfile is failed. The srcpath[%s] is not opened with read permission. fopen()", srcpath);
goto FAIL;
}
if ((out = fopen(destpath, "wb")) == NULL)
{
- DEBUG_ERROR("copyfile is failed. The destpath[%s] is not opened with write permission. fopen(): %s\n", destpath, strerror(errno));
+ DEBUG_ERROR_ERRNO("copyfile is failed. The destpath[%s] is not opened with write permission. fopen()", destpath);
goto FAIL;
}
if ((buf = (char *) malloc(COPY_BUF_SIZE)) == NULL)
{
- DEBUG_ERROR("copyfile is failed. Memory allocation for copy buffer is failed. Request size [%d]. malloc(): %s\n", COPY_BUF_SIZE, strerror(errno));
+ DEBUG_ERROR_ERRNO("copyfile is failed. Memory allocation for copy buffer is failed. Request size [%d]. malloc()", COPY_BUF_SIZE);
goto FAIL;
}
- while ((len = fread(buf, sizeof(char), sizeof(buf), in)) != 0)
+ while ((len = fread(buf, sizeof(char), COPY_BUF_SIZE, in)) != 0)
{
if (fwrite(buf, sizeof(char), len, out) == 0)
{
/* Reads "len" string. But, it fails to write file.
We need to remove wrong result. */
- DEBUG_ERROR("copyfile is failed. fwrite fails to write. fwrite(): %s\n", strerror(errno));
+ DEBUG_ERROR_ERRNO("copyfile is failed. fwrite fails to write. fwrite()");
fclose(out);
out = NULL;
if (remove(destpath) == -1)
- DEBUG_ERROR("removing copied file with error is failed. remove(): %s\n", strerror(errno));
+ DEBUG_ERROR_ERRNO("removing copied file with error is failed. remove()");
goto FAIL;
}
goto FAIL;
}
- sprintf(srcdir, "%s/%s", srcpath, (char *)e->d_name);
- sprintf(destdir, "%s/%s", destpath, (char *)e->d_name);
+ snprintf(srcdir, sizeof(srcdir), "%s/%s", srcpath, (char *)e->d_name);
+ snprintf(destdir, sizeof(destdir), "%s/%s", destpath, (char *)e->d_name);
if (stat(srcdir, &statb) == -1)
{
}
if (remove(srcdir) == -1)
- DEBUG_ERROR("removing src file[%s] is failed. remove(): %s\n", srcdir, strerror(errno));
+ DEBUG_ERROR_ERRNO("removing src file[%s] is failed. remove()", srcdir);
}
}
return -1;
}
- sprintf(destdir,"%s/%s",parent,appid);
+ snprintf(destdir, sizeof(destdir), "%s/%s", parent, appid);
ret = make_dir(destdir);
if (ret < 0)
{
goto FAIL;
}
- sprintf(path,"%s/shared/res", rootpath);
+ snprintf(path, sizeof(path), "%s/shared/res", rootpath);
if (!strcmp(type,"wgt"))
{
char srcpath[MAX_FILE_LEN];
- sprintf(srcpath,"%s/res/wgt/shared/res", rootpath);
+ snprintf(srcpath, sizeof(srcpath), "%s/res/wgt/shared/res", rootpath);
ret = move_path(srcpath, path);
}
if (ret < 0)
{
- DEBUG_ERROR("install is failed \n", destdir);
+ DEBUG_ERROR("install is failed to [%s]\n", destdir);
goto FAIL;
}
goto FAIL;
}
- sprintf(destfile,"%s/%s",deletedir,(char *) e->d_name);
+ snprintf(destfile, sizeof(destfile), "%s/%s", deletedir, (char *)e->d_name);
if (lstat (destfile, &statb) == -1)
{
DEBUG_ERROR("lstat %s is failed \n",destfile);
goto FAIL;
}
- sprintf(deletedir,"%s/%s", dest_path, appid);
+ snprintf(deletedir, sizeof(deletedir), "%s/%s", dest_path, appid);
if (access(deletedir, F_OK) == -1)
{
- DEBUG_ERROR("dest directory(%s) is not exist: %s\n", deletedir, strerror(errno));
+ DEBUG_ERROR_ERRNO("dest directory(%s) is not exist", deletedir);
goto FAIL;
}
ret = make_dir(PARENT_PATH);
if (ret < 0)
{
- DEBUG_ERROR("make current directory(%s) is failed: %s\n", PARENT_PATH, strerror(errno));
+ DEBUG_ERROR_ERRNO("make current directory(%s) is failed", PARENT_PATH);
goto FAIL;
}
ret = make_dir(dest_path);
if (ret < 0)
{
- DEBUG_ERROR("make current directory(%s) is failed: %s\n", dest_path, strerror(errno));
+ DEBUG_ERROR_ERRNO("make current directory(%s) is failed", dest_path);
goto FAIL;
}
/* It must contain "/" character at end of the delete dir path.
* It prevents file path comparing issues when there are many similar path. */
- sprintf(deletedir,"%s/%s/", dest_path, appid);
+ snprintf(deletedir, sizeof(deletedir), "%s/%s/", dest_path, appid);
//check if current using font is same with uninstall font
deletedir_len = strlen(deletedir);
fs = FcFontList(NULL, pat, os);
FcPatternDestroy(pat);
+ pat = NULL;
free(current_font_name);
+ current_font_name = NULL;
if (fs)
{
if (access(deletedir, F_OK) == -1)
{
- DEBUG_ERROR("dest directory(%s) is not exist: %s\n", deletedir, strerror(errno));
+ DEBUG_ERROR_ERRNO("dest directory(%s) is not exist", deletedir);
goto FAIL;
}
return do_uninstall(deletedir);
FAIL:
+ if (pat) FcPatternDestroy(pat);
elm_shutdown();
pkgmgrinfo_pkginfo_destroy_pkginfo(handle);