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