![]() |
librnr
1.14.5
RoadNarrows Robotics Common Library 1
|
General file name and file path utilities. More...
#include <sys/types.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <unistd.h>#include <pwd.h>#include "rnr/rnrconfig.h"#include "rnr/dliststr.h"#include "rnr/log.h"#include "rnr/new.h"#include "rnr/path.h"Go to the source code of this file.
Classes | |
| struct | path_iter |
Macros | |
| #define | is1stidentifier(c) (isapha((int)c) || ((c) == '_')) |
| first id char More... | |
| #define | isidentifier(c) (isalnum((int)c) || ((c) == '_')) |
| id char | |
Functions | |
| static DListStr_T * | NewSearchPathDList (const char *sSearchPath) |
| Build a dlist of canonical search paths. More... | |
| char * | NewExpandTilde (const char *sTildeExpr) |
| Expand tilde expression. More... | |
| char * | NewSearchPathExpanded (const char *sSearchPath) |
| Expands search path. More... | |
| char * | NewSearchPathCanonicalized (const char *sSearchPath) |
| Expands and canonicalizes a search path. More... | |
| PathIter_T * | SearchPathIterNew (const char *sSearchPath) |
| Allocates and initilized a new search path iterator. More... | |
| void | SearchPathIterDelete (PathIter_T *pIter) |
| Deletes search path iterator. More... | |
| char * | SearchPathIterFirst (PathIter_T *pIter, const char *sSearchFile) |
| Get the first concatenated file path. More... | |
| char * | SearchPathIterNext (PathIter_T *pIter) |
| Construct next file path from search path and search file name. More... | |
| char * | NewNormPath (const char *sPath) |
| Normalize path. More... | |
| char * | NewRealPath (const char *sPath) |
| Expands and canonicalizes a real path. More... | |
| char * | NewJoinedPath (const char *sPath1, const char *sPath2) |
| Join two file paths. More... | |
General file name and file path utilities.
Boths posix (the world) and Microsoft's file and path syntax are supported.
Definition in file path.c.
| #define is1stidentifier | ( | c | ) | (isapha((int)c) || ((c) == '_')) |
| char* NewExpandTilde | ( | const char * | sTildeExpr | ) |
Expand tilde expression.
| sTildeExpr | '~' [user] |
Definition at line 157 of file path.c.
References DIR_SEP_CHAR, new_strdup(), NULL, and PATH_SEP_CHAR.
Referenced by NewSearchPathExpanded(), and PathIsAbsolute().
| char* NewJoinedPath | ( | const char * | sPath1, |
| const char * | sPath2 | ||
| ) |
Join two file paths.
The paths are expanded and canonicalized. The paths do not have to exist. If the second, appended path is an absolute path, then the joined path is the second path.
| sPath1 | Front absolute/relative path. |
| sPath2 | Appended, back end path. |
Definition at line 802 of file path.c.
References DIR_SEP_STR, LOGERROR, NewSearchPathCanonicalized(), NEWSTR, NULL, and PathIsAbsolute().
Referenced by PathIsAbsolute().
| char* NewNormPath | ( | const char * | sPath | ) |
Normalize path.
Normalize path, eliminating double slashes and simplifying dot "." current and ".." parent directory references.
The path does not have to exist.
Definition at line 572 of file path.c.
References DIR_SEP_CHAR, DIR_SEP_STR, new_strdup(), NEWSTR, and PathIsAbsolute().
Referenced by NewSearchPathCanonicalized(), and PathIsAbsolute().
| char* NewRealPath | ( | const char * | sPath | ) |
Expands and canonicalizes a real path.
The expanded path must exist.
| sPath | Path file name. |
Definition at line 778 of file path.c.
References NewSearchPathCanonicalized(), and NULL.
Referenced by PathIsAbsolute().
| char* NewSearchPathCanonicalized | ( | const char * | sSearchPath | ) |
Expands and canonicalizes a search path.
The path does not have to exist.
A canonical search path has:
| sSearchPath | Search path of form: path [path_sep path...] |
Definition at line 331 of file path.c.
References NewNormPath(), NewSearchPathExpanded(), NEWSTR, NULL, and PATH_SEP_STR.
Referenced by NewJoinedPath(), NewRealPath(), NewSearchPathDList(), PathIsAbsolute(), and SearchPathIterFirst().
|
static |
Build a dlist of canonical search paths.
| sSearchPath | Search path of form: path [path_sep path...] |
Definition at line 93 of file path.c.
References DListStrDataPrint(), DListStrNewDft(), LOG_GET_LOGFP(), LOG_LEVEL_DIAG4, LOGABLE, LOGDIAG4, LOGERROR, LOGFUNCNAME, NewSearchPathCanonicalized(), NULL, and PATH_SEP_STR.
Referenced by SearchPathIterNew().
| char* NewSearchPathExpanded | ( | const char * | sSearchPath | ) |
Expands search path.
Expands any environment variables and tilde expressions in search path while building new search path.
The path does not have to exist.
Variable are specified as:
$<identifier> or ${<identifier>} where <identifier> is a legal shell variable name.
Tilde expressions are specified as:
~ or ~user
| sSearchPath | Search path of form: path [path_sep path...] |
Definition at line 227 of file path.c.
References DIR_SEP_CHAR, isidentifier, LOGDIAG4, LOGERROR, LOGFUNCNAME, MAX_SEARCH_PATH, new_strndup(), NewExpandTilde(), NEWSTR, and NULL.
Referenced by NewSearchPathCanonicalized(), and PathIsAbsolute().
| void SearchPathIterDelete | ( | PathIter_T * | pIter | ) |
Deletes search path iterator.
| pIter | Search path iterator (invalid after return from this call). |
Definition at line 422 of file path.c.
References path_iter::m_pSearchPaths, path_iter::m_sFileCanonical, path_iter::m_sFilePath, and NULL.
Referenced by PathIsAbsolute(), and SearchPathIterNew().
| char* SearchPathIterFirst | ( | PathIter_T * | pIter, |
| const char * | sSearchFile | ||
| ) |
Get the first concatenated file path.
Initialize search path iterator from given search file and returns first concatenated file path.
| pIter | Path iterator. |
| sSearchFile | Search path. |
Definition at line 452 of file path.c.
References DIR_SEP_STR, LOGDIAG4, LOGERROR, LOGFUNCNAME, path_iter::m_bIsEos, path_iter::m_iterPaths, path_iter::m_nFileLen, path_iter::m_pSearchPaths, path_iter::m_sFileCanonical, path_iter::m_sFilePath, NewSearchPathCanonicalized(), NEWSTR, and NULL.
Referenced by PathIsAbsolute().
| PathIter_T* SearchPathIterNew | ( | const char * | sSearchPath | ) |
Allocates and initilized a new search path iterator.
This iterator can be reused multiple times with different search files by calling SearchPathIterFirst(). SearchPathIterDelete() must be called when finished with the iterator to clean up any allocated memory.
| sSearchPath | Search path of form: path [path_sep path...] |
Definition at line 398 of file path.c.
References LOGERROR, path_iter::m_bIsEos, path_iter::m_nFileLen, path_iter::m_pSearchPaths, path_iter::m_sFileCanonical, path_iter::m_sFilePath, NEW, NewSearchPathDList(), NULL, and SearchPathIterDelete().
Referenced by PathIsAbsolute().
| char* SearchPathIterNext | ( | PathIter_T * | pIter | ) |
Construct next file path from search path and search file name.
| pIter | Path iterator. |
Definition at line 526 of file path.c.
References DIR_SEP_STR, LOGDIAG4, LOGFUNCNAME, path_iter::m_bIsEos, path_iter::m_iterPaths, path_iter::m_nFileLen, path_iter::m_sFileCanonical, path_iter::m_sFilePath, NEWSTR, and NULL.
Referenced by PathIsAbsolute().