Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sal / osl / unx / file_path_helper.hxx
blobe210b27a3866206976439c4d88976431a3376a3a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SAL_OSL_UNX_FILE_PATH_HELPER_HXX
21 #define INCLUDED_SAL_OSL_UNX_FILE_PATH_HELPER_HXX
23 #include <sal/types.h>
24 #include <rtl/ustring.h>
25 #include <rtl/ustring.hxx>
27 /**
28 Removes the last separator from the given system path if any and if the path
29 is not the root path '/'
31 @param ppstrPath[inout] a system path if the path is not the root path
32 and the last character is a path separator it
33 will be cut off ppstrPath must not be NULL and
34 must point to a valid rtl_String
36 @returns nothing
39 void osl_systemPathRemoveSeparator(rtl_String* pstrPath);
41 /**
42 Returns true if the given path is a relative path and so starts not with '/'
44 @param pustrPath [in] a system path - must not be NULL
46 @retval sal_True the given path doesn't start with a separator
47 @retval sal_False the given path starts with a separator
50 bool osl_systemPathIsRelativePath(
51 const rtl_uString* pustrPath);
53 /**
54 Returns the file or the directory part of the given path
56 @param pstrPath [in] a system path, must not be NULL
58 @param ppstrFileOrDirPart [out] on return receives the last part of the
59 given directory or the file name if pstrPath is the
60 root path '/' an empty string will be returned if
61 pstrPath has a trailing '/' the last part before the
62 '/' will be returned else the part after the last '/'
63 will be returned
65 @returns nothing
68 void osl_systemPathGetFileNameOrLastDirectoryPart(
69 const rtl_String* pstrPath,
70 rtl_String** ppstrFileNameOrLastDirPart);
72 /**
73 @param pustrPath [in] a system path, must not be NULL
75 @retval sal_True the last part of the given system path starts with '.'
76 @retval sal_False the last part of the given system path is '.' or '..'
77 alone or doesn't start with a dot
80 bool osl_systemPathIsHiddenFileOrDirectoryEntry(
81 const rtl_String* pustrPath);
83 /************************************************
84 osl_systemPathIsLocalOrParentDirectoryEntry
85 Returns sal_True if the last part of the given
86 system path is the local directory entry '.'
87 or the parent directory entry '..'
89 @param pstrPath [in] a system path,
90 must not be NULL
92 @returns sal_True if the last part of the
93 given system path is '.' or '..'
94 else sal_False
96 ************************************************/
98 bool osl_systemPathIsLocalOrParentDirectoryEntry(
99 const rtl_String* pstrPath);
101 /************************************************
102 osl_searchPath
103 Searches for a file name or path name in all
104 directories specified by a given path list.
105 Symbolic links in the resulting path will not be
106 resolved, it's up to the caller to do this.
108 @param pustrFilePath [in] a file name or
109 directory name to search for, the name must
110 be provided as system path not as a file URL
112 @param pustrSearchPathList [in] a ':'
113 separated list of paths in which to search for
114 the file or directory name
116 @param ppustrPathFound [out] on success receives the
117 complete path of the file or directory found
118 as a system path
120 @returns sal_True if the specified file or
121 directory was found else sal_False
122 ***********************************************/
124 bool osl_searchPath(
125 const rtl_uString* pustrFilePath,
126 const rtl_uString* pustrSearchPathList,
127 rtl_uString** ppustrPathFound);
129 namespace osl
132 /*******************************************
133 systemPathRemoveSeparator
134 Removes the last separator from the
135 given system path if any and if the path
136 is not the root path '/'
138 @param ppustrPath [inout] a system path
139 if the path is not the root path
140 and the last character is a
141 path separator it will be cut off
142 ppustrPath must not be NULL and
143 must point to a valid rtl_uString
145 @returns nothing
147 ******************************************/
149 inline void systemPathRemoveSeparator(/*inout*/ OString& Path)
151 osl_systemPathRemoveSeparator(Path.pData);
154 /*******************************************
155 systemPathIsRelativePath
156 Returns true if the given path is a
157 relative path and so starts not with '/'
159 @param pustrPath [in] a system path
160 pustrPath must not be NULL
162 @returns sal_True if the given path
163 doesn't start with a separator
164 else sal_False will be returned
166 ******************************************/
168 inline bool systemPathIsRelativePath(const OUString& Path)
170 return osl_systemPathIsRelativePath(Path.pData);
173 /******************************************
174 systemPathMakeAbsolutePath
175 Append a relative path to a base path
177 @param BasePath [in] a system
178 path that will be considered as
179 base path
181 @param RelPath [in] a system path
182 that will be considered as
183 relative path
185 @return the
186 resulting path which is a
187 concatenation of the base and
188 the relative path
189 if base path is empty the
190 resulting absolute path is the
191 relative path
192 if relative path is empty the
193 resulting absolute path is the
194 base path
195 if base and relative path are
196 empty the resulting absolute
197 path is also empty
199 *****************************************/
201 OString systemPathMakeAbsolutePath(
202 const OString& BasePath,
203 const OString& RelPath);
205 OUString systemPathMakeAbsolutePath(
206 const OUString& BasePath,
207 const OUString& RelPath);
209 /********************************************
210 systemPathIsHiddenFileOrDirectoryEntry
211 Returns sal_True if the last part of
212 given system path is not '.' or '..'
213 alone and starts with a '.'
215 @param pustrPath [in] a system path,
216 must not be NULL
218 @returns sal_True if the last part of
219 the given system path starts
220 with '.' or sal_False the last
221 part is '.' or '..' alone or
222 doesn't start with a dot
224 *********************************************/
226 inline bool systemPathIsHiddenFileOrDirectoryEntry(
227 const OString& Path)
229 return osl_systemPathIsHiddenFileOrDirectoryEntry(Path.pData);
232 /************************************************
233 searchPath
234 ***********************************************/
236 inline bool searchPath(
237 const OUString& ustrFilePath,
238 const OUString& ustrSearchPathList,
239 OUString& ustrPathFound)
241 return osl_searchPath(
242 ustrFilePath.pData,
243 ustrSearchPathList.pData,
244 &ustrPathFound.pData);
247 } // namespace osl
249 #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */