Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SAL_OSL_UNX_FILE_PATH_HELPER_HXX
21 : #define INCLUDED_SAL_OSL_UNX_FILE_PATH_HELPER_HXX
22 :
23 : #include <sal/types.h>
24 : #include <rtl/ustring.h>
25 : #include <rtl/ustring.hxx>
26 :
27 : /*******************************************
28 : osl_systemPathRemoveSeparator
29 : Removes the last separator from the
30 : given system path if any and if the path
31 : is not the root path '/'
32 :
33 : @param ppustrPath [inout] a system path
34 : if the path is not the root path
35 : and the last character is a
36 : path separator it will be cut off
37 : ppustrPath must not be NULL and
38 : must point to a valid rtl_uString
39 :
40 : @returns nothing
41 :
42 : ******************************************/
43 :
44 : void SAL_CALL osl_systemPathRemoveSeparator(
45 : /*inout*/ rtl_uString* pustrPath);
46 :
47 : /*******************************************
48 : osl_systemPathEnsureSeparator
49 : Adds a trailing path separator to the
50 : given system path if not already there
51 : and if the path is not the root path '/'
52 :
53 : @param pustrPath [inout] a system path
54 : if the path is not the root path
55 : '/' and has no trailing separator
56 : a separator will be added
57 : ppustrPath must not be NULL and
58 : must point to a valid rtl_uString
59 :
60 : @returns nothing
61 :
62 : ******************************************/
63 :
64 : void SAL_CALL osl_systemPathEnsureSeparator(
65 : rtl_uString** ppustrPath);
66 :
67 : /*******************************************
68 : osl_systemPathIsRelativePath
69 : Returns true if the given path is a
70 : relative path and so starts not with '/'
71 :
72 : @param pustrPath [in] a system path
73 : pustrPath must not be NULL
74 :
75 : @returns sal_True if the given path
76 : doesn't start with a separator
77 : else sal_False will be returned
78 :
79 : ******************************************/
80 :
81 : bool SAL_CALL osl_systemPathIsRelativePath(
82 : const rtl_uString* pustrPath);
83 :
84 : /******************************************
85 : osl_systemPathMakeAbsolutePath
86 : Append a relative path to a base path
87 :
88 : @param pustrBasePath [in] a system
89 : path that will be considered as
90 : base path
91 : pustrBasePath must not be NULL
92 :
93 : @param pustrRelPath [in] a system path
94 : that will be considered as
95 : relative path
96 : pustrBasePath must not be NULL
97 :
98 : @param ppustrAbsolutePath [out] the
99 : resulting path which is a
100 : concatination of the base and
101 : the relative path
102 : if base path is empty the
103 : resulting absolute path is the
104 : relative path
105 : if relative path is empty the
106 : resulting absolute path is the
107 : base path
108 : if base and relative path are
109 : empty the resulting absolute
110 : path is also empty
111 : ppustrAbsolutePath must not be
112 : NULL and *ppustrAbsolutePath
113 : must be 0 or point to a valid
114 : rtl_uString
115 :
116 : *****************************************/
117 :
118 : void SAL_CALL osl_systemPathMakeAbsolutePath(
119 : const rtl_uString* pustrBasePath,
120 : const rtl_uString* pustrRelPath,
121 : rtl_uString** ppustrAbsolutePath);
122 :
123 : /*****************************************
124 : osl_systemPathGetFileOrLastDirectoryPart
125 : Returns the file or the directory part
126 : of the given path
127 :
128 : @param pustrPath [in] a system path,
129 : must not be NULL
130 :
131 : @param ppustrFileOrDirPart [out] on
132 : return receives the last part
133 : of the given directory or the
134 : file name
135 : if pustrPath is the root path
136 : '/' an empty string will be
137 : returned
138 : if pustrPath has a trailing
139 : '/' the last part before the
140 : '/' will be returned else
141 : the part after the last '/'
142 : will be returned
143 :
144 : @returns nothing
145 :
146 : ****************************************/
147 :
148 : void SAL_CALL osl_systemPathGetFileNameOrLastDirectoryPart(
149 : const rtl_uString* pustrPath,
150 : rtl_uString** ppustrFileNameOrLastDirPart);
151 :
152 : /********************************************
153 : osl_systemPathIsHiddenFileOrDirectoryEntry
154 : Returns sal_True if the last part of
155 : given system path is not '.' or '..'
156 : alone and starts with a '.'
157 :
158 : @param pustrPath [in] a system path,
159 : must not be NULL
160 :
161 : @returns sal_True if the last part of
162 : the given system path starts
163 : with '.' or sal_False the last
164 : part is '.' or '..' alone or
165 : doesn't start with a dot
166 :
167 : *********************************************/
168 :
169 : bool SAL_CALL osl_systemPathIsHiddenFileOrDirectoryEntry(
170 : const rtl_uString* pustrPath);
171 :
172 : /************************************************
173 : osl_systemPathIsLocalOrParentDirectoryEntry
174 : Returns sal_True if the last part of the given
175 : system path is the local directory entry '.'
176 : or the parent directory entry '..'
177 :
178 : @param pustrPath [in] a system path,
179 : must not be NULL
180 :
181 : @returns sal_True if the last part of the
182 : given system path is '.' or '..'
183 : else sal_False
184 :
185 : ************************************************/
186 :
187 : bool SAL_CALL osl_systemPathIsLocalOrParentDirectoryEntry(
188 : const rtl_uString* pustrPath);
189 :
190 : /************************************************
191 : osl_searchPath
192 : Searches for a file name or path name in all
193 : directories specified by a given path list.
194 : Symbolic links in the resulting path will not be
195 : resolved, it's up to the caller to do this.
196 :
197 : @param pustrFilePath [in] a file name or
198 : directory name to search for, the name must
199 : be provided as system path not as a file URL
200 :
201 : @param pustrSearchPathList [in] a ':'
202 : separated list of paths in which to search for
203 : the file or directory name
204 :
205 : @param ppustrPathFound [out] on success receives the
206 : complete path of the file or directory found
207 : as a system path
208 :
209 : @returns sal_True if the specified file or
210 : directory was found else sal_False
211 : ***********************************************/
212 :
213 : bool SAL_CALL osl_searchPath(
214 : const rtl_uString* pustrFilePath,
215 : const rtl_uString* pustrSearchPathList,
216 : rtl_uString** ppustrPathFound);
217 :
218 : namespace osl
219 : {
220 :
221 : /*******************************************
222 : systemPathRemoveSeparator
223 : Removes the last separator from the
224 : given system path if any and if the path
225 : is not the root path '/'
226 :
227 : @param ppustrPath [inout] a system path
228 : if the path is not the root path
229 : and the last character is a
230 : path separator it will be cut off
231 : ppustrPath must not be NULL and
232 : must point to a valid rtl_uString
233 :
234 : @returns nothing
235 :
236 : ******************************************/
237 :
238 1549 : inline void systemPathRemoveSeparator(/*inout*/ rtl::OUString& Path)
239 : {
240 1549 : osl_systemPathRemoveSeparator(Path.pData);
241 1549 : }
242 :
243 : /*******************************************
244 : systemPathEnsureSeparator
245 : Adds a trailing path separator to the
246 : given system path if not already there
247 : and if the path is not the root path '/'
248 :
249 : @param pustrPath [inout] a system path
250 : if the path is not the root path
251 : '/' and has no trailing separator
252 : a separator will be added
253 : ppustrPath must not be NULL and
254 : must point to a valid rtl_uString
255 :
256 : @returns nothing
257 :
258 : ******************************************/
259 :
260 1234 : inline void systemPathEnsureSeparator(/*inout*/ rtl::OUString& Path)
261 : {
262 1234 : osl_systemPathEnsureSeparator(&Path.pData);
263 1234 : }
264 :
265 : /*******************************************
266 : systemPathIsRelativePath
267 : Returns true if the given path is a
268 : relative path and so starts not with '/'
269 :
270 : @param pustrPath [in] a system path
271 : pustrPath must not be NULL
272 :
273 : @returns sal_True if the given path
274 : doesn't start with a separator
275 : else sal_False will be returned
276 :
277 : ******************************************/
278 :
279 49392 : inline bool systemPathIsRelativePath(const rtl::OUString& Path)
280 : {
281 49392 : return osl_systemPathIsRelativePath(Path.pData);
282 : }
283 :
284 : /******************************************
285 : systemPathMakeAbsolutePath
286 : Append a relative path to a base path
287 :
288 : @param pustrBasePath [in] a system
289 : path that will be considered as
290 : base path
291 : pustrBasePath must not be NULL
292 :
293 : @param pustrRelPath [in] a system path
294 : that will be considered as
295 : relative path
296 : pustrBasePath must not be NULL
297 :
298 : @param ppustrAbsolutePath [out] the
299 : resulting path which is a
300 : concatination of the base and
301 : the relative path
302 : if base path is empty the
303 : resulting absolute path is the
304 : relative path
305 : if relative path is empty the
306 : resulting absolute path is the
307 : base path
308 : if base and relative path are
309 : empty the resulting absolute
310 : path is also empty
311 : ppustrAbsolutePath must not be
312 : NULL and *ppustrAbsolutePath
313 : must be 0 or point to a valid
314 : rtl_uString
315 :
316 : *****************************************/
317 :
318 85 : inline void systemPathMakeAbsolutePath(
319 : const rtl::OUString& BasePath,
320 : const rtl::OUString& RelPath,
321 : rtl::OUString& AbsolutePath)
322 : {
323 : osl_systemPathMakeAbsolutePath(
324 85 : BasePath.pData, RelPath.pData, &AbsolutePath.pData);
325 85 : }
326 :
327 : /********************************************
328 : systemPathIsHiddenFileOrDirectoryEntry
329 : Returns sal_True if the last part of
330 : given system path is not '.' or '..'
331 : alone and starts with a '.'
332 :
333 : @param pustrPath [in] a system path,
334 : must not be NULL
335 :
336 : @returns sal_True if the last part of
337 : the given system path starts
338 : with '.' or sal_False the last
339 : part is '.' or '..' alone or
340 : doesn't start with a dot
341 :
342 : *********************************************/
343 :
344 83014 : inline bool systemPathIsHiddenFileOrDirectoryEntry(
345 : const rtl::OUString& Path)
346 : {
347 83014 : return osl_systemPathIsHiddenFileOrDirectoryEntry(Path.pData);
348 : }
349 :
350 : /************************************************
351 : searchPath
352 : ***********************************************/
353 :
354 328 : inline bool searchPath(
355 : const rtl::OUString& ustrFilePath,
356 : const rtl::OUString& ustrSearchPathList,
357 : rtl::OUString& ustrPathFound)
358 : {
359 : return osl_searchPath(
360 : ustrFilePath.pData,
361 : ustrSearchPathList.pData,
362 328 : &ustrPathFound.pData);
363 : }
364 :
365 : } // namespace osl
366 :
367 : #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */
368 :
369 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|