1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SAL_OSL_UNX_FILE_PATH_HELPER_HXX
21 #define INCLUDED_SAL_OSL_UNX_FILE_PATH_HELPER_HXX
23 #include <rtl/ustring.h>
24 #include <rtl/ustring.hxx>
27 Removes the last separator from the given system path if any and if the path
28 is not the root path '/'
30 @param ppstrPath[inout] a system path if the path is not the root path
31 and the last character is a path separator it
32 will be cut off ppstrPath must not be NULL and
33 must point to a valid rtl_String
38 void osl_systemPathRemoveSeparator(rtl_String
* pstrPath
);
41 Returns true if the given path is a relative path and so starts not with '/'
43 @param pustrPath [in] a system path - must not be NULL
45 @retval sal_True the given path doesn't start with a separator
46 @retval sal_False the given path starts with a separator
49 bool osl_systemPathIsRelativePath(
50 const rtl_uString
* pustrPath
);
53 Returns the file or the directory part of the given path
55 @param pstrPath [in] a system path, must not be NULL
57 @param ppstrFileOrDirPart [out] on return receives the last part of the
58 given directory or the file name if pstrPath is the
59 root path '/' an empty string will be returned if
60 pstrPath has a trailing '/' the last part before the
61 '/' will be returned else the part after the last '/'
67 void osl_systemPathGetFileNameOrLastDirectoryPart(
68 const rtl_String
* pstrPath
,
69 rtl_String
** ppstrFileNameOrLastDirPart
);
72 @param pustrPath [in] a system path, must not be NULL
74 @retval sal_True the last part of the given system path starts with '.'
75 @retval sal_False the last part of the given system path is '.' or '..'
76 alone or doesn't start with a dot
79 bool osl_systemPathIsHiddenFileOrDirectoryEntry(
80 const rtl_String
* pustrPath
);
82 /************************************************
83 osl_systemPathIsLocalOrParentDirectoryEntry
84 Returns sal_True if the last part of the given
85 system path is the local directory entry '.'
86 or the parent directory entry '..'
88 @param pstrPath [in] a system path,
91 @returns sal_True if the last part of the
92 given system path is '.' or '..'
95 ************************************************/
97 bool osl_systemPathIsLocalOrParentDirectoryEntry(
98 const rtl_String
* pstrPath
);
100 /************************************************
102 Searches for a file name or path name in all
103 directories specified by a given path list.
104 Symbolic links in the resulting path will not be
105 resolved, it's up to the caller to do this.
107 @param pustrFilePath [in] a file name or
108 directory name to search for, the name must
109 be provided as system path not as a file URL
111 @param pustrSearchPathList [in] a ':'
112 separated list of paths in which to search for
113 the file or directory name
115 @param ppustrPathFound [out] on success receives the
116 complete path of the file or directory found
119 @returns sal_True if the specified file or
120 directory was found else sal_False
121 ***********************************************/
124 const rtl_uString
* pustrFilePath
,
125 const rtl_uString
* pustrSearchPathList
,
126 rtl_uString
** ppustrPathFound
);
131 /*******************************************
132 systemPathRemoveSeparator
133 Removes the last separator from the
134 given system path if any and if the path
135 is not the root path '/'
137 @param ppustrPath [inout] a system path
138 if the path is not the root path
139 and the last character is a
140 path separator it will be cut off
141 ppustrPath must not be NULL and
142 must point to a valid rtl_uString
146 ******************************************/
148 inline void systemPathRemoveSeparator(/*inout*/ OString
& Path
)
150 osl_systemPathRemoveSeparator(Path
.pData
);
153 /*******************************************
154 systemPathIsRelativePath
155 Returns true if the given path is a
156 relative path and so starts not with '/'
158 @param pustrPath [in] a system path
159 pustrPath must not be NULL
161 @returns sal_True if the given path
162 doesn't start with a separator
163 else sal_False will be returned
165 ******************************************/
167 inline bool systemPathIsRelativePath(const OUString
& Path
)
169 return osl_systemPathIsRelativePath(Path
.pData
);
172 /******************************************
173 systemPathMakeAbsolutePath
174 Append a relative path to a base path
176 @param BasePath [in] a system
177 path that will be considered as
180 @param RelPath [in] a system path
181 that will be considered as
185 resulting path which is a
186 concatenation of the base and
188 if base path is empty the
189 resulting absolute path is the
191 if relative path is empty the
192 resulting absolute path is the
194 if base and relative path are
195 empty the resulting absolute
198 *****************************************/
200 OString
systemPathMakeAbsolutePath(
201 const OString
& BasePath
,
202 const OString
& RelPath
);
204 OUString
systemPathMakeAbsolutePath(
205 const OUString
& BasePath
,
206 const OUString
& RelPath
);
208 /********************************************
209 systemPathIsHiddenFileOrDirectoryEntry
210 Returns sal_True if the last part of
211 given system path is not '.' or '..'
212 alone and starts with a '.'
214 @param pustrPath [in] a system path,
217 @returns sal_True if the last part of
218 the given system path starts
219 with '.' or sal_False the last
220 part is '.' or '..' alone or
221 doesn't start with a dot
223 *********************************************/
225 inline bool systemPathIsHiddenFileOrDirectoryEntry(
228 return osl_systemPathIsHiddenFileOrDirectoryEntry(Path
.pData
);
231 /************************************************
233 ***********************************************/
235 inline bool searchPath(
236 const OUString
& ustrFilePath
,
237 const OUString
& ustrSearchPathList
,
238 OUString
& ustrPathFound
)
240 return osl_searchPath(
242 ustrSearchPathList
.pData
,
243 &ustrPathFound
.pData
);
248 #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */