xref: /trunk/main/sal/osl/os2/file_path_helper.h (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28  #ifndef _OSL_FILE_PATH_HELPER_H_
29  #define _OSL_FILE_PATH_HELPER_H_
30 
31 
32  #ifndef _SAL_TYPES_H_
33  #include <sal/types.h>
34  #endif
35 
36  #ifndef _RTL_USTRING_H_
37  #include <rtl/ustring.h>
38  #endif
39 
40 
41  #ifdef __cplusplus
42  extern "C"
43  {
44  #endif
45 
46 
47  /*******************************************
48     osl_systemPathRemoveSeparator
49     Removes the last separator from the
50     given system path if any and if the path
51     is not the root path '/'
52 
53     @param  ppustrPath [inout] a system path
54             if the path is not the root path
55             and the last character is a
56             path separator it will be cut off
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_systemPathRemoveSeparator(
65     /*inout*/ rtl_uString* pustrPath);
66 
67  /*******************************************
68     osl_systemPathEnsureSeparator
69     Adds a trailing path separator to the
70     given system path if not already there
71     and if the path is not the root path '/'
72 
73     @param  pustrPath [inout] a system path
74             if the path is not the root path
75             '/' and has no trailing separator
76             a separator will be added
77             ppustrPath must not be NULL and
78             must point to a valid rtl_uString
79 
80     @returns nothing
81 
82   ******************************************/
83 
84  void SAL_CALL osl_systemPathEnsureSeparator(
85     /*inout*/ rtl_uString** ppustrPath);
86 
87  /*******************************************
88     osl_systemPathIsRelativePath
89     Returns true if the given path is a
90     relative path and so starts not with '/'
91 
92     @param  pustrPath [in] a system path
93             pustrPath must not be NULL
94 
95     @returns sal_True if the given path
96              doesn't start with a separator
97              else sal_False will be returned
98 
99   ******************************************/
100 
101  sal_Bool SAL_CALL osl_systemPathIsRelativePath(
102     const rtl_uString* pustrPath);
103 
104  /******************************************
105     osl_systemPathIsAbsolutePath
106     Returns true if the given path is an
107     absolute path and so starts with a '/'
108 
109     @param pustrPath [in] a system path
110            pustrPath must not be NULL
111 
112     @returns sal_True if the given path
113              start's with a separator else
114              sal_False will be returned
115 
116   *****************************************/
117 
118  sal_Bool SAL_CALL osl_systemPathIsAbsolutePath(
119     const rtl_uString* pustrPath);
120 
121  /******************************************
122     osl_systemPathMakeAbsolutePath
123     Append a relative path to a base path
124 
125     @param  pustrBasePath [in] a system
126             path that will be considered as
127             base path
128             pustrBasePath must not be NULL
129 
130     @param  pustrRelPath [in] a system path
131             that will be considered as
132             relative path
133             pustrBasePath must not be NULL
134 
135     @param  ppustrAbsolutePath [out] the
136             resulting path which is a
137             concatination of the base and
138             the relative path
139             if base path is empty the
140             resulting absolute path is the
141             relative path
142             if relative path is empty the
143             resulting absolute path is the
144             base path
145             if base and relative path are
146             empty the resulting absolute
147             path is also empty
148             ppustrAbsolutePath must not be
149             NULL and *ppustrAbsolutePath
150             must be 0 or point to a valid
151             rtl_uString
152 
153   *****************************************/
154 
155  void SAL_CALL osl_systemPathMakeAbsolutePath(
156     const rtl_uString* pustrBasePath,
157     const rtl_uString* pustrRelPath,
158     rtl_uString**      ppustrAbsolutePath);
159 
160  /*****************************************
161     osl_systemPathGetParent
162     Replaces the last occurrance of a path
163     separator with '\0' and returns the
164     position where the '/' was replaced
165 
166     @param  pustrPath [inout] a system
167             path, the last separator of
168             this path will be replaced by
169             a '\0'
170             if the path is the root path
171             '/' or the path is considered
172             as to have no parent, e.g.
173             '/NoParent' or 'NoParent' or
174             the path is empty no
175             replacement will be made
176             pustrPath must not be NULL
177 
178     @returns the position of the last path
179              separator that was replaced
180              or 0 if no replacement took
181              place
182 
183   ****************************************/
184 
185  sal_Int32 SAL_CALL osl_systemPathGetParent(
186     /*inout*/ rtl_uString* pustrPath);
187 
188  /*****************************************
189     osl_systemPathGetFileOrLastDirectoryPart
190     Returns the file or the directory part
191     of the given path
192 
193     @param pustrPath [in] a system path,
194            must not be NULL
195 
196     @param ppustrFileOrDirPart [out] on
197            return receives the last part
198            of the given directory or the
199            file name
200            if pustrPath is the root path
201            '/' an empty string will be
202            returned
203            if pustrPath has a trailing
204            '/' the last part before the
205            '/' will be returned else
206            the part after the last '/'
207            will be returned
208 
209     @returns nothing
210 
211   ****************************************/
212  void SAL_CALL osl_systemPathGetFileNameOrLastDirectoryPart(
213     const rtl_uString*  pustrPath,
214     rtl_uString**       ppustrFileNameOrLastDirPart);
215 
216 
217  /********************************************
218     osl_systemPathIsHiddenFileOrDirectoryEntry
219     Returns sal_True if the last part of
220     given system path is not '.' or '..'
221     alone and starts with a '.'
222 
223     @param pustrPath [in] a system path,
224            must not be NULL
225 
226     @returns sal_True if the last part of
227              the given system path starts
228              with '.' or sal_False the last
229              part is '.' or '..' alone or
230              doesn't start with a dot
231 
232  *********************************************/
233 
234  sal_Bool SAL_CALL osl_systemPathIsHiddenFileOrDirectoryEntry(
235     const rtl_uString* pustrPath);
236 
237 
238  /************************************************
239     osl_systemPathIsLocalOrParentDirectoryEntry
240     Returns sal_True if the last part of the given
241     system path is the local directory entry '.'
242     or the parent directory entry '..'
243 
244     @param pustrPath [in] a system path,
245            must not be NULL
246 
247     @returns sal_True if the last part of the
248              given system path is '.' or '..'
249              else sal_False
250 
251  ************************************************/
252 
253  sal_Bool SAL_CALL osl_systemPathIsLocalOrParentDirectoryEntry(
254     const rtl_uString* pustrPath);
255 
256 
257  /************************************************
258     osl_searchPath
259     Searches for a file name or path name in all
260     directories specified by a given path list.
261     Symbolic links in the resulting path will not be
262     resolved, it's up to the caller to do this.
263 
264     @param pustrFilePath [in] a file name or
265     directory name to search for, the name must
266     be provided as system path not as a file URL
267 
268     @param pustrSearchPathList [in] a ':'
269     separated list of paths in which to search for
270     the file or directory name
271 
272     @ppustrPathFound [out] on success receives the
273     complete path of the file or directory found
274     as a system path
275 
276     @returns sal_True if the specified file or
277     directory was found else sal_False
278   ***********************************************/
279 
280  sal_Bool SAL_CALL osl_searchPath(
281     const rtl_uString* pustrFilePath,
282     const rtl_uString* pustrSearchPathList,
283     rtl_uString**      ppustrPathFound);
284 
285 
286  #ifdef __cplusplus
287  }
288  #endif
289 
290 
291  #endif /* #ifndef _OSL_PATH_HELPER_H_ */
292 
293