eina_file_mkstemp(const char *templatename, Eina_Tmpstr **path)
{
char buffer[PATH_MAX];
- const char *XXXXXX = NULL, *sep;
+ const char *tmpdir = NULL;
+ const char *XXXXXX = NULL;
int fd, len;
#ifndef _WIN32
mode_t old_umask;
EINA_SAFETY_ON_NULL_RETURN_VAL(templatename, -1);
- sep = strchr(templatename, '/');
-#ifdef _WIN32
- if (!sep) sep = strchr(templatename, '\\');
-#endif
- if (sep)
- {
- len = eina_strlcpy(buffer, templatename, sizeof(buffer));
- }
- else
+# if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
+ if (getuid() == geteuid())
+# endif
{
- len = eina_file_path_join(buffer, sizeof(buffer),
- eina_environment_tmp_get(), templatename);
+ tmpdir = getenv("TMPDIR");
+ if (!tmpdir) tmpdir = getenv("XDG_RUNTIME_DIR");
}
+ if (!tmpdir) tmpdir = "/tmp";
+
+#ifdef _WIN32
+ if (strchr(templatename, '\\'))
+#else
+ if (strchr(templatename, '/'))
+#endif
+ len = snprintf(buffer, PATH_MAX, "%s", templatename);
+else
+ len = snprintf(buffer, PATH_MAX, "%s/%s", tmpdir, templatename);
/*
* Unix:
eina_file_mkdtemp(const char *templatename, Eina_Tmpstr **path)
{
char buffer[PATH_MAX];
- char *tmpdirname, *sep;
+ const char *tmpdir = NULL;
+ char *tmpdirname;
EINA_SAFETY_ON_NULL_RETURN_VAL(templatename, EINA_FALSE);
- sep = strchr(templatename, '/');
-#ifdef _WIN32
- if (!sep) sep = strchr(templatename, '\\');
-#endif
- if (sep)
- {
- eina_strlcpy(buffer, templatename, sizeof(buffer));
- }
- else
+# if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
+ if (getuid() == geteuid())
+# endif
{
- eina_file_path_join(buffer, sizeof(buffer),
- eina_environment_tmp_get(), templatename);
+ tmpdir = getenv("TMPDIR");
+ if (!tmpdir) tmpdir = getenv("XDG_RUNTIME_DIR");
}
+ if (!tmpdir) tmpdir = "/tmp";
+
+#ifdef _WIN32
+ if (strchr(templatename, '\\'))
+#else
+ if (strchr(templatename, '/'))
+#endif
+ snprintf(buffer, PATH_MAX, "%s", templatename);
+else
+ snprintf(buffer, PATH_MAX, "%s/%s", tmpdir, templatename);
tmpdirname = mkdtemp(buffer);
if (tmpdirname == NULL)