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>
This commit is contained in:
Vincent Torri 2015-08-13 08:11:15 +02:00 committed by Cedric BAIL
parent b5d2cef660
commit 33227fc15d
3 changed files with 124 additions and 0 deletions

View File

@ -29,6 +29,7 @@ lib/eina/eina_inlist.h \
lib/eina/eina_inline_inlist.x \
lib/eina/eina_list.h \
lib/eina/eina_file.h \
lib/eina/eina_inline_file.x \
lib/eina/eina_mempool.h \
lib/eina/eina_module.h \
lib/eina/eina_rectangle.h \

View File

@ -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"
/**
* @}
*/

View File

@ -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_ */