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