xref: /trunk/main/sal/osl/unx/file_path_helper.hxx (revision 565d668c)
1*565d668cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*565d668cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*565d668cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*565d668cSAndrew Rist  * distributed with this work for additional information
6*565d668cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*565d668cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*565d668cSAndrew Rist  * "License"); you may not use this file except in compliance
9*565d668cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*565d668cSAndrew Rist  *
11*565d668cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*565d668cSAndrew Rist  *
13*565d668cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*565d668cSAndrew Rist  * software distributed under the License is distributed on an
15*565d668cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*565d668cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*565d668cSAndrew Rist  * specific language governing permissions and limitations
18*565d668cSAndrew Rist  * under the License.
19*565d668cSAndrew Rist  *
20*565d668cSAndrew Rist  *************************************************************/
21*565d668cSAndrew Rist 
22*565d668cSAndrew 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     systemPathMakeAbsolutePath
103cdf0e10cSrcweir     Append a relative path to a base path
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	@param	pustrBasePath [in] a system
106cdf0e10cSrcweir 			path that will be considered as
107cdf0e10cSrcweir 			base path
108cdf0e10cSrcweir 			pustrBasePath must not be NULL
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	@param	pustrRelPath [in] a system path
111cdf0e10cSrcweir 			that will be considered as
112cdf0e10cSrcweir 			relative path
113cdf0e10cSrcweir 			pustrBasePath must not be NULL
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	@param	ppustrAbsolutePath [out] the
116cdf0e10cSrcweir 			resulting path which is a
117cdf0e10cSrcweir 			concatination of the base and
118cdf0e10cSrcweir 			the relative path
119cdf0e10cSrcweir 			if base path is empty the
120cdf0e10cSrcweir 			resulting absolute path is the
121cdf0e10cSrcweir 			relative path
122cdf0e10cSrcweir 			if relative path is empty the
123cdf0e10cSrcweir 			resulting absolute path is the
124cdf0e10cSrcweir 			base path
125cdf0e10cSrcweir 			if base and relative path are
126cdf0e10cSrcweir 			empty the resulting absolute
127cdf0e10cSrcweir 			path is also empty
128cdf0e10cSrcweir 			ppustrAbsolutePath must not be
129cdf0e10cSrcweir 			NULL and *ppustrAbsolutePath
130cdf0e10cSrcweir 			must be 0 or point to a valid
131cdf0e10cSrcweir 			rtl_uString
132cdf0e10cSrcweir 
133cdf0e10cSrcweir   *****************************************/
134cdf0e10cSrcweir 
systemPathMakeAbsolutePath(const rtl::OUString & BasePath,const rtl::OUString & RelPath,rtl::OUString & AbsolutePath)135cdf0e10cSrcweir  inline void systemPathMakeAbsolutePath(
136cdf0e10cSrcweir  	const rtl::OUString& BasePath,
137cdf0e10cSrcweir 	const rtl::OUString& RelPath,
138cdf0e10cSrcweir 	rtl::OUString& 	     AbsolutePath)
139cdf0e10cSrcweir  {
140cdf0e10cSrcweir 	osl_systemPathMakeAbsolutePath(
141cdf0e10cSrcweir 		BasePath.pData, RelPath.pData, &AbsolutePath.pData);
142cdf0e10cSrcweir  }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir  /*****************************************
145cdf0e10cSrcweir  	systemPathGetFileOrLastDirectoryPart
146cdf0e10cSrcweir 	Returns the file or the directory part
147cdf0e10cSrcweir 	of the given path
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	@param pustrPath [in] a system path,
150cdf0e10cSrcweir 		   must not be NULL
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	@param ppustrFileOrDirPart [out] on
153cdf0e10cSrcweir 		   return receives the last part
154cdf0e10cSrcweir 		   of the given directory or the
155cdf0e10cSrcweir 		   file name
156cdf0e10cSrcweir 		   if pustrPath is the root path
157cdf0e10cSrcweir 		   '/' an empty string will be
158cdf0e10cSrcweir 		   returned
159cdf0e10cSrcweir 		   if pustrPath has a trailing
160cdf0e10cSrcweir 		   '/' the last part before the
161cdf0e10cSrcweir 		   '/' will be returned else
162cdf0e10cSrcweir 		   the part after the last '/'
163cdf0e10cSrcweir 		   will be returned
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	@returns nothing
166cdf0e10cSrcweir 
167cdf0e10cSrcweir   ****************************************/
168cdf0e10cSrcweir 
systemPathGetFileNameOrLastDirectoryPart(const rtl::OUString & Path,rtl::OUString & FileNameOrLastDirPart)169cdf0e10cSrcweir  inline void systemPathGetFileNameOrLastDirectoryPart(
170cdf0e10cSrcweir  	const rtl::OUString& Path,
171cdf0e10cSrcweir 	rtl::OUString& 		 FileNameOrLastDirPart)
172cdf0e10cSrcweir  {
173cdf0e10cSrcweir 	osl_systemPathGetFileNameOrLastDirectoryPart(
174cdf0e10cSrcweir 		Path.pData, &FileNameOrLastDirPart.pData);
175cdf0e10cSrcweir  }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 
178cdf0e10cSrcweir  /********************************************
179cdf0e10cSrcweir  	systemPathIsHiddenFileOrDirectoryEntry
180cdf0e10cSrcweir 	Returns sal_True if the last part of
181cdf0e10cSrcweir 	given system path is not '.' or '..'
182cdf0e10cSrcweir 	alone and starts with a '.'
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	@param pustrPath [in] a system path,
185cdf0e10cSrcweir 		   must not be NULL
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 	@returns sal_True if the last part of
188cdf0e10cSrcweir 			 the given system path starts
189cdf0e10cSrcweir 			 with '.' or sal_False the last
190cdf0e10cSrcweir 			 part is '.' or	'..' alone or
191cdf0e10cSrcweir 			 doesn't start with a dot
192cdf0e10cSrcweir 
193cdf0e10cSrcweir  *********************************************/
194cdf0e10cSrcweir 
systemPathIsHiddenFileOrDirectoryEntry(const rtl::OUString & Path)195cdf0e10cSrcweir  inline bool systemPathIsHiddenFileOrDirectoryEntry(
196cdf0e10cSrcweir  	const rtl::OUString& Path)
197cdf0e10cSrcweir  {
198cdf0e10cSrcweir 	return osl_systemPathIsHiddenFileOrDirectoryEntry(Path.pData);
199cdf0e10cSrcweir  }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 
202cdf0e10cSrcweir  /************************************************
203cdf0e10cSrcweir  	systemPathIsLocalOrParentDirectoryEntry
204cdf0e10cSrcweir 	Returns sal_True if the last part of the given
205cdf0e10cSrcweir 	system path is the local directory entry '.'
206cdf0e10cSrcweir 	or the parent directory entry '..'
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	@param pustrPath [in] a system path,
209cdf0e10cSrcweir 		   must not be NULL
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	@returns sal_True if the last part of the
212cdf0e10cSrcweir 			 given system path is '.' or '..'
213cdf0e10cSrcweir 			 else sal_False
214cdf0e10cSrcweir 
215cdf0e10cSrcweir  ************************************************/
216cdf0e10cSrcweir 
systemPathIsLocalOrParentDirectoryEntry(const rtl::OUString & Path)217cdf0e10cSrcweir  inline bool systemPathIsLocalOrParentDirectoryEntry(
218cdf0e10cSrcweir  	const rtl::OUString& Path)
219cdf0e10cSrcweir  {
220cdf0e10cSrcweir 	return osl_systemPathIsLocalOrParentDirectoryEntry(Path.pData);
221cdf0e10cSrcweir  }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir  /************************************************
224cdf0e10cSrcweir   searchPath
225cdf0e10cSrcweir   ***********************************************/
226cdf0e10cSrcweir 
searchPath(const rtl::OUString & ustrFilePath,const rtl::OUString & ustrSearchPathList,rtl::OUString & ustrPathFound)227cdf0e10cSrcweir  inline bool searchPath(
228cdf0e10cSrcweir  	const rtl::OUString& ustrFilePath,
229cdf0e10cSrcweir 	const rtl::OUString& ustrSearchPathList,
230cdf0e10cSrcweir 	rtl::OUString& ustrPathFound)
231cdf0e10cSrcweir  {
232cdf0e10cSrcweir  	return osl_searchPath(
233cdf0e10cSrcweir 		ustrFilePath.pData,
234cdf0e10cSrcweir 		ustrSearchPathList.pData,
235cdf0e10cSrcweir 		&ustrPathFound.pData);
236cdf0e10cSrcweir  }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 
239cdf0e10cSrcweir  } // namespace osl
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 
242cdf0e10cSrcweir  #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */
243cdf0e10cSrcweir 
244