diff options
author | Vincent Torri <vincent.torri@gmail.com> | 2015-08-13 08:11:15 +0200 |
---|---|---|
committer | Cedric BAIL <cedric@osg.samsung.com> | 2015-08-21 17:10:29 +0200 |
commit | 33227fc15d7fe2dcf7bdb7a69b3c46034d3c43b1 (patch) | |
tree | 12e26c447ef7ac08c5a09a53f3abe3f68992c10e /src/lib/eina | |
parent | b5d2cef660bc8e63074f1eada8fbd15392f2e3e3 (diff) | |
download | efl-33227fc15d7fe2dcf7bdb7a69b3c46034d3c43b1.tar.gz |
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>
Diffstat (limited to 'src/lib/eina')
-rw-r--r-- | src/lib/eina/eina_file.h | 38 | ||||
-rw-r--r-- | src/lib/eina/eina_inline_file.x | 85 |
2 files changed, 123 insertions, 0 deletions
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 @@ #include "eina_array.h" #include "eina_iterator.h" #include "eina_tmpstr.h" +#include "eina_str.h" /** * @page eina_file_example_01_page @@ -161,6 +162,29 @@ typedef enum { * @brief The constant defined as the highest value for PATH_MAX. */ #define EINA_PATH_MAX 8192 + +/** + * @def EINA_PATH_SEP_C + * @brief The constant defined the path separator as the character '\' + * on Windows and '/' otherwise. + * + * @since 1.16 + */ +/** + * @def EINA_PATH_SEP_S + * @brief The constant defined the path separator as the string "\" on Windows + * and "/" otherwise. + * + * @since 1.16 + */ +#ifdef _WIN32 +# define EINA_PATH_SEP_C '\\' +# define EINA_PATH_SEP_S "\\" +#else +# define EINA_PATH_SEP_C '/' +# define EINA_PATH_SEP_S "/" +#endif + /** * @struct _Eina_File_Direct_Info * @brief The structure to store information of a path. @@ -670,6 +694,20 @@ EAPI Eina_Iterator *eina_file_map_lines(Eina_File *file); */ EAPI Eina_Bool eina_file_map_faulted(Eina_File *file, void *map); +static inline size_t eina_file_path_join_len(char *dst, + size_t size, + const char *a, + size_t a_len, + const char *b, + size_t b_len); + +static inline size_t eina_file_path_join(char *dst, + size_t size, + const char *a, + const char *b); + +#include "eina_inline_file.x" + /** * @} */ 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 @@ +/* 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_FILE_INLINE_H_ +#define EINA_FILE_INLINE_H_ + +/** + * @addtogroup Eina_File_Group File + * + * @{ + */ + +/** + * @brief Join two paths of known length. + * + * @param dst The buffer to store the result. + * @param size Size (in byte) of the buffer. + * @param a First path to use. + * @param a_len length of @p a. + * @param b Second path to use. + * @param b_len length of @p b. + * @return The number of characters printed. + * + * This function is similar to eina_str_join_len(), but the separator + * is '\' on Windows and '/' otherwise. + * + * @see eina_str_join_len() + * @see eina_file_path_join() + * + * @since 1.16 + */ +static inline size_t +eina_file_path_join_len(char *dst, + size_t size, + const char *a, + size_t a_len, + const char *b, + size_t b_len) +{ + return eina_str_join_len(dst, size, EINA_PATH_SEP_C, a, a_len, b, b_len); +} + +/** + * @brief Join two paths of known length. + * + * @param dst The buffer to store the result. + * @param size Size (in byte) of the buffer. + * @param a First string to use. + * @param b Second string to use. + * @return The number of characters printed. + * + * This function is similar to eina_file_path_join_len(), but will compute + * the length of @p a and @p b using strlen(). The path separator is + * '\' on Windows and '/' otherwise. + * + * @see eina_file_path_join_len() + * + * @since 1.16 + */ +static inline size_t +eina_file_path_join(char *dst, size_t size, const char *a, const char *b) +{ + return eina_file_path_join_len(dst, size, a, strlen(a), b, strlen(b)); +} + +/** + * @} + */ + +#endif /* EINA_FILE_INLINE_H_ */ |