1 | /** @file
|
---|
2 | * IPRT - Path Manipulation.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2017 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___iprt_path_h
|
---|
27 | #define ___iprt_path_h
|
---|
28 |
|
---|
29 | #include <iprt/cdefs.h>
|
---|
30 | #include <iprt/types.h>
|
---|
31 | #ifdef IN_RING3
|
---|
32 | # include <iprt/fs.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 | RT_C_DECLS_BEGIN
|
---|
38 |
|
---|
39 | /** @defgroup grp_rt_path RTPath - Path Manipulation
|
---|
40 | * @ingroup grp_rt
|
---|
41 | * @{
|
---|
42 | */
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Host max path (the reasonable value).
|
---|
46 | * @remarks defined both by iprt/param.h and iprt/path.h.
|
---|
47 | */
|
---|
48 | #if !defined(___iprt_param_h) || defined(DOXYGEN_RUNNING)
|
---|
49 | # define RTPATH_MAX (4096 + 4) /* (PATH_MAX + 1) on linux w/ some alignment */
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | /** @def RTPATH_TAG
|
---|
53 | * The default allocation tag used by the RTPath allocation APIs.
|
---|
54 | *
|
---|
55 | * When not defined before the inclusion of iprt/string.h, this will default to
|
---|
56 | * the pointer to the current file name. The string API will make of use of
|
---|
57 | * this as pointer to a volatile but read-only string.
|
---|
58 | */
|
---|
59 | #ifndef RTPATH_TAG
|
---|
60 | # define RTPATH_TAG (__FILE__)
|
---|
61 | #endif
|
---|
62 |
|
---|
63 |
|
---|
64 | /** @name RTPATH_F_XXX - Generic flags for APIs working on the file system.
|
---|
65 | * @{ */
|
---|
66 | /** Last component: Work on the link. */
|
---|
67 | #define RTPATH_F_ON_LINK RT_BIT_32(0)
|
---|
68 | /** Last component: Follow if link. */
|
---|
69 | #define RTPATH_F_FOLLOW_LINK RT_BIT_32(1)
|
---|
70 | /** Don't allow symbolic links as part of the path.
|
---|
71 | * @remarks this flag is currently not implemented and will be ignored. */
|
---|
72 | #define RTPATH_F_NO_SYMLINKS RT_BIT_32(2)
|
---|
73 | /** @} */
|
---|
74 |
|
---|
75 | /** Validates a flags parameter containing RTPATH_F_*.
|
---|
76 | * @remarks The parameters will be referenced multiple times. */
|
---|
77 | #define RTPATH_F_IS_VALID(a_fFlags, a_fIgnore) \
|
---|
78 | ( ((a_fFlags) & ~(uint32_t)((a_fIgnore) | RTPATH_F_NO_SYMLINKS)) == RTPATH_F_ON_LINK \
|
---|
79 | || ((a_fFlags) & ~(uint32_t)((a_fIgnore) | RTPATH_F_NO_SYMLINKS)) == RTPATH_F_FOLLOW_LINK )
|
---|
80 |
|
---|
81 |
|
---|
82 | /** @name RTPATH_STR_F_XXX - Generic flags for APIs working with path strings.
|
---|
83 | * @{
|
---|
84 | */
|
---|
85 | /** Host OS path style (default 0 value). */
|
---|
86 | #define RTPATH_STR_F_STYLE_HOST UINT32_C(0x00000000)
|
---|
87 | /** DOS, OS/2 and Windows path style. */
|
---|
88 | #define RTPATH_STR_F_STYLE_DOS UINT32_C(0x00000001)
|
---|
89 | /** Unix path style. */
|
---|
90 | #define RTPATH_STR_F_STYLE_UNIX UINT32_C(0x00000002)
|
---|
91 | /** Reserved path style. */
|
---|
92 | #define RTPATH_STR_F_STYLE_RESERVED UINT32_C(0x00000003)
|
---|
93 | /** The path style mask. */
|
---|
94 | #define RTPATH_STR_F_STYLE_MASK UINT32_C(0x00000003)
|
---|
95 | /** Partial path - no start.
|
---|
96 | * This causes the API to skip the root specification parsing. */
|
---|
97 | #define RTPATH_STR_F_NO_START UINT32_C(0x00000010)
|
---|
98 | /** Partial path - no end.
|
---|
99 | * This causes the API to skip the filename and dir-slash parsing. */
|
---|
100 | #define RTPATH_STR_F_NO_END UINT32_C(0x00000020)
|
---|
101 | /** Partial path - no start and no end. */
|
---|
102 | #define RTPATH_STR_F_MIDDLE (RTPATH_STR_F_NO_START | RTPATH_STR_F_NO_END)
|
---|
103 |
|
---|
104 | /** Reserved for future use. */
|
---|
105 | #define RTPATH_STR_F_RESERVED_MASK UINT32_C(0x0000ffcc)
|
---|
106 | /** @} */
|
---|
107 |
|
---|
108 | /** Validates a flags parameter containing RTPATH_FSTR_.
|
---|
109 | * @remarks The parameters will be references multiple times. */
|
---|
110 | #define RTPATH_STR_F_IS_VALID(a_fFlags, a_fIgnore) \
|
---|
111 | ( ((a_fFlags) & ~((uint32_t)(a_fIgnore) | RTPATH_STR_F_STYLE_MASK | RTPATH_STR_F_MIDDLE)) == 0 \
|
---|
112 | && ((a_fFlags) & RTPATH_STR_F_STYLE_MASK) != RTPATH_STR_F_STYLE_RESERVED \
|
---|
113 | && ((a_fFlags) & RTPATH_STR_F_RESERVED_MASK) == 0 )
|
---|
114 |
|
---|
115 |
|
---|
116 | /** @def RTPATH_STYLE
|
---|
117 | * The host path style. This is set to RTPATH_STR_F_STYLE_DOS,
|
---|
118 | * RTPATH_STR_F_STYLE_UNIX, or other future styles. */
|
---|
119 | #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
|
---|
120 | # define RTPATH_STYLE RTPATH_STR_F_STYLE_DOS
|
---|
121 | #else
|
---|
122 | # define RTPATH_STYLE RTPATH_STR_F_STYLE_UNIX
|
---|
123 | #endif
|
---|
124 |
|
---|
125 |
|
---|
126 | /** @def RTPATH_SLASH
|
---|
127 | * The preferred slash character.
|
---|
128 | *
|
---|
129 | * @remark IPRT will always accept unix slashes. So, normally you would
|
---|
130 | * never have to use this define.
|
---|
131 | */
|
---|
132 | #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
|
---|
133 | # define RTPATH_SLASH '\\'
|
---|
134 | #elif RTPATH_STYLE == RTPATH_STR_F_STYLE_UNIX
|
---|
135 | # define RTPATH_SLASH '/'
|
---|
136 | #else
|
---|
137 | # error "Unsupported RTPATH_STYLE value."
|
---|
138 | #endif
|
---|
139 |
|
---|
140 | /** @deprecated Use '/'! */
|
---|
141 | #define RTPATH_DELIMITER RTPATH_SLASH
|
---|
142 |
|
---|
143 |
|
---|
144 | /** @def RTPATH_SLASH_STR
|
---|
145 | * The preferred slash character as a string, handy for concatenations
|
---|
146 | * with other strings.
|
---|
147 | *
|
---|
148 | * @remark IPRT will always accept unix slashes. So, normally you would
|
---|
149 | * never have to use this define.
|
---|
150 | */
|
---|
151 | #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
|
---|
152 | # define RTPATH_SLASH_STR "\\"
|
---|
153 | #elif RTPATH_STYLE == RTPATH_STR_F_STYLE_UNIX
|
---|
154 | # define RTPATH_SLASH_STR "/"
|
---|
155 | #else
|
---|
156 | # error "Unsupported RTPATH_STYLE value."
|
---|
157 | #endif
|
---|
158 |
|
---|
159 |
|
---|
160 | /** @def RTPATH_IS_SLASH
|
---|
161 | * Checks if a character is a slash.
|
---|
162 | *
|
---|
163 | * @returns true if it's a slash and false if not.
|
---|
164 | * @returns @param a_ch Char to check.
|
---|
165 | */
|
---|
166 | #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
|
---|
167 | # define RTPATH_IS_SLASH(a_ch) ( (a_ch) == '\\' || (a_ch) == '/' )
|
---|
168 | #elif RTPATH_STYLE == RTPATH_STR_F_STYLE_UNIX
|
---|
169 | # define RTPATH_IS_SLASH(a_ch) ( (a_ch) == '/' )
|
---|
170 | #else
|
---|
171 | # error "Unsupported RTPATH_STYLE value."
|
---|
172 | #endif
|
---|
173 |
|
---|
174 |
|
---|
175 | /** @def RTPATH_IS_VOLSEP
|
---|
176 | * Checks if a character marks the end of the volume specification.
|
---|
177 | *
|
---|
178 | * @remark This is sufficient for the drive letter concept on PC.
|
---|
179 | * However it might be insufficient on other platforms
|
---|
180 | * and even on PC a UNC volume spec won't be detected this way.
|
---|
181 | * Use the RTPath@<too be created@>() instead.
|
---|
182 | *
|
---|
183 | * @returns true if it is and false if it isn't.
|
---|
184 | * @returns @param a_ch Char to check.
|
---|
185 | */
|
---|
186 | #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
|
---|
187 | # define RTPATH_IS_VOLSEP(a_ch) ( (a_ch) == ':' )
|
---|
188 | #elif RTPATH_STYLE == RTPATH_STR_F_STYLE_UNIX
|
---|
189 | # define RTPATH_IS_VOLSEP(a_ch) (false)
|
---|
190 | #else
|
---|
191 | # error "Unsupported RTPATH_STYLE value."
|
---|
192 | #endif
|
---|
193 |
|
---|
194 |
|
---|
195 | /** @def RTPATH_IS_SEP
|
---|
196 | * Checks if a character is path component separator
|
---|
197 | *
|
---|
198 | * @returns true if it is and false if it isn't.
|
---|
199 | * @returns @param a_ch Char to check.
|
---|
200 | * @
|
---|
201 | */
|
---|
202 | #define RTPATH_IS_SEP(a_ch) ( RTPATH_IS_SLASH(a_ch) || RTPATH_IS_VOLSEP(a_ch) )
|
---|
203 |
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * Checks if the path exists.
|
---|
207 | *
|
---|
208 | * Symbolic links will all be attempted resolved and broken links means false.
|
---|
209 | *
|
---|
210 | * @returns true if it exists and false if it doesn't.
|
---|
211 | * @param pszPath The path to check.
|
---|
212 | */
|
---|
213 | RTDECL(bool) RTPathExists(const char *pszPath);
|
---|
214 |
|
---|
215 | /**
|
---|
216 | * Checks if the path exists.
|
---|
217 | *
|
---|
218 | * @returns true if it exists and false if it doesn't.
|
---|
219 | * @param pszPath The path to check.
|
---|
220 | * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
|
---|
221 | */
|
---|
222 | RTDECL(bool) RTPathExistsEx(const char *pszPath, uint32_t fFlags);
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Sets the current working directory of the process.
|
---|
226 | *
|
---|
227 | * @returns IPRT status code.
|
---|
228 | * @param pszPath The path to the new working directory.
|
---|
229 | */
|
---|
230 | RTDECL(int) RTPathSetCurrent(const char *pszPath);
|
---|
231 |
|
---|
232 | /**
|
---|
233 | * Gets the current working directory of the process.
|
---|
234 | *
|
---|
235 | * @returns IPRT status code.
|
---|
236 | * @param pszPath Where to store the path.
|
---|
237 | * @param cchPath The size of the buffer pszPath points to.
|
---|
238 | */
|
---|
239 | RTDECL(int) RTPathGetCurrent(char *pszPath, size_t cchPath);
|
---|
240 |
|
---|
241 | /**
|
---|
242 | * Gets the current working directory on the specified drive.
|
---|
243 | *
|
---|
244 | * On systems without drive letters, the root slash will be returned.
|
---|
245 | *
|
---|
246 | * @returns IPRT status code.
|
---|
247 | * @param chDrive The drive we're querying the driver letter on.
|
---|
248 | * @param pszPath Where to store the working directroy path.
|
---|
249 | * @param cbPath The size of the buffer pszPath points to.
|
---|
250 | */
|
---|
251 | RTDECL(int) RTPathGetCurrentOnDrive(char chDrive, char *pszPath, size_t cbPath);
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * Gets the current working drive of the process.
|
---|
255 | *
|
---|
256 | * Normally drive letter and colon will be returned, never trailing a root
|
---|
257 | * slash. If the current directory is on a UNC share, the root of the share
|
---|
258 | * will be returned. On systems without drive letters, an empty string is
|
---|
259 | * returned for consistency.
|
---|
260 | *
|
---|
261 | * @returns IPRT status code.
|
---|
262 | * @param pszPath Where to store the working drive or UNC root.
|
---|
263 | * @param cbPath The size of the buffer pszPath points to.
|
---|
264 | */
|
---|
265 | RTDECL(int) RTPathGetCurrentDrive(char *pszPath, size_t cbPath);
|
---|
266 |
|
---|
267 | /**
|
---|
268 | * Get the real path (no symlinks, no . or .. components), must exist.
|
---|
269 | *
|
---|
270 | * @returns iprt status code.
|
---|
271 | * @param pszPath The path to resolve.
|
---|
272 | * @param pszRealPath Where to store the real path.
|
---|
273 | * @param cchRealPath Size of the buffer.
|
---|
274 | */
|
---|
275 | RTDECL(int) RTPathReal(const char *pszPath, char *pszRealPath, size_t cchRealPath);
|
---|
276 |
|
---|
277 | /**
|
---|
278 | * Same as RTPathReal only the result is RTStrDup()'ed.
|
---|
279 | *
|
---|
280 | * @returns Pointer to real path. Use RTStrFree() to free this string.
|
---|
281 | * @returns NULL if RTPathReal() or RTStrDup() fails.
|
---|
282 | * @param pszPath The path to resolve.
|
---|
283 | */
|
---|
284 | RTDECL(char *) RTPathRealDup(const char *pszPath);
|
---|
285 |
|
---|
286 | /**
|
---|
287 | * Get the absolute path (starts from root, no . or .. components), doesn't have
|
---|
288 | * to exist. Note that this method is designed to never perform actual file
|
---|
289 | * system access, therefore symlinks are not resolved.
|
---|
290 | *
|
---|
291 | * @returns iprt status code.
|
---|
292 | * @param pszPath The path to resolve.
|
---|
293 | * @param pszAbsPath Where to store the absolute path.
|
---|
294 | * @param cchAbsPath Size of the buffer.
|
---|
295 | */
|
---|
296 | RTDECL(int) RTPathAbs(const char *pszPath, char *pszAbsPath, size_t cchAbsPath);
|
---|
297 |
|
---|
298 | /**
|
---|
299 | * Same as RTPathAbs only the result is RTStrDup()'ed.
|
---|
300 | *
|
---|
301 | * @returns Pointer to the absolute path. Use RTStrFree() to free this string.
|
---|
302 | * @returns NULL if RTPathAbs() or RTStrDup() fails.
|
---|
303 | * @param pszPath The path to resolve.
|
---|
304 | */
|
---|
305 | RTDECL(char *) RTPathAbsDup(const char *pszPath);
|
---|
306 |
|
---|
307 | /**
|
---|
308 | * Get the absolute path (no symlinks, no . or .. components), assuming the
|
---|
309 | * given base path as the current directory. The resulting path doesn't have
|
---|
310 | * to exist.
|
---|
311 | *
|
---|
312 | * @returns iprt status code.
|
---|
313 | * @param pszBase The base path to act like a current directory.
|
---|
314 | * When NULL, the actual cwd is used (i.e. the call
|
---|
315 | * is equivalent to RTPathAbs(pszPath, ...).
|
---|
316 | * @param pszPath The path to resolve.
|
---|
317 | * @param pszAbsPath Where to store the absolute path.
|
---|
318 | * @param cchAbsPath Size of the buffer.
|
---|
319 | */
|
---|
320 | RTDECL(int) RTPathAbsEx(const char *pszBase, const char *pszPath, char *pszAbsPath, size_t cchAbsPath);
|
---|
321 |
|
---|
322 | /**
|
---|
323 | * Same as RTPathAbsEx only the result is RTStrDup()'ed.
|
---|
324 | *
|
---|
325 | * @returns Pointer to the absolute path. Use RTStrFree() to free this string.
|
---|
326 | * @returns NULL if RTPathAbsEx() or RTStrDup() fails.
|
---|
327 | * @param pszBase The base path to act like a current directory.
|
---|
328 | * When NULL, the actual cwd is used (i.e. the call
|
---|
329 | * is equivalent to RTPathAbs(pszPath, ...).
|
---|
330 | * @param pszPath The path to resolve.
|
---|
331 | */
|
---|
332 | RTDECL(char *) RTPathAbsExDup(const char *pszBase, const char *pszPath);
|
---|
333 |
|
---|
334 | /**
|
---|
335 | * Strips the filename from a path. Truncates the given string in-place by overwriting the
|
---|
336 | * last path separator character with a null byte in a platform-neutral way.
|
---|
337 | *
|
---|
338 | * @param pszPath Path from which filename should be extracted, will be truncated.
|
---|
339 | * If the string contains no path separator, it will be changed to a "." string.
|
---|
340 | */
|
---|
341 | RTDECL(void) RTPathStripFilename(char *pszPath);
|
---|
342 |
|
---|
343 | /**
|
---|
344 | * Strips the last suffix from a path.
|
---|
345 | *
|
---|
346 | * @param pszPath Path which suffix should be stripped.
|
---|
347 | */
|
---|
348 | RTDECL(void) RTPathStripSuffix(char *pszPath);
|
---|
349 |
|
---|
350 | /**
|
---|
351 | * Strips the trailing slashes of a path name.
|
---|
352 | *
|
---|
353 | * Won't strip root slashes.
|
---|
354 | *
|
---|
355 | * @returns The new length of pszPath.
|
---|
356 | * @param pszPath Path to strip.
|
---|
357 | */
|
---|
358 | RTDECL(size_t) RTPathStripTrailingSlash(char *pszPath);
|
---|
359 |
|
---|
360 | /**
|
---|
361 | * Skips the root specification, if present.
|
---|
362 | *
|
---|
363 | * @return Pointer to the first char after the root specification. This can be
|
---|
364 | * pointing to the terminator, if the path is only a root
|
---|
365 | * specification.
|
---|
366 | * @param pszPath The path to skip ahead in.
|
---|
367 | */
|
---|
368 | RTDECL(char *) RTPathSkipRootSpec(const char *pszPath);
|
---|
369 |
|
---|
370 | /**
|
---|
371 | * Ensures that the path has a trailing path separator such that file names can
|
---|
372 | * be appended without further work.
|
---|
373 | *
|
---|
374 | * This can be helpful when preparing for efficiently combining a directory path
|
---|
375 | * with the filenames returned by RTDirRead. The return value gives you the
|
---|
376 | * position at which you copy the RTDIRENTRY::szName to construct a valid path
|
---|
377 | * to it.
|
---|
378 | *
|
---|
379 | * @returns The length of the path, 0 on buffer overflow.
|
---|
380 | * @param pszPath The path.
|
---|
381 | * @param cbPath The length of the path buffer @a pszPath points to.
|
---|
382 | */
|
---|
383 | RTDECL(size_t) RTPathEnsureTrailingSeparator(char *pszPath, size_t cbPath);
|
---|
384 |
|
---|
385 | /**
|
---|
386 | * Changes all the slashes in the specified path to DOS style.
|
---|
387 | *
|
---|
388 | * Unless @a fForce is set, nothing will be done when on a UNIX flavored system
|
---|
389 | * since paths wont work with DOS style slashes there.
|
---|
390 | *
|
---|
391 | * @returns @a pszPath.
|
---|
392 | * @param pszPath The path to modify.
|
---|
393 | * @param fForce Whether to force the conversion on non-DOS OSes.
|
---|
394 | */
|
---|
395 | RTDECL(char *) RTPathChangeToDosSlashes(char *pszPath, bool fForce);
|
---|
396 |
|
---|
397 | /**
|
---|
398 | * Changes all the slashes in the specified path to unix style.
|
---|
399 | *
|
---|
400 | * Unless @a fForce is set, nothing will be done when on a UNIX flavored system
|
---|
401 | * since paths wont work with DOS style slashes there.
|
---|
402 | *
|
---|
403 | * @returns @a pszPath.
|
---|
404 | * @param pszPath The path to modify.
|
---|
405 | * @param fForce Whether to force the conversion on non-DOS OSes.
|
---|
406 | */
|
---|
407 | RTDECL(char *) RTPathChangeToUnixSlashes(char *pszPath, bool fForce);
|
---|
408 |
|
---|
409 | /**
|
---|
410 | * Simple parsing of the a path.
|
---|
411 | *
|
---|
412 | * It figures the length of the directory component, the offset of
|
---|
413 | * the file name and the location of the suffix dot.
|
---|
414 | *
|
---|
415 | * @returns The path length.
|
---|
416 | *
|
---|
417 | * @param pszPath Path to find filename in.
|
---|
418 | * @param pcchDir Where to put the length of the directory component. If
|
---|
419 | * no directory, this will be 0. Optional.
|
---|
420 | * @param poffName Where to store the filename offset.
|
---|
421 | * If empty string or if it's ending with a slash this
|
---|
422 | * will be set to -1. Optional.
|
---|
423 | * @param poffSuff Where to store the suffix offset (the last dot).
|
---|
424 | * If empty string or if it's ending with a slash this
|
---|
425 | * will be set to -1. Optional.
|
---|
426 | */
|
---|
427 | RTDECL(size_t) RTPathParseSimple(const char *pszPath, size_t *pcchDir, ssize_t *poffName, ssize_t *poffSuff);
|
---|
428 |
|
---|
429 | /**
|
---|
430 | * Finds the filename in a path.
|
---|
431 | *
|
---|
432 | * @returns Pointer to filename within pszPath.
|
---|
433 | * @returns NULL if no filename (i.e. empty string or ends with a slash).
|
---|
434 | * @param pszPath Path to find filename in.
|
---|
435 | */
|
---|
436 | RTDECL(char *) RTPathFilename(const char *pszPath);
|
---|
437 |
|
---|
438 | /**
|
---|
439 | * Finds the filename in a path, extended version.
|
---|
440 | *
|
---|
441 | * @returns Pointer to filename within pszPath.
|
---|
442 | * @returns NULL if no filename (i.e. empty string or ends with a slash).
|
---|
443 | * @param pszPath Path to find filename in.
|
---|
444 | * @param fFlags RTPATH_STR_F_STYLE_XXX. Other RTPATH_STR_F_XXX flags
|
---|
445 | * will be ignored.
|
---|
446 | */
|
---|
447 | RTDECL(char *) RTPathFilenameEx(const char *pszPath, uint32_t fFlags);
|
---|
448 |
|
---|
449 | /**
|
---|
450 | * Finds the suffix part of in a path (last dot and onwards).
|
---|
451 | *
|
---|
452 | * @returns Pointer to suffix within pszPath.
|
---|
453 | * @returns NULL if no suffix
|
---|
454 | * @param pszPath Path to find suffix in.
|
---|
455 | *
|
---|
456 | * @remarks IPRT terminology: A suffix includes the dot, the extension starts
|
---|
457 | * after the dot. For instance suffix '.txt' and extension 'txt'.
|
---|
458 | */
|
---|
459 | RTDECL(char *) RTPathSuffix(const char *pszPath);
|
---|
460 |
|
---|
461 | /**
|
---|
462 | * Checks if a path has an extension / suffix.
|
---|
463 | *
|
---|
464 | * @returns true if extension / suffix present.
|
---|
465 | * @returns false if no extension / suffix.
|
---|
466 | * @param pszPath Path to check.
|
---|
467 | */
|
---|
468 | RTDECL(bool) RTPathHasSuffix(const char *pszPath);
|
---|
469 | /** Same thing, different name. */
|
---|
470 | #define RTPathHasExt RTPathHasSuffix
|
---|
471 |
|
---|
472 | /**
|
---|
473 | * Checks if a path includes more than a filename.
|
---|
474 | *
|
---|
475 | * @returns true if path present.
|
---|
476 | * @returns false if no path.
|
---|
477 | * @param pszPath Path to check.
|
---|
478 | */
|
---|
479 | RTDECL(bool) RTPathHasPath(const char *pszPath);
|
---|
480 | /** Misspelled, don't use. */
|
---|
481 | #define RTPathHavePath RTPathHasPath
|
---|
482 |
|
---|
483 | /**
|
---|
484 | * Checks if the path starts with a root specifier or not.
|
---|
485 | *
|
---|
486 | * @returns @c true if it starts with root, @c false if not.
|
---|
487 | *
|
---|
488 | * @param pszPath Path to check.
|
---|
489 | */
|
---|
490 | RTDECL(bool) RTPathStartsWithRoot(const char *pszPath);
|
---|
491 |
|
---|
492 |
|
---|
493 |
|
---|
494 | /**
|
---|
495 | * Counts the components in the specified path.
|
---|
496 | *
|
---|
497 | * An empty string has zero components. A lone root slash is considered have
|
---|
498 | * one. The paths "/init" and "/bin/" are considered having two components. An
|
---|
499 | * UNC share specifier like "\\myserver\share" will be considered as one single
|
---|
500 | * component.
|
---|
501 | *
|
---|
502 | * @returns The number of path components.
|
---|
503 | * @param pszPath The path to parse.
|
---|
504 | */
|
---|
505 | RTDECL(size_t) RTPathCountComponents(const char *pszPath);
|
---|
506 |
|
---|
507 | /**
|
---|
508 | * Copies the specified number of path components from @a pszSrc and into @a
|
---|
509 | * pszDst.
|
---|
510 | *
|
---|
511 | * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW. In the latter case the buffer
|
---|
512 | * is not touched.
|
---|
513 | *
|
---|
514 | * @param pszDst The destination buffer.
|
---|
515 | * @param cbDst The size of the destination buffer.
|
---|
516 | * @param pszSrc The source path.
|
---|
517 | * @param cComponents The number of components to copy from @a pszSrc.
|
---|
518 | */
|
---|
519 | RTDECL(int) RTPathCopyComponents(char *pszDst, size_t cbDst, const char *pszSrc, size_t cComponents);
|
---|
520 |
|
---|
521 | /** @name Path properties returned by RTPathParse and RTPathSplit.
|
---|
522 | * @{ */
|
---|
523 |
|
---|
524 | /** Indicates that there is a filename.
|
---|
525 | * If not set, either a lone root spec was given (RTPATH_PROP_UNC,
|
---|
526 | * RTPATH_PROP_ROOT_SLASH, or RTPATH_PROP_VOLUME) or the final component had a
|
---|
527 | * trailing slash (RTPATH_PROP_DIR_SLASH). */
|
---|
528 | #define RTPATH_PROP_FILENAME UINT16_C(0x0001)
|
---|
529 | /** Indicates that a directory was specified using a trailing slash.
|
---|
530 | * @note This is not set for lone root specifications (RTPATH_PROP_UNC,
|
---|
531 | * RTPATH_PROP_ROOT_SLASH, or RTPATH_PROP_VOLUME).
|
---|
532 | * @note The slash is not counted into the last component. However, it is
|
---|
533 | * counted into cchPath. */
|
---|
534 | #define RTPATH_PROP_DIR_SLASH UINT16_C(0x0002)
|
---|
535 |
|
---|
536 | /** The filename has a suffix (extension). */
|
---|
537 | #define RTPATH_PROP_SUFFIX UINT16_C(0x0004)
|
---|
538 | /** Indicates that this is an UNC path (Windows and OS/2 only).
|
---|
539 | *
|
---|
540 | * UNC = Universal Naming Convention. It is on the form '//Computer/',
|
---|
541 | * '//Namespace/', '//ComputerName/Resource' and '//Namespace/Resource'.
|
---|
542 | * RTPathParse, RTPathSplit and friends does not consider the 'Resource' as
|
---|
543 | * part of the UNC root specifier. Thus the root specs for the above examples
|
---|
544 | * would be '//ComputerName/' or '//Namespace/'.
|
---|
545 | *
|
---|
546 | * Please note that '//something' is not a UNC path, there must be a slash
|
---|
547 | * following the computer or namespace.
|
---|
548 | */
|
---|
549 | #define RTPATH_PROP_UNC UINT16_C(0x0010)
|
---|
550 | /** A root slash was specified (unix style root).
|
---|
551 | * (While the path must relative if not set, this being set doesn't make it
|
---|
552 | * absolute.)
|
---|
553 | *
|
---|
554 | * This will be set in the following examples: '/', '/bin', 'C:/', 'C:/Windows',
|
---|
555 | * '//./', '//./PhysicalDisk0', '//example.org/', and '//example.org/share'.
|
---|
556 | *
|
---|
557 | * It will not be set for the following examples: '.', 'bin/ls', 'C:', and
|
---|
558 | * 'C:Windows'.
|
---|
559 | */
|
---|
560 | #define RTPATH_PROP_ROOT_SLASH UINT16_C(0x0020)
|
---|
561 | /** A volume is specified (Windows, DOS and OS/2).
|
---|
562 | * For examples: 'C:', 'C:/', and 'A:/AutoExec.bat'. */
|
---|
563 | #define RTPATH_PROP_VOLUME UINT16_C(0x0040)
|
---|
564 | /** The path is absolute, i.e. has a root specifier (root-slash,
|
---|
565 | * volume or UNC) and contains no winding '..' bits, though it may contain
|
---|
566 | * unnecessary slashes (RTPATH_PROP_EXTRA_SLASHES) and '.' components
|
---|
567 | * (RTPATH_PROP_DOT_REFS).
|
---|
568 | *
|
---|
569 | * On systems without volumes and UNC (unix style) it will be set for '/',
|
---|
570 | * '/bin/ls', and '/bin//./ls', but not for 'bin/ls', /bin/../usr/bin/env',
|
---|
571 | * '/./bin/ls' or '/.'.
|
---|
572 | *
|
---|
573 | * On systems with volumes, it will be set for 'C:/', C:/Windows', and
|
---|
574 | * 'C:/./Windows//', but not for 'C:', 'C:Windows', or 'C:/Windows/../boot.ini'.
|
---|
575 | *
|
---|
576 | * On systems with UNC paths, it will be set for '//localhost/',
|
---|
577 | * '//localhost/C$', '//localhost/C$/Windows/System32', '//localhost/.', and
|
---|
578 | * '//localhost/C$//./AutoExec.bat', but not for
|
---|
579 | * '//localhost/C$/Windows/../AutoExec.bat'.
|
---|
580 | *
|
---|
581 | * @note For the RTPathAbs definition, this flag needs to be set while both
|
---|
582 | * RTPATH_PROP_EXTRA_SLASHES and RTPATH_PROP_DOT_REFS must be cleared.
|
---|
583 | */
|
---|
584 | #define RTPATH_PROP_ABSOLUTE UINT16_C(0x0100)
|
---|
585 | /** Relative path. Inverse of RTPATH_PROP_ABSOLUTE. */
|
---|
586 | #define RTPATH_PROP_RELATIVE UINT16_C(0x0200)
|
---|
587 | /** The path contains unnecessary slashes. Meaning, that if */
|
---|
588 | #define RTPATH_PROP_EXTRA_SLASHES UINT16_C(0x0400)
|
---|
589 | /** The path contains references to the special '.' (dot) directory link. */
|
---|
590 | #define RTPATH_PROP_DOT_REFS UINT16_C(0x0800)
|
---|
591 | /** The path contains references to the special '..' (dot) directory link.
|
---|
592 | * RTPATH_PROP_RELATIVE will always be set together with this. */
|
---|
593 | #define RTPATH_PROP_DOTDOT_REFS UINT16_C(0x1000)
|
---|
594 |
|
---|
595 |
|
---|
596 | /** Macro to determin whether to insert a slash after the first component when
|
---|
597 | * joining it with something else.
|
---|
598 | * (All other components in a split or parsed path requies slashes added.) */
|
---|
599 | #define RTPATH_PROP_FIRST_NEEDS_NO_SLASH(a_fProps) \
|
---|
600 | RT_BOOL( (a_fProps) & (RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_VOLUME | RTPATH_PROP_UNC) )
|
---|
601 |
|
---|
602 | /** Macro to determin whether there is a root specification of any kind
|
---|
603 | * (unix, volumes, unc). */
|
---|
604 | #define RTPATH_PROP_HAS_ROOT_SPEC(a_fProps) \
|
---|
605 | RT_BOOL( (a_fProps) & (RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_VOLUME | RTPATH_PROP_UNC) )
|
---|
606 |
|
---|
607 | /** @} */
|
---|
608 |
|
---|
609 |
|
---|
610 | /**
|
---|
611 | * Parsed path.
|
---|
612 | *
|
---|
613 | * The first component is the root, volume or UNC specifier, if present. Use
|
---|
614 | * RTPATH_PROP_HAS_ROOT_SPEC() on RTPATHPARSED::fProps to determine its
|
---|
615 | * presence.
|
---|
616 | *
|
---|
617 | * Other than the root component, no component will include directory separators
|
---|
618 | * (slashes).
|
---|
619 | */
|
---|
620 | typedef struct RTPATHPARSED
|
---|
621 | {
|
---|
622 | /** Number of path components.
|
---|
623 | * This will always be set on VERR_BUFFER_OVERFLOW returns from RTPathParsed
|
---|
624 | * so the caller can calculate the required buffer size. */
|
---|
625 | uint16_t cComps;
|
---|
626 | /** Path property flags, RTPATH_PROP_XXX */
|
---|
627 | uint16_t fProps;
|
---|
628 | /** On success this is the length of the described path, i.e. sum of all
|
---|
629 | * component lengths and necessary separators.
|
---|
630 | * Do NOT use this to index in the source path in case it contains
|
---|
631 | * unnecessary slashes that RTPathParsed has ignored here. */
|
---|
632 | uint16_t cchPath;
|
---|
633 | /** Reserved for future use. */
|
---|
634 | uint16_t u16Reserved;
|
---|
635 | /** The offset of the filename suffix, offset of the NUL char if none. */
|
---|
636 | uint16_t offSuffix;
|
---|
637 | /** The lenght of the suffix. */
|
---|
638 | uint16_t cchSuffix;
|
---|
639 | /** Array of component descriptors (variable size).
|
---|
640 | * @note Don't try figure the end of the input path by adding up off and cch
|
---|
641 | * of the last component. If RTPATH_PROP_DIR_SLASH is set, there may
|
---|
642 | * be one or more trailing slashes that are unaccounted for! */
|
---|
643 | struct
|
---|
644 | {
|
---|
645 | /** The offset of the component. */
|
---|
646 | uint16_t off;
|
---|
647 | /** The length of the component. */
|
---|
648 | uint16_t cch;
|
---|
649 | } aComps[1];
|
---|
650 | } RTPATHPARSED;
|
---|
651 | /** Pointer to to a parsed path result. */
|
---|
652 | typedef RTPATHPARSED *PRTPATHPARSED;
|
---|
653 | /** Pointer to to a const parsed path result. */
|
---|
654 | typedef RTPATHPARSED *PCRTPATHPARSED;
|
---|
655 |
|
---|
656 |
|
---|
657 | /**
|
---|
658 | * Parses the path.
|
---|
659 | *
|
---|
660 | * @returns IPRT status code.
|
---|
661 | * @retval VERR_INVALID_POINTER if pParsed or pszPath is an invalid pointer.
|
---|
662 | * @retval VERR_INVALID_PARAMETER if cbOutput is less than the RTPATHPARSED
|
---|
663 | * strucuture. No output. (asserted)
|
---|
664 | * @retval VERR_BUFFER_OVERFLOW there are more components in the path than
|
---|
665 | * there is space in aComps. The required amount of space can be
|
---|
666 | * determined from the pParsed->cComps:
|
---|
667 | * @code
|
---|
668 | * RT_OFFSETOF(RTPATHPARSED, aComps[pParsed->cComps])
|
---|
669 | * @endcode
|
---|
670 | * @retval VERR_PATH_ZERO_LENGTH if the path is empty.
|
---|
671 | *
|
---|
672 | * @param pszPath The path to parse.
|
---|
673 | * @param pParsed Where to store the details of the parsed path.
|
---|
674 | * @param cbParsed The size of the buffer. Must be at least the
|
---|
675 | * size of RTPATHPARSED.
|
---|
676 | * @param fFlags Combination of RTPATH_STR_F_XXX flags.
|
---|
677 | * Most users will pass 0.
|
---|
678 | * @sa RTPathSplit, RTPathSplitA.
|
---|
679 | */
|
---|
680 | RTDECL(int) RTPathParse(const char *pszPath, PRTPATHPARSED pParsed, size_t cbParsed, uint32_t fFlags);
|
---|
681 |
|
---|
682 | /**
|
---|
683 | * Reassembles a path parsed by RTPathParse.
|
---|
684 | *
|
---|
685 | * This will be more useful as more APIs manipulating the RTPATHPARSED output
|
---|
686 | * are added.
|
---|
687 | *
|
---|
688 | * @returns IPRT status code.
|
---|
689 | * @retval VERR_BUFFER_OVERFLOW if @a cbDstPath is less than or equal to
|
---|
690 | * RTPATHPARSED::cchPath.
|
---|
691 | *
|
---|
692 | * @param pszSrcPath The source path.
|
---|
693 | * @param pParsed The parser output for @a pszSrcPath.
|
---|
694 | * @param fFlags Combination of RTPATH_STR_F_STYLE_XXX.
|
---|
695 | * Most users will pass 0.
|
---|
696 | * @param pszDstPath Pointer to the buffer where the path is to be
|
---|
697 | * reassembled.
|
---|
698 | * @param cbDstPath The size of the output buffer.
|
---|
699 | */
|
---|
700 | RTDECL(int) RTPathParsedReassemble(const char *pszSrcPath, PRTPATHPARSED pParsed, uint32_t fFlags,
|
---|
701 | char *pszDstPath, size_t cbDstPath);
|
---|
702 |
|
---|
703 |
|
---|
704 | /**
|
---|
705 | * Output buffer for RTPathSplit and RTPathSplitA.
|
---|
706 | */
|
---|
707 | typedef struct RTPATHSPLIT
|
---|
708 | {
|
---|
709 | /** Number of path components.
|
---|
710 | * This will always be set on VERR_BUFFER_OVERFLOW returns from RTPathParsed
|
---|
711 | * so the caller can calculate the required buffer size. */
|
---|
712 | uint16_t cComps;
|
---|
713 | /** Path property flags, RTPATH_PROP_XXX */
|
---|
714 | uint16_t fProps;
|
---|
715 | /** On success this is the length of the described path, i.e. sum of all
|
---|
716 | * component lengths and necessary separators.
|
---|
717 | * Do NOT use this to index in the source path in case it contains
|
---|
718 | * unnecessary slashes that RTPathSplit has ignored here. */
|
---|
719 | uint16_t cchPath;
|
---|
720 | /** Reserved (internal use). */
|
---|
721 | uint16_t u16Reserved;
|
---|
722 | /** The amount of memory used (on success) or required (on
|
---|
723 | * VERR_BUFFER_OVERFLOW) of this structure and it's strings. */
|
---|
724 | uint32_t cbNeeded;
|
---|
725 | /** Pointer to the filename suffix (the dot), if any. Points to the NUL
|
---|
726 | * character of the last component if none or if RTPATH_PROP_DIR_SLASH is
|
---|
727 | * present. */
|
---|
728 | const char *pszSuffix;
|
---|
729 | /** Array of component strings (variable size). */
|
---|
730 | char *apszComps[1];
|
---|
731 | } RTPATHSPLIT;
|
---|
732 | /** Pointer to a split path buffer. */
|
---|
733 | typedef RTPATHSPLIT *PRTPATHSPLIT;
|
---|
734 | /** Pointer to a const split path buffer. */
|
---|
735 | typedef RTPATHSPLIT const *PCRTPATHSPLIT;
|
---|
736 |
|
---|
737 | /**
|
---|
738 | * Splits the path into individual component strings, carved from user supplied
|
---|
739 | * the given buffer block.
|
---|
740 | *
|
---|
741 | * @returns IPRT status code.
|
---|
742 | * @retval VERR_INVALID_POINTER if pParsed or pszPath is an invalid pointer.
|
---|
743 | * @retval VERR_INVALID_PARAMETER if cbOutput is less than the RTPATHSPLIT
|
---|
744 | * strucuture. No output. (asserted)
|
---|
745 | * @retval VERR_BUFFER_OVERFLOW there are more components in the path than
|
---|
746 | * there is space in aComps. The required amount of space can be
|
---|
747 | * determined from the pParsed->cComps:
|
---|
748 | * @code
|
---|
749 | * RT_OFFSETOF(RTPATHPARSED, aComps[pParsed->cComps])
|
---|
750 | * @endcode
|
---|
751 | * @retval VERR_PATH_ZERO_LENGTH if the path is empty.
|
---|
752 | * @retval VERR_FILENAME_TOO_LONG if the filename is too long (close to 64 KB).
|
---|
753 | *
|
---|
754 | * @param pszPath The path to parse.
|
---|
755 | * @param pSplit Where to store the details of the parsed path.
|
---|
756 | * @param cbSplit The size of the buffer pointed to by @a pSplit
|
---|
757 | * (variable sized array at the end). Must be at
|
---|
758 | * least the size of RTPATHSPLIT.
|
---|
759 | * @param fFlags Combination of RTPATH_STR_F_XXX flags.
|
---|
760 | * Most users will pass 0.
|
---|
761 | *
|
---|
762 | * @sa RTPathSplitA, RTPathParse.
|
---|
763 | */
|
---|
764 | RTDECL(int) RTPathSplit(const char *pszPath, PRTPATHSPLIT pSplit, size_t cbSplit, uint32_t fFlags);
|
---|
765 |
|
---|
766 | /**
|
---|
767 | * Splits the path into individual component strings, allocating the buffer on
|
---|
768 | * the default thread heap.
|
---|
769 | *
|
---|
770 | * @returns IPRT status code.
|
---|
771 | * @retval VERR_INVALID_POINTER if pParsed or pszPath is an invalid pointer.
|
---|
772 | * @retval VERR_PATH_ZERO_LENGTH if the path is empty.
|
---|
773 | *
|
---|
774 | * @param pszPath The path to parse.
|
---|
775 | * @param ppSplit Where to return the pointer to the output on
|
---|
776 | * success. This must be freed by calling
|
---|
777 | * RTPathSplitFree().
|
---|
778 | * @param fFlags Combination of RTPATH_STR_F_XXX flags.
|
---|
779 | * Most users will pass 0.
|
---|
780 | * @sa RTPathSplitFree, RTPathSplit, RTPathParse.
|
---|
781 | */
|
---|
782 | #define RTPathSplitA(pszPath, ppSplit, fFlags) RTPathSplitATag(pszPath, ppSplit, fFlags, RTPATH_TAG)
|
---|
783 |
|
---|
784 | /**
|
---|
785 | * Splits the path into individual component strings, allocating the buffer on
|
---|
786 | * the default thread heap.
|
---|
787 | *
|
---|
788 | * @returns IPRT status code.
|
---|
789 | * @retval VERR_INVALID_POINTER if pParsed or pszPath is an invalid pointer.
|
---|
790 | * @retval VERR_PATH_ZERO_LENGTH if the path is empty.
|
---|
791 | *
|
---|
792 | * @param pszPath The path to parse.
|
---|
793 | * @param ppSplit Where to return the pointer to the output on
|
---|
794 | * success. This must be freed by calling
|
---|
795 | * RTPathSplitFree().
|
---|
796 | * @param fFlags Combination of RTPATH_STR_F_XXX flags.
|
---|
797 | * Most users will pass 0.
|
---|
798 | * @param pszTag Allocation tag used for statistics and such.
|
---|
799 | * @sa RTPathSplitFree, RTPathSplit, RTPathParse.
|
---|
800 | */
|
---|
801 | RTDECL(int) RTPathSplitATag(const char *pszPath, PRTPATHSPLIT *ppSplit, uint32_t fFlags, const char *pszTag);
|
---|
802 |
|
---|
803 | /**
|
---|
804 | * Frees buffer returned by RTPathSplitA.
|
---|
805 | *
|
---|
806 | * @param pSplit What RTPathSplitA returned.
|
---|
807 | * @sa RTPathSplitA
|
---|
808 | */
|
---|
809 | RTDECL(void) RTPathSplitFree(PRTPATHSPLIT pSplit);
|
---|
810 |
|
---|
811 | /**
|
---|
812 | * Reassembles a path parsed by RTPathSplit.
|
---|
813 | *
|
---|
814 | * This will be more useful as more APIs manipulating the RTPATHSPLIT output are
|
---|
815 | * added.
|
---|
816 | *
|
---|
817 | * @returns IPRT status code.
|
---|
818 | * @retval VERR_BUFFER_OVERFLOW if @a cbDstPath is less than or equal to
|
---|
819 | * RTPATHSPLIT::cchPath.
|
---|
820 | *
|
---|
821 | * @param pSplit A split path (see RTPathSplit, RTPathSplitA).
|
---|
822 | * @param fFlags Combination of RTPATH_STR_F_STYLE_XXX.
|
---|
823 | * Most users will pass 0.
|
---|
824 | * @param pszDstPath Pointer to the buffer where the path is to be
|
---|
825 | * reassembled.
|
---|
826 | * @param cbDstPath The size of the output buffer.
|
---|
827 | */
|
---|
828 | RTDECL(int) RTPathSplitReassemble(PRTPATHSPLIT pSplit, uint32_t fFlags, char *pszDstPath, size_t cbDstPath);
|
---|
829 |
|
---|
830 | /**
|
---|
831 | * Checks if the two paths leads to the file system object.
|
---|
832 | *
|
---|
833 | * If the objects exist, we'll query attributes for them. If that's not
|
---|
834 | * conclusive (some OSes) or one of them doesn't exist, we'll use a combination
|
---|
835 | * of RTPathAbs and RTPathCompare to determine the result.
|
---|
836 | *
|
---|
837 | * @returns true, false, or VERR_FILENAME_TOO_LONG.
|
---|
838 | * @param pszPath1 The first path.
|
---|
839 | * @param pszPath2 The seoncd path.
|
---|
840 | */
|
---|
841 | RTDECL(int) RTPathIsSame(const char *pszPath1, const char *pszPath2);
|
---|
842 |
|
---|
843 |
|
---|
844 | /**
|
---|
845 | * Compares two paths.
|
---|
846 | *
|
---|
847 | * The comparison takes platform-dependent details into account,
|
---|
848 | * such as:
|
---|
849 | * <ul>
|
---|
850 | * <li>On DOS-like platforms, both separator chars (|\| and |/|) are considered
|
---|
851 | * to be equal.
|
---|
852 | * <li>On platforms with case-insensitive file systems, mismatching characters
|
---|
853 | * are uppercased and compared again.
|
---|
854 | * </ul>
|
---|
855 | *
|
---|
856 | * @returns @< 0 if the first path less than the second path.
|
---|
857 | * @returns 0 if the first path identical to the second path.
|
---|
858 | * @returns @> 0 if the first path greater than the second path.
|
---|
859 | *
|
---|
860 | * @param pszPath1 Path to compare (must be an absolute path).
|
---|
861 | * @param pszPath2 Path to compare (must be an absolute path).
|
---|
862 | *
|
---|
863 | * @remarks File system details are currently ignored. This means that you won't
|
---|
864 | * get case-insensitive compares on unix systems when a path goes into a
|
---|
865 | * case-insensitive filesystem like FAT, HPFS, HFS, NTFS, JFS, or
|
---|
866 | * similar. For NT, OS/2 and similar you'll won't get case-sensitive
|
---|
867 | * compares on a case-sensitive file system.
|
---|
868 | */
|
---|
869 | RTDECL(int) RTPathCompare(const char *pszPath1, const char *pszPath2);
|
---|
870 |
|
---|
871 | /**
|
---|
872 | * Checks if a path starts with the given parent path.
|
---|
873 | *
|
---|
874 | * This means that either the path and the parent path matches completely, or
|
---|
875 | * that the path is to some file or directory residing in the tree given by the
|
---|
876 | * parent directory.
|
---|
877 | *
|
---|
878 | * The path comparison takes platform-dependent details into account,
|
---|
879 | * see RTPathCompare() for details.
|
---|
880 | *
|
---|
881 | * @returns |true| when \a pszPath starts with \a pszParentPath (or when they
|
---|
882 | * are identical), or |false| otherwise.
|
---|
883 | *
|
---|
884 | * @param pszPath Path to check, must be an absolute path.
|
---|
885 | * @param pszParentPath Parent path, must be an absolute path.
|
---|
886 | * No trailing directory slash!
|
---|
887 | *
|
---|
888 | * @remarks This API doesn't currently handle root directory compares in a
|
---|
889 | * manner consistent with the other APIs. RTPathStartsWith(pszSomePath,
|
---|
890 | * "/") will not work if pszSomePath isn't "/".
|
---|
891 | */
|
---|
892 | RTDECL(bool) RTPathStartsWith(const char *pszPath, const char *pszParentPath);
|
---|
893 |
|
---|
894 | /**
|
---|
895 | * Appends one partial path to another.
|
---|
896 | *
|
---|
897 | * The main purpose of this function is to deal correctly with the slashes when
|
---|
898 | * concatenating the two partial paths.
|
---|
899 | *
|
---|
900 | * @retval VINF_SUCCESS on success.
|
---|
901 | * @retval VERR_BUFFER_OVERFLOW if the result is too big to fit within
|
---|
902 | * cbPathDst bytes. No changes has been made.
|
---|
903 | * @retval VERR_INVALID_PARAMETER if the string pointed to by pszPath is longer
|
---|
904 | * than cbPathDst-1 bytes (failed to find terminator). Asserted.
|
---|
905 | *
|
---|
906 | * @param pszPath The path to append pszAppend to. This serves as both
|
---|
907 | * input and output. This can be empty, in which case
|
---|
908 | * pszAppend is just copied over.
|
---|
909 | * @param cbPathDst The size of the buffer pszPath points to, terminator
|
---|
910 | * included. This should NOT be strlen(pszPath).
|
---|
911 | * @param pszAppend The partial path to append to pszPath. This can be
|
---|
912 | * NULL, in which case nothing is done.
|
---|
913 | *
|
---|
914 | * @remarks See the RTPathAppendEx remarks.
|
---|
915 | */
|
---|
916 | RTDECL(int) RTPathAppend(char *pszPath, size_t cbPathDst, const char *pszAppend);
|
---|
917 |
|
---|
918 | /**
|
---|
919 | * Appends one partial path to another.
|
---|
920 | *
|
---|
921 | * The main purpose of this function is to deal correctly with the slashes when
|
---|
922 | * concatenating the two partial paths.
|
---|
923 | *
|
---|
924 | * @retval VINF_SUCCESS on success.
|
---|
925 | * @retval VERR_BUFFER_OVERFLOW if the result is too big to fit within
|
---|
926 | * cbPathDst bytes. No changes has been made.
|
---|
927 | * @retval VERR_INVALID_PARAMETER if the string pointed to by pszPath is longer
|
---|
928 | * than cbPathDst-1 bytes (failed to find terminator). Asserted.
|
---|
929 | *
|
---|
930 | * @param pszPath The path to append pszAppend to. This serves as both
|
---|
931 | * input and output. This can be empty, in which case
|
---|
932 | * pszAppend is just copied over.
|
---|
933 | * @param cbPathDst The size of the buffer pszPath points to, terminator
|
---|
934 | * included. This should NOT be strlen(pszPath).
|
---|
935 | * @param pszAppend The partial path to append to pszPath. This can be
|
---|
936 | * NULL, in which case nothing is done.
|
---|
937 | * @param cchAppendMax The maximum number or characters to take from @a
|
---|
938 | * pszAppend. RTSTR_MAX is fine.
|
---|
939 | *
|
---|
940 | * @remarks On OS/2, Window and similar systems, concatenating a drive letter
|
---|
941 | * specifier with a slash prefixed path will result in an absolute
|
---|
942 | * path. Meaning, RTPathAppend(strcpy(szBuf, "C:"), sizeof(szBuf),
|
---|
943 | * "/bar") will result in "C:/bar". (This follows directly from the
|
---|
944 | * behavior when pszPath is empty.)
|
---|
945 | *
|
---|
946 | * On the other hand, when joining a drive letter specifier with a
|
---|
947 | * partial path that does not start with a slash, the result is not an
|
---|
948 | * absolute path. Meaning, RTPathAppend(strcpy(szBuf, "C:"),
|
---|
949 | * sizeof(szBuf), "bar") will result in "C:bar".
|
---|
950 | */
|
---|
951 | RTDECL(int) RTPathAppendEx(char *pszPath, size_t cbPathDst, const char *pszAppend, size_t cchAppendMax);
|
---|
952 |
|
---|
953 | /**
|
---|
954 | * Like RTPathAppend, but with the base path as a separate argument instead of
|
---|
955 | * in the path buffer.
|
---|
956 | *
|
---|
957 | * @retval VINF_SUCCESS on success.
|
---|
958 | * @retval VERR_BUFFER_OVERFLOW if the result is too big to fit within
|
---|
959 | * cbPathDst bytes.
|
---|
960 | * @retval VERR_INVALID_PARAMETER if the string pointed to by pszPath is longer
|
---|
961 | * than cbPathDst-1 bytes (failed to find terminator). Asserted.
|
---|
962 | *
|
---|
963 | * @param pszPathDst Where to store the resulting path.
|
---|
964 | * @param cbPathDst The size of the buffer pszPathDst points to,
|
---|
965 | * terminator included.
|
---|
966 | * @param pszPathSrc The base path to copy into @a pszPathDst before
|
---|
967 | * appending @a pszAppend.
|
---|
968 | * @param pszAppend The partial path to append to pszPathSrc. This can
|
---|
969 | * be NULL, in which case nothing is done.
|
---|
970 | *
|
---|
971 | */
|
---|
972 | RTDECL(int) RTPathJoin(char *pszPathDst, size_t cbPathDst, const char *pszPathSrc,
|
---|
973 | const char *pszAppend);
|
---|
974 |
|
---|
975 | /**
|
---|
976 | * Same as RTPathJoin, except that the output buffer is allocated.
|
---|
977 | *
|
---|
978 | * @returns Buffer containing the joined up path, call RTStrFree to free. NULL
|
---|
979 | * on allocation failure.
|
---|
980 | * @param pszPathSrc The base path to copy into @a pszPathDst before
|
---|
981 | * appending @a pszAppend.
|
---|
982 | * @param pszAppend The partial path to append to pszPathSrc. This can
|
---|
983 | * be NULL, in which case nothing is done.
|
---|
984 | *
|
---|
985 | */
|
---|
986 | RTDECL(char *) RTPathJoinA(const char *pszPathSrc, const char *pszAppend);
|
---|
987 |
|
---|
988 | /**
|
---|
989 | * Extended version of RTPathJoin, both inputs can be specified as substrings.
|
---|
990 | *
|
---|
991 | * @retval VINF_SUCCESS on success.
|
---|
992 | * @retval VERR_BUFFER_OVERFLOW if the result is too big to fit within
|
---|
993 | * cbPathDst bytes.
|
---|
994 | * @retval VERR_INVALID_PARAMETER if the string pointed to by pszPath is longer
|
---|
995 | * than cbPathDst-1 bytes (failed to find terminator). Asserted.
|
---|
996 | *
|
---|
997 | * @param pszPathDst Where to store the resulting path.
|
---|
998 | * @param cbPathDst The size of the buffer pszPathDst points to,
|
---|
999 | * terminator included.
|
---|
1000 | * @param pszPathSrc The base path to copy into @a pszPathDst before
|
---|
1001 | * appending @a pszAppend.
|
---|
1002 | * @param cchPathSrcMax The maximum number of bytes to copy from @a
|
---|
1003 | * pszPathSrc. RTSTR_MAX is find.
|
---|
1004 | * @param pszAppend The partial path to append to pszPathSrc. This can
|
---|
1005 | * be NULL, in which case nothing is done.
|
---|
1006 | * @param cchAppendMax The maximum number of bytes to copy from @a
|
---|
1007 | * pszAppend. RTSTR_MAX is find.
|
---|
1008 | *
|
---|
1009 | */
|
---|
1010 | RTDECL(int) RTPathJoinEx(char *pszPathDst, size_t cbPathDst,
|
---|
1011 | const char *pszPathSrc, size_t cchPathSrcMax,
|
---|
1012 | const char *pszAppend, size_t cchAppendMax);
|
---|
1013 |
|
---|
1014 | /**
|
---|
1015 | * Callback for RTPathTraverseList that's called for each element.
|
---|
1016 | *
|
---|
1017 | * @returns IPRT style status code. Return VERR_TRY_AGAIN to continue, any other
|
---|
1018 | * value will abort the traversing and be returned to the caller.
|
---|
1019 | *
|
---|
1020 | * @param pchPath Pointer to the start of the current path. This is
|
---|
1021 | * not null terminated.
|
---|
1022 | * @param cchPath The length of the path.
|
---|
1023 | * @param pvUser1 The first user parameter.
|
---|
1024 | * @param pvUser2 The second user parameter.
|
---|
1025 | */
|
---|
1026 | typedef DECLCALLBACK(int) FNRTPATHTRAVERSER(char const *pchPath, size_t cchPath, void *pvUser1, void *pvUser2);
|
---|
1027 | /** Pointer to a FNRTPATHTRAVERSER. */
|
---|
1028 | typedef FNRTPATHTRAVERSER *PFNRTPATHTRAVERSER;
|
---|
1029 |
|
---|
1030 | /**
|
---|
1031 | * Traverses a string that can contain multiple paths separated by a special
|
---|
1032 | * character.
|
---|
1033 | *
|
---|
1034 | * @returns IPRT style status code from the callback or VERR_END_OF_STRING if
|
---|
1035 | * the callback returned VERR_TRY_AGAIN for all paths in the string.
|
---|
1036 | *
|
---|
1037 | * @param pszPathList The string to traverse.
|
---|
1038 | * @param chSep The separator character. Using the null terminator
|
---|
1039 | * is fine, but the result will simply be that there
|
---|
1040 | * will only be one callback for the entire string
|
---|
1041 | * (save any leading white space).
|
---|
1042 | * @param pfnCallback The callback.
|
---|
1043 | * @param pvUser1 First user argument for the callback.
|
---|
1044 | * @param pvUser2 Second user argument for the callback.
|
---|
1045 | */
|
---|
1046 | RTDECL(int) RTPathTraverseList(const char *pszPathList, char chSep, PFNRTPATHTRAVERSER pfnCallback, void *pvUser1, void *pvUser2);
|
---|
1047 |
|
---|
1048 |
|
---|
1049 | /**
|
---|
1050 | * Calculate a relative path between the two given paths.
|
---|
1051 | *
|
---|
1052 | * @returns IPRT status code.
|
---|
1053 | * @retval VINF_SUCCESS on success.
|
---|
1054 | * @retval VERR_BUFFER_OVERFLOW if the result is too big to fit within
|
---|
1055 | * cbPathDst bytes.
|
---|
1056 | * @retval VERR_NOT_SUPPORTED if both paths start with different volume specifiers.
|
---|
1057 | * @param pszPathDst Where to store the resulting path.
|
---|
1058 | * @param cbPathDst The size of the buffer pszPathDst points to,
|
---|
1059 | * terminator included.
|
---|
1060 | * @param pszPathFrom The path to start from creating the relative path.
|
---|
1061 | * @param pszPathTo The path to reach with the created relative path.
|
---|
1062 | */
|
---|
1063 | RTDECL(int) RTPathCalcRelative(char *pszPathDst, size_t cbPathDst,
|
---|
1064 | const char *pszPathFrom,
|
---|
1065 | const char *pszPathTo);
|
---|
1066 |
|
---|
1067 | #ifdef IN_RING3
|
---|
1068 |
|
---|
1069 | /**
|
---|
1070 | * Gets the path to the directory containing the executable.
|
---|
1071 | *
|
---|
1072 | * @returns iprt status code.
|
---|
1073 | * @param pszPath Buffer where to store the path.
|
---|
1074 | * @param cchPath Buffer size in bytes.
|
---|
1075 | */
|
---|
1076 | RTDECL(int) RTPathExecDir(char *pszPath, size_t cchPath);
|
---|
1077 |
|
---|
1078 | /**
|
---|
1079 | * Gets the user home directory.
|
---|
1080 | *
|
---|
1081 | * @returns iprt status code.
|
---|
1082 | * @param pszPath Buffer where to store the path.
|
---|
1083 | * @param cchPath Buffer size in bytes.
|
---|
1084 | */
|
---|
1085 | RTDECL(int) RTPathUserHome(char *pszPath, size_t cchPath);
|
---|
1086 |
|
---|
1087 | /**
|
---|
1088 | * Gets the user documents directory.
|
---|
1089 | *
|
---|
1090 | * The returned path isn't guaranteed to exist.
|
---|
1091 | *
|
---|
1092 | * @returns iprt status code.
|
---|
1093 | * @param pszPath Buffer where to store the path.
|
---|
1094 | * @param cchPath Buffer size in bytes.
|
---|
1095 | */
|
---|
1096 | RTDECL(int) RTPathUserDocuments(char *pszPath, size_t cchPath);
|
---|
1097 |
|
---|
1098 | /**
|
---|
1099 | * Gets the directory of shared libraries.
|
---|
1100 | *
|
---|
1101 | * This is not the same as RTPathAppPrivateArch() as Linux depends all shared
|
---|
1102 | * libraries in a common global directory where ld.so can find them.
|
---|
1103 | *
|
---|
1104 | * Linux: /usr/lib
|
---|
1105 | * Solaris: /opt/@<application@>/@<arch>@ or something
|
---|
1106 | * Windows: @<program files directory@>/@<application@>
|
---|
1107 | * Old path: same as RTPathExecDir()
|
---|
1108 | *
|
---|
1109 | * @returns iprt status code.
|
---|
1110 | * @param pszPath Buffer where to store the path.
|
---|
1111 | * @param cchPath Buffer size in bytes.
|
---|
1112 | */
|
---|
1113 | RTDECL(int) RTPathSharedLibs(char *pszPath, size_t cchPath);
|
---|
1114 |
|
---|
1115 | /**
|
---|
1116 | * Gets the directory for architecture-independent application data, for
|
---|
1117 | * example NLS files, module sources, ...
|
---|
1118 | *
|
---|
1119 | * Linux: /usr/shared/@<application@>
|
---|
1120 | * Solaris: /opt/@<application@>
|
---|
1121 | * Windows: @<program files directory@>/@<application@>
|
---|
1122 | * Old path: same as RTPathExecDir()
|
---|
1123 | *
|
---|
1124 | * @returns iprt status code.
|
---|
1125 | * @param pszPath Buffer where to store the path.
|
---|
1126 | * @param cchPath Buffer size in bytes.
|
---|
1127 | */
|
---|
1128 | RTDECL(int) RTPathAppPrivateNoArch(char *pszPath, size_t cchPath);
|
---|
1129 |
|
---|
1130 | /**
|
---|
1131 | * Gets the directory for architecture-dependent application data, for
|
---|
1132 | * example modules which can be loaded at runtime.
|
---|
1133 | *
|
---|
1134 | * Linux: /usr/lib/@<application@>
|
---|
1135 | * Solaris: /opt/@<application@>/@<arch>@ or something
|
---|
1136 | * Windows: @<program files directory@>/@<application@>
|
---|
1137 | * Old path: same as RTPathExecDir()
|
---|
1138 | *
|
---|
1139 | * @returns iprt status code.
|
---|
1140 | * @param pszPath Buffer where to store the path.
|
---|
1141 | * @param cchPath Buffer size in bytes.
|
---|
1142 | */
|
---|
1143 | RTDECL(int) RTPathAppPrivateArch(char *pszPath, size_t cchPath);
|
---|
1144 |
|
---|
1145 | /**
|
---|
1146 | * Gets the toplevel directory for architecture-dependent application data.
|
---|
1147 | *
|
---|
1148 | * This differs from RTPathAppPrivateArch on Solaris only where it will work
|
---|
1149 | * around the /opt/@<application@>/amd64 and /opt/@<application@>/i386 multi
|
---|
1150 | * architecture installation style.
|
---|
1151 | *
|
---|
1152 | * Linux: /usr/lib/@<application@>
|
---|
1153 | * Solaris: /opt/@<application@>
|
---|
1154 | * Windows: @<program files directory@>/@<application@>
|
---|
1155 | * Old path: same as RTPathExecDir()
|
---|
1156 | *
|
---|
1157 | * @returns iprt status code.
|
---|
1158 | * @param pszPath Buffer where to store the path.
|
---|
1159 | * @param cchPath Buffer size in bytes.
|
---|
1160 | */
|
---|
1161 | RTDECL(int) RTPathAppPrivateArchTop(char *pszPath, size_t cchPath);
|
---|
1162 |
|
---|
1163 | /**
|
---|
1164 | * Gets the directory for documentation.
|
---|
1165 | *
|
---|
1166 | * Linux: /usr/share/doc/@<application@>
|
---|
1167 | * Solaris: /opt/@<application@>
|
---|
1168 | * Windows: @<program files directory@>/@<application@>
|
---|
1169 | * Old path: same as RTPathExecDir()
|
---|
1170 | *
|
---|
1171 | * @returns iprt status code.
|
---|
1172 | * @param pszPath Buffer where to store the path.
|
---|
1173 | * @param cchPath Buffer size in bytes.
|
---|
1174 | */
|
---|
1175 | RTDECL(int) RTPathAppDocs(char *pszPath, size_t cchPath);
|
---|
1176 |
|
---|
1177 | /**
|
---|
1178 | * Gets the temporary directory path.
|
---|
1179 | *
|
---|
1180 | * @returns iprt status code.
|
---|
1181 | * @param pszPath Buffer where to store the path.
|
---|
1182 | * @param cchPath Buffer size in bytes.
|
---|
1183 | */
|
---|
1184 | RTDECL(int) RTPathTemp(char *pszPath, size_t cchPath);
|
---|
1185 |
|
---|
1186 |
|
---|
1187 | /**
|
---|
1188 | * RTPathGlobl result entry.
|
---|
1189 | */
|
---|
1190 | typedef struct RTPATHGLOBENTRY
|
---|
1191 | {
|
---|
1192 | /** List entry. */
|
---|
1193 | struct RTPATHGLOBENTRY *pNext;
|
---|
1194 | /** RTDIRENTRYTYPE value. */
|
---|
1195 | uint8_t uType;
|
---|
1196 | /** Unused explicit padding. */
|
---|
1197 | uint8_t bUnused;
|
---|
1198 | /** The length of the path. */
|
---|
1199 | uint16_t cchPath;
|
---|
1200 | /** The path to the file (variable length). */
|
---|
1201 | char szPath[1];
|
---|
1202 | } RTPATHGLOBENTRY;
|
---|
1203 | /** Pointer to a GLOB result entry. */
|
---|
1204 | typedef RTPATHGLOBENTRY *PRTPATHGLOBENTRY;
|
---|
1205 | /** Pointer to a const GLOB result entry. */
|
---|
1206 | typedef RTPATHGLOBENTRY const *PCRTPATHGLOBENTRY;
|
---|
1207 | /** Pointer to a GLOB result entry pointer. */
|
---|
1208 | typedef PCRTPATHGLOBENTRY *PPCRTPATHGLOBENTRY;
|
---|
1209 |
|
---|
1210 | /**
|
---|
1211 | * Performs wildcard expansion on a path pattern.
|
---|
1212 | *
|
---|
1213 | * @returns IPRT status code.
|
---|
1214 | *
|
---|
1215 | * @param pszPattern The pattern to expand.
|
---|
1216 | * @param fFlags RTPATHGLOB_F_XXX.
|
---|
1217 | * @param ppHead Where to return the head of the result list. This
|
---|
1218 | * is always set to NULL on failure.
|
---|
1219 | * @param pcResults Where to return the number of the result. Optional.
|
---|
1220 | */
|
---|
1221 | RTDECL(int) RTPathGlob(const char *pszPattern, uint32_t fFlags, PPCRTPATHGLOBENTRY ppHead, uint32_t *pcResults);
|
---|
1222 |
|
---|
1223 | /** @name RTPATHGLOB_F_XXX - RTPathGlob flags
|
---|
1224 | * @{ */
|
---|
1225 | /** Case insensitive. */
|
---|
1226 | #define RTPATHGLOB_F_IGNORE_CASE RT_BIT_32(0)
|
---|
1227 | /** Do not expand \${EnvOrSpecialVariable} in the pattern. */
|
---|
1228 | #define RTPATHGLOB_F_NO_VARIABLES RT_BIT_32(1)
|
---|
1229 | /** Do not interpret a leading tilde as a home directory reference. */
|
---|
1230 | #define RTPATHGLOB_F_NO_TILDE RT_BIT_32(2)
|
---|
1231 | /** Only return the first match. */
|
---|
1232 | #define RTPATHGLOB_F_FIRST_ONLY RT_BIT_32(3)
|
---|
1233 | /** Only match directories (implied if pattern ends with slash). */
|
---|
1234 | #define RTPATHGLOB_F_ONLY_DIRS RT_BIT_32(4)
|
---|
1235 | /** Do not match directories. (Can't be used with RTPATHGLOB_F_ONLY_DIRS or
|
---|
1236 | * patterns containing a trailing slash.) */
|
---|
1237 | #define RTPATHGLOB_F_NO_DIRS RT_BIT_32(5)
|
---|
1238 | /** Disables the '**' wildcard pattern for matching zero or more subdirs. */
|
---|
1239 | #define RTPATHGLOB_F_NO_STARSTAR RT_BIT_32(6)
|
---|
1240 | /** Mask of valid flags. */
|
---|
1241 | #define RTPATHGLOB_F_MASK UINT32_C(0x0000007f)
|
---|
1242 | /** @} */
|
---|
1243 |
|
---|
1244 | /**
|
---|
1245 | * Frees the results produced by RTPathGlob.
|
---|
1246 | *
|
---|
1247 | * @param pHead What RTPathGlob returned. NULL ignored.
|
---|
1248 | */
|
---|
1249 | RTDECL(void) RTPathGlobFree(PCRTPATHGLOBENTRY pHead);
|
---|
1250 |
|
---|
1251 |
|
---|
1252 | /**
|
---|
1253 | * Query information about a file system object.
|
---|
1254 | *
|
---|
1255 | * This API will resolve NOT symbolic links in the last component (just like
|
---|
1256 | * unix lstat()).
|
---|
1257 | *
|
---|
1258 | * @returns IPRT status code.
|
---|
1259 | * @retval VINF_SUCCESS if the object exists, information returned.
|
---|
1260 | * @retval VERR_PATH_NOT_FOUND if any but the last component in the specified
|
---|
1261 | * path was not found or was not a directory.
|
---|
1262 | * @retval VERR_FILE_NOT_FOUND if the object does not exist (but path to the
|
---|
1263 | * parent directory exists).
|
---|
1264 | *
|
---|
1265 | * @param pszPath Path to the file system object.
|
---|
1266 | * @param pObjInfo Object information structure to be filled on successful
|
---|
1267 | * return.
|
---|
1268 | * @param enmAdditionalAttribs
|
---|
1269 | * Which set of additional attributes to request.
|
---|
1270 | * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
|
---|
1271 | */
|
---|
1272 | RTR3DECL(int) RTPathQueryInfo(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs);
|
---|
1273 |
|
---|
1274 | /**
|
---|
1275 | * Query information about a file system object.
|
---|
1276 | *
|
---|
1277 | * @returns IPRT status code.
|
---|
1278 | * @retval VINF_SUCCESS if the object exists, information returned.
|
---|
1279 | * @retval VERR_PATH_NOT_FOUND if any but the last component in the specified
|
---|
1280 | * path was not found or was not a directory.
|
---|
1281 | * @retval VERR_FILE_NOT_FOUND if the object does not exist (but path to the
|
---|
1282 | * parent directory exists).
|
---|
1283 | *
|
---|
1284 | * @param pszPath Path to the file system object.
|
---|
1285 | * @param pObjInfo Object information structure to be filled on successful return.
|
---|
1286 | * @param enmAdditionalAttribs
|
---|
1287 | * Which set of additional attributes to request.
|
---|
1288 | * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
|
---|
1289 | * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
|
---|
1290 | */
|
---|
1291 | RTR3DECL(int) RTPathQueryInfoEx(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags);
|
---|
1292 |
|
---|
1293 | /**
|
---|
1294 | * Changes the mode flags of a file system object.
|
---|
1295 | *
|
---|
1296 | * The API requires at least one of the mode flag sets (Unix/Dos) to
|
---|
1297 | * be set. The type is ignored.
|
---|
1298 | *
|
---|
1299 | * This API will resolve symbolic links in the last component since
|
---|
1300 | * mode isn't important for symbolic links.
|
---|
1301 | *
|
---|
1302 | * @returns iprt status code.
|
---|
1303 | * @param pszPath Path to the file system object.
|
---|
1304 | * @param fMode The new file mode, see @ref grp_rt_fs for details.
|
---|
1305 | */
|
---|
1306 | RTR3DECL(int) RTPathSetMode(const char *pszPath, RTFMODE fMode);
|
---|
1307 |
|
---|
1308 | /**
|
---|
1309 | * Gets the mode flags of a file system object.
|
---|
1310 | *
|
---|
1311 | * @returns iprt status code.
|
---|
1312 | * @param pszPath Path to the file system object.
|
---|
1313 | * @param pfMode Where to store the file mode, see @ref grp_rt_fs for details.
|
---|
1314 | *
|
---|
1315 | * @remark This is wrapper around RTPathQueryInfoEx(RTPATH_F_FOLLOW_LINK) and
|
---|
1316 | * exists to complement RTPathSetMode().
|
---|
1317 | */
|
---|
1318 | RTR3DECL(int) RTPathGetMode(const char *pszPath, PRTFMODE pfMode);
|
---|
1319 |
|
---|
1320 | /**
|
---|
1321 | * Changes one or more of the timestamps associated of file system object.
|
---|
1322 | *
|
---|
1323 | * This API will not resolve symbolic links in the last component (just
|
---|
1324 | * like unix lutimes()).
|
---|
1325 | *
|
---|
1326 | * @returns iprt status code.
|
---|
1327 | * @param pszPath Path to the file system object.
|
---|
1328 | * @param pAccessTime Pointer to the new access time.
|
---|
1329 | * @param pModificationTime Pointer to the new modification time.
|
---|
1330 | * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
|
---|
1331 | * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
|
---|
1332 | *
|
---|
1333 | * @remark The file system might not implement all these time attributes,
|
---|
1334 | * the API will ignore the ones which aren't supported.
|
---|
1335 | *
|
---|
1336 | * @remark The file system might not implement the time resolution
|
---|
1337 | * employed by this interface, the time will be chopped to fit.
|
---|
1338 | *
|
---|
1339 | * @remark The file system may update the change time even if it's
|
---|
1340 | * not specified.
|
---|
1341 | *
|
---|
1342 | * @remark POSIX can only set Access & Modification and will always set both.
|
---|
1343 | */
|
---|
1344 | RTR3DECL(int) RTPathSetTimes(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
|
---|
1345 | PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
|
---|
1346 |
|
---|
1347 | /**
|
---|
1348 | * Changes one or more of the timestamps associated of file system object.
|
---|
1349 | *
|
---|
1350 | * @returns iprt status code.
|
---|
1351 | * @param pszPath Path to the file system object.
|
---|
1352 | * @param pAccessTime Pointer to the new access time.
|
---|
1353 | * @param pModificationTime Pointer to the new modification time.
|
---|
1354 | * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
|
---|
1355 | * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
|
---|
1356 | * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
|
---|
1357 | *
|
---|
1358 | * @remark The file system might not implement all these time attributes,
|
---|
1359 | * the API will ignore the ones which aren't supported.
|
---|
1360 | *
|
---|
1361 | * @remark The file system might not implement the time resolution
|
---|
1362 | * employed by this interface, the time will be chopped to fit.
|
---|
1363 | *
|
---|
1364 | * @remark The file system may update the change time even if it's
|
---|
1365 | * not specified.
|
---|
1366 | *
|
---|
1367 | * @remark POSIX can only set Access & Modification and will always set both.
|
---|
1368 | */
|
---|
1369 | RTR3DECL(int) RTPathSetTimesEx(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
|
---|
1370 | PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime, uint32_t fFlags);
|
---|
1371 |
|
---|
1372 | /**
|
---|
1373 | * Gets one or more of the timestamps associated of file system object.
|
---|
1374 | *
|
---|
1375 | * @returns iprt status code.
|
---|
1376 | * @param pszPath Path to the file system object.
|
---|
1377 | * @param pAccessTime Where to store the access time. NULL is ok.
|
---|
1378 | * @param pModificationTime Where to store the modification time. NULL is ok.
|
---|
1379 | * @param pChangeTime Where to store the change time. NULL is ok.
|
---|
1380 | * @param pBirthTime Where to store the creation time. NULL is ok.
|
---|
1381 | *
|
---|
1382 | * @remark This is wrapper around RTPathQueryInfo() and exists to complement
|
---|
1383 | * RTPathSetTimes(). If the last component is a symbolic link, it will
|
---|
1384 | * not be resolved.
|
---|
1385 | */
|
---|
1386 | RTR3DECL(int) RTPathGetTimes(const char *pszPath, PRTTIMESPEC pAccessTime, PRTTIMESPEC pModificationTime,
|
---|
1387 | PRTTIMESPEC pChangeTime, PRTTIMESPEC pBirthTime);
|
---|
1388 |
|
---|
1389 | /**
|
---|
1390 | * Changes the owner and/or group of a file system object.
|
---|
1391 | *
|
---|
1392 | * This API will not resolve symbolic links in the last component (just
|
---|
1393 | * like unix lchown()).
|
---|
1394 | *
|
---|
1395 | * @returns iprt status code.
|
---|
1396 | * @param pszPath Path to the file system object.
|
---|
1397 | * @param uid The new file owner user id. Pass NIL_RTUID to leave
|
---|
1398 | * this unchanged.
|
---|
1399 | * @param gid The new group id. Pass NIL_RTGUID to leave this
|
---|
1400 | * unchanged.
|
---|
1401 | */
|
---|
1402 | RTR3DECL(int) RTPathSetOwner(const char *pszPath, uint32_t uid, uint32_t gid);
|
---|
1403 |
|
---|
1404 | /**
|
---|
1405 | * Changes the owner and/or group of a file system object.
|
---|
1406 | *
|
---|
1407 | * @returns iprt status code.
|
---|
1408 | * @param pszPath Path to the file system object.
|
---|
1409 | * @param uid The new file owner user id. Pass NIL_RTUID to leave
|
---|
1410 | * this unchanged.
|
---|
1411 | * @param gid The new group id. Pass NIL_RTGID to leave this
|
---|
1412 | * unchanged.
|
---|
1413 | * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
|
---|
1414 | */
|
---|
1415 | RTR3DECL(int) RTPathSetOwnerEx(const char *pszPath, uint32_t uid, uint32_t gid, uint32_t fFlags);
|
---|
1416 |
|
---|
1417 | /**
|
---|
1418 | * Gets the owner and/or group of a file system object.
|
---|
1419 | *
|
---|
1420 | * @returns iprt status code.
|
---|
1421 | * @param pszPath Path to the file system object.
|
---|
1422 | * @param pUid Where to store the owner user id. NULL is ok.
|
---|
1423 | * @param pGid Where to store the group id. NULL is ok.
|
---|
1424 | *
|
---|
1425 | * @remark This is wrapper around RTPathQueryInfo() and exists to complement
|
---|
1426 | * RTPathGetOwner(). If the last component is a symbolic link, it will
|
---|
1427 | * not be resolved.
|
---|
1428 | */
|
---|
1429 | RTR3DECL(int) RTPathGetOwner(const char *pszPath, uint32_t *pUid, uint32_t *pGid);
|
---|
1430 |
|
---|
1431 |
|
---|
1432 | /** @name RTPathRename, RTDirRename & RTFileRename flags.
|
---|
1433 | * @{ */
|
---|
1434 | /** Do not replace anything. */
|
---|
1435 | #define RTPATHRENAME_FLAGS_NO_REPLACE UINT32_C(0)
|
---|
1436 | /** This will replace attempt any target which isn't a directory. */
|
---|
1437 | #define RTPATHRENAME_FLAGS_REPLACE RT_BIT(0)
|
---|
1438 | /** Don't allow symbolic links as part of the path.
|
---|
1439 | * @remarks this flag is currently not implemented and will be ignored. */
|
---|
1440 | #define RTPATHRENAME_FLAGS_NO_SYMLINKS RT_BIT(1)
|
---|
1441 | /** @} */
|
---|
1442 |
|
---|
1443 | /**
|
---|
1444 | * Renames a path within a filesystem.
|
---|
1445 | *
|
---|
1446 | * This will rename symbolic links. If RTPATHRENAME_FLAGS_REPLACE is used and
|
---|
1447 | * pszDst is a symbolic link, it will be replaced and not its target.
|
---|
1448 | *
|
---|
1449 | * @returns IPRT status code.
|
---|
1450 | * @param pszSrc The source path.
|
---|
1451 | * @param pszDst The destination path.
|
---|
1452 | * @param fRename Rename flags, RTPATHRENAME_FLAGS_*.
|
---|
1453 | */
|
---|
1454 | RTR3DECL(int) RTPathRename(const char *pszSrc, const char *pszDst, unsigned fRename);
|
---|
1455 |
|
---|
1456 | /** @name RTPathUnlink flags.
|
---|
1457 | * @{ */
|
---|
1458 | /** Don't allow symbolic links as part of the path.
|
---|
1459 | * @remarks this flag is currently not implemented and will be ignored. */
|
---|
1460 | #define RTPATHUNLINK_FLAGS_NO_SYMLINKS RT_BIT(0)
|
---|
1461 | /** @} */
|
---|
1462 |
|
---|
1463 | /**
|
---|
1464 | * Removes the last component of the path.
|
---|
1465 | *
|
---|
1466 | * @returns IPRT status code.
|
---|
1467 | * @param pszPath The path.
|
---|
1468 | * @param fUnlink Unlink flags, RTPATHUNLINK_FLAGS_*.
|
---|
1469 | */
|
---|
1470 | RTR3DECL(int) RTPathUnlink(const char *pszPath, uint32_t fUnlink);
|
---|
1471 |
|
---|
1472 | /**
|
---|
1473 | * A /bin/rm tool.
|
---|
1474 | *
|
---|
1475 | * @returns Program exit code.
|
---|
1476 | *
|
---|
1477 | * @param cArgs The number of arguments.
|
---|
1478 | * @param papszArgs The argument vector. (Note that this may be
|
---|
1479 | * reordered, so the memory must be writable.)
|
---|
1480 | */
|
---|
1481 | RTDECL(RTEXITCODE) RTPathRmCmd(unsigned cArgs, char **papszArgs);
|
---|
1482 |
|
---|
1483 | #endif /* IN_RING3 */
|
---|
1484 |
|
---|
1485 | /** @} */
|
---|
1486 |
|
---|
1487 | RT_C_DECLS_END
|
---|
1488 |
|
---|
1489 | #endif
|
---|
1490 |
|
---|