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