summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2015-08-13 08:11:15 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-08-21 17:10:29 +0200
commit33227fc15d7fe2dcf7bdb7a69b3c46034d3c43b1 (patch)
tree12e26c447ef7ac08c5a09a53f3abe3f68992c10e
parentb5d2cef660bc8e63074f1eada8fbd15392f2e3e3 (diff)
eina: add API to join pahs, as well as path separators
eina_str_join() is used a lot to contatenate paths, but the separator should be '\' on Windows. So add 2 API and 2 defines for more cross platform code @feature Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/Makefile_Eina.am1
-rw-r--r--src/lib/eina/eina_file.h38
-rw-r--r--src/lib/eina/eina_inline_file.x85
3 files changed, 124 insertions, 0 deletions
diff --git a/src/Makefile_Eina.am b/src/Makefile_Eina.am
index 7537e8a932..7e65a262f7 100644
--- a/src/Makefile_Eina.am
+++ b/src/Makefile_Eina.am
@@ -29,6 +29,7 @@ lib/eina/eina_inlist.h \
29lib/eina/eina_inline_inlist.x \ 29lib/eina/eina_inline_inlist.x \
30lib/eina/eina_list.h \ 30lib/eina/eina_list.h \
31lib/eina/eina_file.h \ 31lib/eina/eina_file.h \
32lib/eina/eina_inline_file.x \
32lib/eina/eina_mempool.h \ 33lib/eina/eina_mempool.h \
33lib/eina/eina_module.h \ 34lib/eina/eina_module.h \
34lib/eina/eina_rectangle.h \ 35lib/eina/eina_rectangle.h \
diff --git a/src/lib/eina/eina_file.h b/src/lib/eina/eina_file.h
index cf245e7bb6..952e22c80c 100644
--- a/src/lib/eina/eina_file.h
+++ b/src/lib/eina/eina_file.h
@@ -28,6 +28,7 @@
28#include "eina_array.h" 28#include "eina_array.h"
29#include "eina_iterator.h" 29#include "eina_iterator.h"
30#include "eina_tmpstr.h" 30#include "eina_tmpstr.h"
31#include "eina_str.h"
31 32
32/** 33/**
33 * @page eina_file_example_01_page 34 * @page eina_file_example_01_page
@@ -161,6 +162,29 @@ typedef enum {
161 * @brief The constant defined as the highest value for PATH_MAX. 162 * @brief The constant defined as the highest value for PATH_MAX.
162 */ 163 */
163#define EINA_PATH_MAX 8192 164#define EINA_PATH_MAX 8192
165
166/**
167 * @def EINA_PATH_SEP_C
168 * @brief The constant defined the path separator as the character '\'
169 * on Windows and '/' otherwise.
170 *
171 * @since 1.16
172 */
173/**
174 * @def EINA_PATH_SEP_S
175 * @brief The constant defined the path separator as the string "\" on Windows
176 * and "/" otherwise.
177 *
178 * @since 1.16
179 */
180#ifdef _WIN32
181# define EINA_PATH_SEP_C '\\'
182# define EINA_PATH_SEP_S "\\"
183#else
184# define EINA_PATH_SEP_C '/'
185# define EINA_PATH_SEP_S "/"
186#endif
187
164/** 188/**
165 * @struct _Eina_File_Direct_Info 189 * @struct _Eina_File_Direct_Info
166 * @brief The structure to store information of a path. 190 * @brief The structure to store information of a path.
@@ -670,6 +694,20 @@ EAPI Eina_Iterator *eina_file_map_lines(Eina_File *file);
670 */ 694 */
671EAPI Eina_Bool eina_file_map_faulted(Eina_File *file, void *map); 695EAPI Eina_Bool eina_file_map_faulted(Eina_File *file, void *map);
672 696
697static inline size_t eina_file_path_join_len(char *dst,
698 size_t size,
699 const char *a,
700 size_t a_len,
701 const char *b,
702 size_t b_len);
703
704static inline size_t eina_file_path_join(char *dst,
705 size_t size,
706 const char *a,
707 const char *b);
708
709#include "eina_inline_file.x"
710
673/** 711/**
674 * @} 712 * @}
675 */ 713 */
diff --git a/src/lib/eina/eina_inline_file.x b/src/lib/eina/eina_inline_file.x
new file mode 100644
index 0000000000..d9dffddd80
--- /dev/null
+++ b/src/lib/eina/eina_inline_file.x
@@ -0,0 +1,85 @@
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_FILE_INLINE_H_
20#define EINA_FILE_INLINE_H_
21
22/**
23 * @addtogroup Eina_File_Group File
24 *
25 * @{
26 */
27
28/**
29 * @brief Join two paths of known length.
30 *
31 * @param dst The buffer to store the result.
32 * @param size Size (in byte) of the buffer.
33 * @param a First path to use.
34 * @param a_len length of @p a.
35 * @param b Second path to use.
36 * @param b_len length of @p b.
37 * @return The number of characters printed.
38 *
39 * This function is similar to eina_str_join_len(), but the separator
40 * is '\' on Windows and '/' otherwise.
41 *
42 * @see eina_str_join_len()
43 * @see eina_file_path_join()
44 *
45 * @since 1.16
46 */
47static inline size_t
48eina_file_path_join_len(char *dst,
49 size_t size,
50 const char *a,
51 size_t a_len,
52 const char *b,
53 size_t b_len)
54{
55 return eina_str_join_len(dst, size, EINA_PATH_SEP_C, a, a_len, b, b_len);
56}
57
58/**
59 * @brief Join two paths of known length.
60 *
61 * @param dst The buffer to store the result.
62 * @param size Size (in byte) of the buffer.
63 * @param a First string to use.
64 * @param b Second string to use.
65 * @return The number of characters printed.
66 *
67 * This function is similar to eina_file_path_join_len(), but will compute
68 * the length of @p a and @p b using strlen(). The path separator is
69 * '\' on Windows and '/' otherwise.
70 *
71 * @see eina_file_path_join_len()
72 *
73 * @since 1.16
74 */
75static inline size_t
76eina_file_path_join(char *dst, size_t size, const char *a, const char *b)
77{
78 return eina_file_path_join_len(dst, size, a, strlen(a), b, strlen(b));
79}
80
81/**
82 * @}
83 */
84
85#endif /* EINA_FILE_INLINE_H_ */