From: Jean-Philippe Andre Date: Tue, 19 Jan 2016 02:50:54 +0000 (+0900) Subject: Eina: Fix eina_file_mk[ds]temp when a path is passed X-Git-Tag: submit/tizen/20161026.040418~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=711e25ad02940089ba9e8c8098536663c2df102d;p=platform%2Fupstream%2Fefl.git Eina: Fix eina_file_mk[ds]temp when a path is passed If the template is a path, mkstemp and mkdtemp would fail miserably as they would try to create a file inside /run/user/1000//path/to/file.XXXXXX even if the path did not exist. This patch fixes that by creating temp files inside the sys temp dir iif the templatename is just a basic name without path separator. @fix Change-Id: I7d8503f8a15e9a03e92f33271dca280b966f70de Signed-off-by: Mykyta Biliavskyi --- diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c index 630efc0..8314f00 100644 --- a/src/lib/eina/eina_file_common.c +++ b/src/lib/eina/eina_file_common.c @@ -913,8 +913,7 @@ EAPI int eina_file_mkstemp(const char *templatename, Eina_Tmpstr **path) { char buffer[PATH_MAX]; - const char *tmpdir = NULL; - const char *XXXXXX = NULL; + const char *XXXXXX = NULL, *sep; int fd, len; #ifndef _WIN32 mode_t old_umask; @@ -922,30 +921,19 @@ eina_file_mkstemp(const char *templatename, Eina_Tmpstr **path) EINA_SAFETY_ON_NULL_RETURN_VAL(templatename, -1); -# if defined(HAVE_GETUID) && defined(HAVE_GETEUID) - if (getuid() == geteuid()) -# endif - { - tmpdir = getenv("TMPDIR"); - if (!tmpdir) tmpdir = getenv("XDG_RUNTIME_DIR"); - } + sep = strchr(templatename, '/'); #ifdef _WIN32 - /* TIZEN_ONLY(160629): it doesn't gurantee tmp folder on windows. rather than that, we get a - * tmp folder via environment values. */ - tmpdir = getenv("TMP"); - if (!tmpdir) tmpdir = getenv("TEMP"); - if (!tmpdir) tmpdir = getenv("USERPROFILE"); - if (!tmpdir) tmpdir = getenv("WINDIR"); - if (!tmpdir) tmpdir = "C:\\"; - - if (strchr(templatename, '\\')) -#else - if (!tmpdir) tmpdir = "/tmp"; - if (strchr(templatename, '/')) + if (!sep) sep = strchr(templatename, '\\'); #endif - len = snprintf(buffer, PATH_MAX, "%s", templatename); -else - len = snprintf(buffer, PATH_MAX, "%s/%s", tmpdir, templatename); + if (sep) + { + len = eina_strlcpy(buffer, templatename, sizeof(buffer)); + } + else + { + len = eina_file_path_join(buffer, sizeof(buffer), + eina_environment_tmp_get(), templatename); + } /* * Unix: @@ -984,28 +972,23 @@ EAPI Eina_Bool eina_file_mkdtemp(const char *templatename, Eina_Tmpstr **path) { char buffer[PATH_MAX]; - const char *tmpdir = NULL; - char *tmpdirname; + char *tmpdirname, *sep; EINA_SAFETY_ON_NULL_RETURN_VAL(templatename, EINA_FALSE); -# if defined(HAVE_GETUID) && defined(HAVE_GETEUID) - if (getuid() == geteuid()) -# endif - { - tmpdir = getenv("TMPDIR"); - if (!tmpdir) tmpdir = getenv("XDG_RUNTIME_DIR"); - } - if (!tmpdir) tmpdir = "/tmp"; - + sep = strchr(templatename, '/'); #ifdef _WIN32 - if (strchr(templatename, '\\')) -#else - if (strchr(templatename, '/')) + if (!sep) sep = strchr(templatename, '\\'); #endif - snprintf(buffer, PATH_MAX, "%s", templatename); -else - snprintf(buffer, PATH_MAX, "%s/%s", tmpdir, templatename); + if (sep) + { + eina_strlcpy(buffer, templatename, sizeof(buffer)); + } + else + { + eina_file_path_join(buffer, sizeof(buffer), + eina_environment_tmp_get(), templatename); + } tmpdirname = mkdtemp(buffer); if (tmpdirname == NULL)