cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=dbc6cbb953674217f4741330287d3d062a673151

commit dbc6cbb953674217f4741330287d3d062a673151
Author: Vincent Torri <vincent.to...@gmail.com>
Date:   Thu May 14 07:40:33 2015 +0200

    eina: add crosss platforme API to retrieve tmp and home directories from 
environment.
    
    @feature
    
    No tests added as it is highly dependent on the system and it would make 
little sens.
    
    Signed-off-by: Cedric BAIL <ced...@osg.samsung.com>
---
 src/Makefile_Eina.am     |  4 ++-
 src/lib/eina/Eina.h      |  1 +
 src/lib/eina/eina_util.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/lib/eina/eina_util.h | 46 ++++++++++++++++++++++++++++
 4 files changed, 129 insertions(+), 1 deletion(-)

diff --git a/src/Makefile_Eina.am b/src/Makefile_Eina.am
index 18e3f44..3a181b6 100644
--- a/src/Makefile_Eina.am
+++ b/src/Makefile_Eina.am
@@ -89,7 +89,8 @@ lib/eina/eina_thread_queue.h \
 lib/eina/eina_matrix.h \
 lib/eina/eina_quad.h \
 lib/eina/eina_crc.h \
-lib/eina/eina_evlog.h
+lib/eina/eina_evlog.h \
+lib/eina/eina_util.h
 
 lib_eina_libeina_la_SOURCES = \
 lib/eina/eina_abi.c \
@@ -150,6 +151,7 @@ lib/eina/eina_tmpstr.c \
 lib/eina/eina_unicode.c \
 lib/eina/eina_ustrbuf.c \
 lib/eina/eina_ustringshare.c \
+lib/eina/eina_util.c \
 lib/eina/eina_value.c \
 lib/eina/eina_value_util.c \
 lib/eina/eina_xattr.c \
diff --git a/src/lib/eina/Eina.h b/src/lib/eina/Eina.h
index c05ab9a..c35820a 100644
--- a/src/lib/eina/Eina.h
+++ b/src/lib/eina/Eina.h
@@ -265,6 +265,7 @@ extern "C" {
 #include <eina_matrix.h>
 #include <eina_crc.h>
 #include <eina_evlog.h>
+#include <eina_util.h>
 
 #undef EAPI
 #define EAPI
diff --git a/src/lib/eina/eina_util.c b/src/lib/eina/eina_util.c
new file mode 100644
index 0000000..55b5bd5
--- /dev/null
+++ b/src/lib/eina/eina_util.c
@@ -0,0 +1,79 @@
+/* EINA - EFL data type library
+ * Copyright (C) 2015 Vincent Torri
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library;
+ * if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include "eina_config.h"
+#include "eina_private.h"
+#include "eina_tmpstr.h"
+
+/*============================================================================*
+ *                                  Local                                     *
+ 
*============================================================================*/
+
+
+/*============================================================================*
+ *                                 Global                                     *
+ 
*============================================================================*/
+
+
+/*============================================================================*
+ *                                   API                                      *
+ 
*============================================================================*/
+
+EAPI Eina_Tmpstr *
+eina_environment_home_get(void)
+{
+#ifdef _WIN32
+   char *home;
+
+   home = getenv("USERPROFILE");
+   if (!home) home = getenv("WINDIR");
+   if (!home) home = "C:\\";
+
+   return eina_tmpstr_add(home);
+#else
+   return eina_tmpstr_add(getenv("HOME"));
+#endif
+}
+
+EAPI Eina_Tmpstr *
+eina_environment_tmp_get(void)
+{
+   char *tmp;
+
+#ifdef _WIN32
+   tmp = getenv("TMP");
+   if (!tmp) tmp = getenv("TEMP");
+   if (!tmp) tmp = getenv("USERPROFILE");
+   if (!tmp) tmp = getenv("WINDIR");
+   if (!tmp) tmp = "C:\\";
+
+   return eina_tmpstr_add(tmp);
+#else
+   tmp = getenv("TMPDIR");
+   if (!tmp) tmp = getenv("XDG_RUNTIME_DIR");
+   if (!tmp) tmp = "/tmp";
+
+   return eina_tmpstr_add(tmp);
+#endif
+}
diff --git a/src/lib/eina/eina_util.h b/src/lib/eina/eina_util.h
new file mode 100644
index 0000000..3677cc4
--- /dev/null
+++ b/src/lib/eina/eina_util.h
@@ -0,0 +1,46 @@
+/* EINA - EFL data type library
+ * Copyright (C) 2015 Vincent Torri
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library;
+ * if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EINA_UTIL_H_
+#define EINA_UTIL_H_
+
+/**
+ * @addtogroup Eina_Tools_Group Tools
+ *
+ * @{
+ */
+
+/**
+ * @brief Return the content of the environment refered by HOME on this system.
+ * @return A temporary string to the content refered by HOME on this system.
+ *
+ * @note The result of this call is highly system dependent and you better use
+ * it instead of the naive getenv("HOME").
+ */
+EAPI Eina_Tmpstr *eina_environment_home_get(void);
+
+/**
+ * @brief Return the content of the environment refered as TMPDIR on this 
system.
+ * @return A temporary string to the content refered by TMPDIR on this system.
+ *
+ * @note The result of this call is highly system dependent and you better use
+ * it instead of the naive getenv("TMPDIR").
+ */
+EAPI Eina_Tmpstr *eina_environment_tmp_get(void);
+
+#endif

-- 


Reply via email to