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