summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2015-05-14 07:40:33 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-05-14 18:41:48 +0200
commitdbc6cbb953674217f4741330287d3d062a673151 (patch)
tree10c7d27b7e56b0cfe2e893de71c29d09a8700c29 /src/lib/eina
parent3a6ccab3adada2daf29094c2fec661f71ac981ab (diff)
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 <cedric@osg.samsung.com>
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/Eina.h1
-rw-r--r--src/lib/eina/eina_util.c79
-rw-r--r--src/lib/eina/eina_util.h46
3 files changed, 126 insertions, 0 deletions
diff --git a/src/lib/eina/Eina.h b/src/lib/eina/Eina.h
index c05ab9abee..c35820a8a8 100644
--- a/src/lib/eina/Eina.h
+++ b/src/lib/eina/Eina.h
@@ -265,6 +265,7 @@ extern "C" {
265#include <eina_matrix.h> 265#include <eina_matrix.h>
266#include <eina_crc.h> 266#include <eina_crc.h>
267#include <eina_evlog.h> 267#include <eina_evlog.h>
268#include <eina_util.h>
268 269
269#undef EAPI 270#undef EAPI
270#define EAPI 271#define EAPI
diff --git a/src/lib/eina/eina_util.c b/src/lib/eina/eina_util.c
new file mode 100644
index 0000000000..55b5bd5343
--- /dev/null
+++ b/src/lib/eina/eina_util.c
@@ -0,0 +1,79 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2015 Vincent Torri
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <stdlib.h>
24
25#include "eina_config.h"
26#include "eina_private.h"
27#include "eina_tmpstr.h"
28
29/*============================================================================*
30 * Local *
31 *============================================================================*/
32
33
34/*============================================================================*
35 * Global *
36 *============================================================================*/
37
38
39/*============================================================================*
40 * API *
41 *============================================================================*/
42
43EAPI Eina_Tmpstr *
44eina_environment_home_get(void)
45{
46#ifdef _WIN32
47 char *home;
48
49 home = getenv("USERPROFILE");
50 if (!home) home = getenv("WINDIR");
51 if (!home) home = "C:\\";
52
53 return eina_tmpstr_add(home);
54#else
55 return eina_tmpstr_add(getenv("HOME"));
56#endif
57}
58
59EAPI Eina_Tmpstr *
60eina_environment_tmp_get(void)
61{
62 char *tmp;
63
64#ifdef _WIN32
65 tmp = getenv("TMP");
66 if (!tmp) tmp = getenv("TEMP");
67 if (!tmp) tmp = getenv("USERPROFILE");
68 if (!tmp) tmp = getenv("WINDIR");
69 if (!tmp) tmp = "C:\\";
70
71 return eina_tmpstr_add(tmp);
72#else
73 tmp = getenv("TMPDIR");
74 if (!tmp) tmp = getenv("XDG_RUNTIME_DIR");
75 if (!tmp) tmp = "/tmp";
76
77 return eina_tmpstr_add(tmp);
78#endif
79}
diff --git a/src/lib/eina/eina_util.h b/src/lib/eina/eina_util.h
new file mode 100644
index 0000000000..3677cc4a1a
--- /dev/null
+++ b/src/lib/eina/eina_util.h
@@ -0,0 +1,46 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2015 Vincent Torri
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef EINA_UTIL_H_
20#define EINA_UTIL_H_
21
22/**
23 * @addtogroup Eina_Tools_Group Tools
24 *
25 * @{
26 */
27
28/**
29 * @brief Return the content of the environment refered by HOME on this system.
30 * @return A temporary string to the content refered by HOME on this system.
31 *
32 * @note The result of this call is highly system dependent and you better use
33 * it instead of the naive getenv("HOME").
34 */
35EAPI Eina_Tmpstr *eina_environment_home_get(void);
36
37/**
38 * @brief Return the content of the environment refered as TMPDIR on this system.
39 * @return A temporary string to the content refered by TMPDIR on this system.
40 *
41 * @note The result of this call is highly system dependent and you better use
42 * it instead of the naive getenv("TMPDIR").
43 */
44EAPI Eina_Tmpstr *eina_environment_tmp_get(void);
45
46#endif