le_path.h File Reference

Go to the source code of this file.

Functions

le_result_t le_path_GetDir (const char *pathPtr, const char *separatorPtr, char *dirPtr, size_t dirBuffSize)
 
char * le_path_GetBasenamePtr (const char *pathPtr, const char *separatorPtr)
 
le_result_t le_path_Concat (const char *separatorPtr, char *pathPtr, size_t pathSize,...)
 
bool le_path_IsSubpath (const char *path1Ptr, const char *path2Ptr, const char *separatorPtr)
 
bool le_path_IsEquivalent (const char *path1Ptr, const char *path2Ptr, const char *separatorPtr)
 

Detailed Description

Legato Path API include file.

Copyright (C) Sierra Wireless Inc. Use of this work is subject to license. license.

Function Documentation

le_result_t le_path_Concat ( const char *  separatorPtr,
char *  pathPtr,
size_t  pathSize,
  ... 
)

Concatenates multiple path segments together.

Concatenates the path in the pathPtr buffer with all path segments and stores the result in the pathPtr. Ensures that where path segments are joined there is only one separator between them. Duplicate trailing separators in the resultant path are also dropped.

If there is not enough space in pathPtr for all segments, as many characters from the segments that will fit in the buffer will be copied and LE_OVERFLOW will be returned. Partial UTF-8 characters and partial separators will never be copied.

Warning
The (char*)NULL at the end of the list of path segments is mandatory. If this NULL is omitted the behaviour is undefined.
Returns
LE_OK if successful. LE_OVERFLOW if there was not enough buffer space in pathPtr for all segments.
Parameters
[in]separatorPtrSeparator string.
[in,out]pathPtrBuffer containing the first segment and where the resultant path will be stored.
[in]pathSizeBuffer size.
char* le_path_GetBasenamePtr ( const char *  pathPtr,
const char *  separatorPtr 
)

Gets a pointer to the basename (the last node in the path). This function gets the basename by returning a pointer to the character following the last separator.

Returns
Pointer to the character following the last separator.
Parameters
[in]pathPtrPath string.
[in]separatorPtrSeparator string.
le_result_t le_path_GetDir ( const char *  pathPtr,
const char *  separatorPtr,
char *  dirPtr,
size_t  dirBuffSize 
)

Gets the directory, which is the entire path up to and including the last separator.

Returns
LE_OK if succesful. LE_OVERFLOW if the dirPtr buffer is too small.
Parameters
[in]pathPtrPath string.
[in]separatorPtrSeparator string.
[out]dirPtrBuffer to store the directory string.
[in]dirBuffSizeSize of the directory buffer in bytes.
bool le_path_IsEquivalent ( const char *  path1Ptr,
const char *  path2Ptr,
const char *  separatorPtr 
)

Checks if path1 and path2 are equivalent, ignoring trailing separators. For example, all the following paths are equivalent.

/a/b/c /a/b/c/ /a/b/c///

Returns
true if path1 is equivalent to path2. false otherwise.
Parameters
[in]path1PtrPath 1 string.
[in]path2PtrPath 2 string.
[in]separatorPtrSeparator string.
bool le_path_IsSubpath ( const char *  path1Ptr,
const char *  path2Ptr,
const char *  separatorPtr 
)

Checks if path2 is a subpath of path1. That is path2 has the same starting nodes as path2. For example, path2 is a subpath of path1 if:

path1 = /a/b/c path2 = /a/b/c/d/e

Returns
true if path2 is a subpath of path1. false otherwise.
Parameters
[in]path1PtrPath 1 string.
[in]path2PtrPath 2 string.
[in]separatorPtrSeparator string.