eina: add eina_file_mkstemp.
authorCedric BAIL <cedric.bail@samsung.com>
Mon, 25 Mar 2013 09:43:13 +0000 (18:43 +0900)
committerCedric BAIL <cedric.bail@samsung.com>
Mon, 25 Mar 2013 09:45:42 +0000 (18:45 +0900)
ChangeLog
NEWS
src/lib/eina/eina_file.h
src/lib/eina/eina_file_common.c

index fe187f6..35443bb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,10 @@
+2013-03-25  Cedric Bail
+
+       * Eina: add portable eina_file_mkstemp().
+
 2013-03-22  Jiyoun Park (Jypark)
 
-    * Ecore_x: fix alpha set function not clear sync counter
+       * Ecore_x: fix alpha set function not clear sync counter
 
 2013-03-22  Cedric Bail
 
diff --git a/NEWS b/NEWS
index 571e40c..655ba53 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,7 +6,6 @@ Changes since 1.7.0:
 --------------------
 
 Additions:
-    * Add eina_list_shuffle
     * Add multiple font draws support to engines
     * eina :
      - Add DOCTYPE children parsing in eina_simple_xml
@@ -21,6 +20,8 @@ Additions:
      - Add eina_stringshare_refplace()
      - Add eina_file_copy()
      - Add eina_log_print_cb_journald()
+     - Add eina_list_shuffle()
+     - Add eina_file_mkstemp()
     * Add Cserve2 scalecache support
     * ecore_x:
      - Add window profile support.
index 718303c..d0accf3 100644 (file)
@@ -27,7 +27,7 @@
 #include "eina_types.h"
 #include "eina_array.h"
 #include "eina_iterator.h"
-
+#include "eina_tmpstr.h"
 
 /**
  * @page eina_file_example_01_page
@@ -323,6 +323,8 @@ EAPI Eina_Iterator *eina_file_stat_ls(const char *dir) EINA_WARN_UNUSED_RESULT E
  */
 EAPI int eina_file_statat(void *container, Eina_File_Direct_Info *info, Eina_Stat *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2, 3);
 
+EAPI int eina_file_mkstemp(const char *filename, Eina_Tmpstr **path);
+
 /**
  * @brief Get an iterator to list the content of a directory, with direct
  * information.
index f3bb0ff..e17b185 100644 (file)
@@ -569,3 +569,27 @@ eina_file_copy(const char *src, const char *dst, Eina_File_Copy_Flags flags, Ein
 
    return success;
 }
+
+EAPI int
+eina_file_mkstemp(const char *filename, Eina_Tmpstr **path)
+{
+   char buffer[PATH_MAX];
+   const char *tmpdir;
+   int fd;
+
+#ifndef HAVE_EVIL
+   tmpdir = getenv("TMPDIR");
+   if (!tmpdir) tmpdir = "/tmp";
+#else
+   tmpdir = (char *)evil_tmpdir_get();
+#endif /* ! HAVE_EVIL */
+
+   snprintf(buffer, PATH_MAX, "%s/%s", tmpdir, filename);
+
+   fd = mkstemp(buffer);
+   if (path) *path = eina_tmpstr_add(buffer);
+   if (fd < 0)
+     return -1;
+
+   return fd;
+}