xref: /AOO41X/main/sal/osl/os2/file_path_helper.h (revision 9eab2a37907b512d383f1547f0e04306f43e3fd9)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24  #ifndef _OSL_FILE_PATH_HELPER_H_
25  #define _OSL_FILE_PATH_HELPER_H_
26 
27 
28  #ifndef _SAL_TYPES_H_
29  #include <sal/types.h>
30  #endif
31 
32  #ifndef _RTL_USTRING_H_
33  #include <rtl/ustring.h>
34  #endif
35 
36 
37  #ifdef __cplusplus
38  extern "C"
39  {
40  #endif
41 
42 
43  /*******************************************
44     osl_systemPathRemoveSeparator
45     Removes the last separator from the
46     given system path if any and if the path
47     is not the root path '/'
48 
49     @param  ppustrPath [inout] a system path
50             if the path is not the root path
51             and the last character is a
52             path separator it will be cut off
53             ppustrPath must not be NULL and
54             must point to a valid rtl_uString
55 
56     @returns nothing
57 
58   ******************************************/
59 
60  void SAL_CALL osl_systemPathRemoveSeparator(
61     /*inout*/ rtl_uString* pustrPath);
62 
63  /*******************************************
64     osl_systemPathEnsureSeparator
65     Adds a trailing path separator to the
66     given system path if not already there
67     and if the path is not the root path '/'
68 
69     @param  pustrPath [inout] a system path
70             if the path is not the root path
71             '/' and has no trailing separator
72             a separator will be added
73             ppustrPath must not be NULL and
74             must point to a valid rtl_uString
75 
76     @returns nothing
77 
78   ******************************************/
79 
80  void SAL_CALL osl_systemPathEnsureSeparator(
81     /*inout*/ rtl_uString** ppustrPath);
82 
83  /*******************************************
84     osl_systemPathIsRelativePath
85     Returns true if the given path is a
86     relative path and so starts not with '/'
87 
88     @param  pustrPath [in] a system path
89             pustrPath must not be NULL
90 
91     @returns sal_True if the given path
92              doesn't start with a separator
93              else sal_False will be returned
94 
95   ******************************************/
96 
97  sal_Bool SAL_CALL osl_systemPathIsRelativePath(
98     const rtl_uString* pustrPath);
99 
100  /******************************************
101     osl_systemPathIsAbsolutePath
102     Returns true if the given path is an
103     absolute path and so starts with a '/'
104 
105     @param pustrPath [in] a system path
106            pustrPath must not be NULL
107 
108     @returns sal_True if the given path
109              start's with a separator else
110              sal_False will be returned
111 
112   *****************************************/
113 
114  sal_Bool SAL_CALL osl_systemPathIsAbsolutePath(
115     const rtl_uString* pustrPath);
116 
117  /******************************************
118     osl_systemPathMakeAbsolutePath
119     Append a relative path to a base path
120 
121     @param  pustrBasePath [in] a system
122             path that will be considered as
123             base path
124             pustrBasePath must not be NULL
125 
126     @param  pustrRelPath [in] a system path
127             that will be considered as
128             relative path
129             pustrBasePath must not be NULL
130 
131     @param  ppustrAbsolutePath [out] the
132             resulting path which is a
133             concatination of the base and
134             the relative path
135             if base path is empty the
136             resulting absolute path is the
137             relative path
138             if relative path is empty the
139             resulting absolute path is the
140             base path
141             if base and relative path are
142             empty the resulting absolute
143             path is also empty
144             ppustrAbsolutePath must not be
145             NULL and *ppustrAbsolutePath
146             must be 0 or point to a valid
147             rtl_uString
148 
149   *****************************************/
150 
151  void SAL_CALL osl_systemPathMakeAbsolutePath(
152     const rtl_uString* pustrBasePath,
153     const rtl_uString* pustrRelPath,
154     rtl_uString**      ppustrAbsolutePath);
155 
156  /*****************************************
157     osl_systemPathGetParent
158     Replaces the last occurrance of a path
159     separator with '\0' and returns the
160     position where the '/' was replaced
161 
162     @param  pustrPath [inout] a system
163             path, the last separator of
164             this path will be replaced by
165             a '\0'
166             if the path is the root path
167             '/' or the path is considered
168             as to have no parent, e.g.
169             '/NoParent' or 'NoParent' or
170             the path is empty no
171             replacement will be made
172             pustrPath must not be NULL
173 
174     @returns the position of the last path
175              separator that was replaced
176              or 0 if no replacement took
177              place
178 
179   ****************************************/
180 
181  sal_Int32 SAL_CALL osl_systemPathGetParent(
182     /*inout*/ rtl_uString* pustrPath);
183 
184  /*****************************************
185     osl_systemPathGetFileOrLastDirectoryPart
186     Returns the file or the directory part
187     of the given path
188 
189     @param pustrPath [in] a system path,
190            must not be NULL
191 
192     @param ppustrFileOrDirPart [out] on
193            return receives the last part
194            of the given directory or the
195            file name
196            if pustrPath is the root path
197            '/' an empty string will be
198            returned
199            if pustrPath has a trailing
200            '/' the last part before the
201            '/' will be returned else
202            the part after the last '/'
203            will be returned
204 
205     @returns nothing
206 
207   ****************************************/
208  void SAL_CALL osl_systemPathGetFileNameOrLastDirectoryPart(
209     const rtl_uString*  pustrPath,
210     rtl_uString**       ppustrFileNameOrLastDirPart);
211 
212 
213  /********************************************
214     osl_systemPathIsHiddenFileOrDirectoryEntry
215     Returns sal_True if the last part of
216     given system path is not '.' or '..'
217     alone and starts with a '.'
218 
219     @param pustrPath [in] a system path,
220            must not be NULL
221 
222     @returns sal_True if the last part of
223              the given system path starts
224              with '.' or sal_False the last
225              part is '.' or '..' alone or
226              doesn't start with a dot
227 
228  *********************************************/
229 
230  sal_Bool SAL_CALL osl_systemPathIsHiddenFileOrDirectoryEntry(
231     const rtl_uString* pustrPath);
232 
233 
234  /************************************************
235     osl_systemPathIsLocalOrParentDirectoryEntry
236     Returns sal_True if the last part of the given
237     system path is the local directory entry '.'
238     or the parent directory entry '..'
239 
240     @param pustrPath [in] a system path,
241            must not be NULL
242 
243     @returns sal_True if the last part of the
244              given system path is '.' or '..'
245              else sal_False
246 
247  ************************************************/
248 
249  sal_Bool SAL_CALL osl_systemPathIsLocalOrParentDirectoryEntry(
250     const rtl_uString* pustrPath);
251 
252 
253  /************************************************
254     osl_searchPath
255     Searches for a file name or path name in all
256     directories specified by a given path list.
257     Symbolic links in the resulting path will not be
258     resolved, it's up to the caller to do this.
259 
260     @param pustrFilePath [in] a file name or
261     directory name to search for, the name must
262     be provided as system path not as a file URL
263 
264     @param pustrSearchPathList [in] a ':'
265     separated list of paths in which to search for
266     the file or directory name
267 
268     @ppustrPathFound [out] on success receives the
269     complete path of the file or directory found
270     as a system path
271 
272     @returns sal_True if the specified file or
273     directory was found else sal_False
274   ***********************************************/
275 
276  sal_Bool SAL_CALL osl_searchPath(
277     const rtl_uString* pustrFilePath,
278     const rtl_uString* pustrSearchPathList,
279     rtl_uString**      ppustrPathFound);
280 
281 
282  #ifdef __cplusplus
283  }
284  #endif
285 
286 
287  #endif /* #ifndef _OSL_PATH_HELPER_H_ */
288 
289