VirtualBox

source: vbox/trunk/include/iprt/path.h@ 45394

Last change on this file since 45394 was 45394, checked in by vboxsync, 12 years ago

IPRT: A Study in Paths - Chapter 2: The splitting of a path into component strings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 49.9 KB
Line 
1/** @file
2 * IPRT - Path Manipulation.
3 */
4
5/*
6 * Copyright (C) 2006-2013 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
37RT_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 */
213RTDECL(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 */
222RTDECL(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 */
230RTDECL(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 */
239RTDECL(int) RTPathGetCurrent(char *pszPath, size_t cchPath);
240
241/**
242 * Get the real path (no symlinks, no . or .. components), must exist.
243 *
244 * @returns iprt status code.
245 * @param pszPath The path to resolve.
246 * @param pszRealPath Where to store the real path.
247 * @param cchRealPath Size of the buffer.
248 */
249RTDECL(int) RTPathReal(const char *pszPath, char *pszRealPath, size_t cchRealPath);
250
251/**
252 * Same as RTPathReal only the result is RTStrDup()'ed.
253 *
254 * @returns Pointer to real path. Use RTStrFree() to free this string.
255 * @returns NULL if RTPathReal() or RTStrDup() fails.
256 * @param pszPath The path to resolve.
257 */
258RTDECL(char *) RTPathRealDup(const char *pszPath);
259
260/**
261 * Get the absolute path (starts from root, no . or .. components), doesn't have
262 * to exist. Note that this method is designed to never perform actual file
263 * system access, therefore symlinks are not resolved.
264 *
265 * @returns iprt status code.
266 * @param pszPath The path to resolve.
267 * @param pszAbsPath Where to store the absolute path.
268 * @param cchAbsPath Size of the buffer.
269 */
270RTDECL(int) RTPathAbs(const char *pszPath, char *pszAbsPath, size_t cchAbsPath);
271
272/**
273 * Same as RTPathAbs only the result is RTStrDup()'ed.
274 *
275 * @returns Pointer to the absolute path. Use RTStrFree() to free this string.
276 * @returns NULL if RTPathAbs() or RTStrDup() fails.
277 * @param pszPath The path to resolve.
278 */
279RTDECL(char *) RTPathAbsDup(const char *pszPath);
280
281/**
282 * Get the absolute path (no symlinks, no . or .. components), assuming the
283 * given base path as the current directory. The resulting path doesn't have
284 * to exist.
285 *
286 * @returns iprt status code.
287 * @param pszBase The base path to act like a current directory.
288 * When NULL, the actual cwd is used (i.e. the call
289 * is equivalent to RTPathAbs(pszPath, ...).
290 * @param pszPath The path to resolve.
291 * @param pszAbsPath Where to store the absolute path.
292 * @param cchAbsPath Size of the buffer.
293 */
294RTDECL(int) RTPathAbsEx(const char *pszBase, const char *pszPath, char *pszAbsPath, size_t cchAbsPath);
295
296/**
297 * Same as RTPathAbsEx only the result is RTStrDup()'ed.
298 *
299 * @returns Pointer to the absolute path. Use RTStrFree() to free this string.
300 * @returns NULL if RTPathAbsEx() or RTStrDup() fails.
301 * @param pszBase The base path to act like a current directory.
302 * When NULL, the actual cwd is used (i.e. the call
303 * is equivalent to RTPathAbs(pszPath, ...).
304 * @param pszPath The path to resolve.
305 */
306RTDECL(char *) RTPathAbsExDup(const char *pszBase, const char *pszPath);
307
308/**
309 * Strips the filename from a path. Truncates the given string in-place by overwriting the
310 * last path separator character with a null byte in a platform-neutral way.
311 *
312 * @param pszPath Path from which filename should be extracted, will be truncated.
313 * If the string contains no path separator, it will be changed to a "." string.
314 */
315RTDECL(void) RTPathStripFilename(char *pszPath);
316
317/**
318 * Strips the extension from a path.
319 *
320 * @param pszPath Path which extension should be stripped.
321 */
322RTDECL(void) RTPathStripExt(char *pszPath);
323
324/**
325 * Strips the trailing slashes of a path name.
326 *
327 * Won't strip root slashes.
328 *
329 * @returns The new length of pszPath.
330 * @param pszPath Path to strip.
331 */
332RTDECL(size_t) RTPathStripTrailingSlash(char *pszPath);
333
334/**
335 * Changes all the slashes in the specified path to DOS style.
336 *
337 * Unless @a fForce is set, nothing will be done when on a UNIX flavored system
338 * since paths wont work with DOS style slashes there.
339 *
340 * @returns @a pszPath.
341 * @param pszPath The path to modify.
342 * @param fForce Whether to force the conversion on non-DOS OSes.
343 */
344RTDECL(char *) RTPathChangeToDosSlashes(char *pszPath, bool fForce);
345
346/**
347 * Changes all the slashes in the specified path to unix style.
348 *
349 * Unless @a fForce is set, nothing will be done when on a UNIX flavored system
350 * since paths wont work with DOS style slashes there.
351 *
352 * @returns @a pszPath.
353 * @param pszPath The path to modify.
354 * @param fForce Whether to force the conversion on non-DOS OSes.
355 */
356RTDECL(char *) RTPathChangeToUnixSlashes(char *pszPath, bool fForce);
357
358/**
359 * Simple parsing of the a path.
360 *
361 * It figures the length of the directory component, the offset of
362 * the file name and the location of the suffix dot.
363 *
364 * @returns The path length.
365 *
366 * @param pszPath Path to find filename in.
367 * @param pcchDir Where to put the length of the directory component. If
368 * no directory, this will be 0. Optional.
369 * @param poffName Where to store the filename offset.
370 * If empty string or if it's ending with a slash this
371 * will be set to -1. Optional.
372 * @param poffSuff Where to store the suffix offset (the last dot).
373 * If empty string or if it's ending with a slash this
374 * will be set to -1. Optional.
375 */
376RTDECL(size_t) RTPathParseSimple(const char *pszPath, size_t *pcchDir, ssize_t *poffName, ssize_t *poffSuff);
377
378/**
379 * Finds the filename in a path.
380 *
381 * @returns Pointer to filename within pszPath.
382 * @returns NULL if no filename (i.e. empty string or ends with a slash).
383 * @param pszPath Path to find filename in.
384 */
385RTDECL(char *) RTPathFilename(const char *pszPath);
386
387/**
388 * Finds the extension part of in a path.
389 *
390 * @returns Pointer to extension within pszPath.
391 * @returns NULL if no extension.
392 * @param pszPath Path to find extension in.
393 */
394RTDECL(char *) RTPathExt(const char *pszPath);
395
396/**
397 * Checks if a path has an extension.
398 *
399 * @returns true if extension present.
400 * @returns false if no extension.
401 * @param pszPath Path to check.
402 */
403RTDECL(bool) RTPathHasExt(const char *pszPath);
404/** Misspelled, don't use. */
405#define RTPathHaveExt RTPathHasExt
406
407/**
408 * Checks if a path includes more than a filename.
409 *
410 * @returns true if path present.
411 * @returns false if no path.
412 * @param pszPath Path to check.
413 */
414RTDECL(bool) RTPathHasPath(const char *pszPath);
415/** Misspelled, don't use. */
416#define RTPathHavePath RTPathHasPath
417
418/**
419 * Checks if the path starts with a root specifier or not.
420 *
421 * @returns @c true if it starts with root, @c false if not.
422 *
423 * @param pszPath Path to check.
424 */
425RTDECL(bool) RTPathStartsWithRoot(const char *pszPath);
426
427/**
428 * Counts the components in the specified path.
429 *
430 * An empty string has zero components. A lone root slash is considered have
431 * one. The paths "/init" and "/bin/" are considered having two components. An
432 * UNC share specifier like "\\myserver\share" will be considered as one single
433 * component.
434 *
435 * @returns The number of path components.
436 * @param pszPath The path to parse.
437 */
438RTDECL(size_t) RTPathCountComponents(const char *pszPath);
439
440/**
441 * Copies the specified number of path components from @a pszSrc and into @a
442 * pszDst.
443 *
444 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW. In the latter case the buffer
445 * is not touched.
446 *
447 * @param pszDst The destination buffer.
448 * @param cbDst The size of the destination buffer.
449 * @param pszSrc The source path.
450 * @param cComponents The number of components to copy from @a pszSrc.
451 */
452RTDECL(int) RTPathCopyComponents(char *pszDst, size_t cbDst, const char *pszSrc, size_t cComponents);
453
454/** @name Path properties returned by RTPathParse and RTPathSplit.
455 * @{ */
456
457/** Indicates that there is a filename.
458 * If not set, either a lone root spec was given (RTPATH_PROP_UNC,
459 * RTPATH_PROP_ROOT_SLASH, or RTPATH_PROP_VOLUME) or the final component had a
460 * trailing slash (RTPATH_PROP_DIR_SLASH). */
461#define RTPATH_PROP_FILENAME UINT16_C(0x0001)
462/** Indicates that a directory was specified using a trailing slash.
463 * @note This is not set for lone root specifications (RTPATH_PROP_UNC,
464 * RTPATH_PROP_ROOT_SLASH, or RTPATH_PROP_VOLUME).
465 * @note The slash is not counted into the last component. However, it is
466 * counted into cchPath. */
467#define RTPATH_PROP_DIR_SLASH UINT16_C(0x0002)
468
469/** The filename has a suffix (extension). */
470#define RTPATH_PROP_SUFFIX UINT16_C(0x0004)
471/** Indicates that this is an UNC path (Windows and OS/2 only).
472 *
473 * UNC = Universal Naming Convention. It is on the form '//Computer/',
474 * '//Namespace/', '//ComputerName/Resource' and '//Namespace/Resource'.
475 * RTPathParse, RTPathSplit and friends does not consider the 'Resource' as
476 * part of the UNC root specifier. Thus the root specs for the above examples
477 * would be '//ComputerName/' or '//Namespace/'.
478 *
479 * Please note that '//something' is not a UNC path, there must be a slash
480 * following the computer or namespace.
481 */
482#define RTPATH_PROP_UNC UINT16_C(0x0010)
483/** A root slash was specified (unix style root).
484 * (While the path must relative if not set, this being set doesn't make it
485 * absolute.)
486 *
487 * This will be set in the following examples: '/', '/bin', 'C:/', 'C:/Windows',
488 * '//./', '//./PhysicalDisk0', '//example.org/', and '//example.org/share'.
489 *
490 * It will not be set for the following examples: '.', 'bin/ls', 'C:', and
491 * 'C:Windows'.
492 */
493#define RTPATH_PROP_ROOT_SLASH UINT16_C(0x0020)
494/** A volume is specified (Windows, DOS and OS/2).
495 * For examples: 'C:', 'C:/', and 'A:/AutoExec.bat'. */
496#define RTPATH_PROP_VOLUME UINT16_C(0x0040)
497/** The path is absolute, i.e. has a root specifier (root-slash,
498 * volume or UNC) and contains no winding '..' bits, though it may contain
499 * unnecessary slashes (RTPATH_PROP_EXTRA_SLASHES) and '.' components
500 * (RTPATH_PROP_DOT_REFS).
501 *
502 * On systems without volumes and UNC (unix style) it will be set for '/',
503 * '/bin/ls', and '/bin//./ls', but not for 'bin/ls', /bin/../usr/bin/env',
504 * '/./bin/ls' or '/.'.
505 *
506 * On systems with volumes, it will be set for 'C:/', C:/Windows', and
507 * 'C:/./Windows//', but not for 'C:', 'C:Windows', or 'C:/Windows/../boot.ini'.
508 *
509 * On systems with UNC paths, it will be set for '//localhost/',
510 * '//localhost/C$', '//localhost/C$/Windows/System32', '//localhost/.', and
511 * '//localhost/C$//./AutoExec.bat', but not for
512 * '//localhost/C$/Windows/../AutoExec.bat'.
513 *
514 * @note For the RTPathAbs definition, this flag needs to be set while both
515 * RTPATH_PROP_EXTRA_SLASHES and RTPATH_PROP_DOT_REFS must be cleared.
516 */
517#define RTPATH_PROP_ABSOLUTE UINT16_C(0x0100)
518/** Relative path. Inverse of RTPATH_PROP_ABSOLUTE. */
519#define RTPATH_PROP_RELATIVE UINT16_C(0x0200)
520/** The path contains unnecessary slashes. Meaning, that if */
521#define RTPATH_PROP_EXTRA_SLASHES UINT16_C(0x0400)
522/** The path contains references to the special '.' (dot) directory link. */
523#define RTPATH_PROP_DOT_REFS UINT16_C(0x0800)
524/** The path contains references to the special '..' (dot) directory link.
525 * RTPATH_PROP_RELATIVE will always be set together with this. */
526#define RTPATH_PROP_DOTDOT_REFS UINT16_C(0x1000)
527
528
529/** Macro to determin whether to insert a slash after the first component when
530 * joining it with something else.
531 * (All other components in a split or parsed path requies slashes added.) */
532#define RTPATH_PROP_FIRST_NEEDS_NO_SLASH(a_fProps) \
533 RT_BOOL( (a_fProps) & (RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_VOLUME | RTPATH_PROP_UNC) )
534
535/** Macro to determin whether there is a root specification of any kind
536 * (unix, volumes, unc). */
537#define RTPATH_PROP_HAS_ROOT_SPEC(a_fProps) \
538 RT_BOOL( (a_fProps) & (RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_VOLUME | RTPATH_PROP_UNC) )
539
540/** @} */
541
542
543/**
544 * Parsed path.
545 *
546 * The first component is the root, volume or UNC specifier, if present. Use
547 * RTPATH_PROP_HAS_ROOT_SPEC() on RTPATHPARSED::fProps to determine its
548 * precense.
549 *
550 * Other than the root component, no component will include directory separators
551 * (slashes).
552 */
553typedef struct RTPATHPARSED
554{
555 /** Number of path components.
556 * This will always be set on VERR_BUFFER_OVERFLOW returns from RTPathParsed
557 * so the caller can calculate the required buffer size. */
558 uint16_t cComps;
559 /** Path property flags, RTPATH_PROP_XXX */
560 uint16_t fProps;
561 /** On success this is the length of the described path, i.e. sum of all
562 * component lengths and necessary separators.
563 * Do NOT use this to index in the source path in case it contains
564 * unnecessary slashes that RTPathParsed has ignored here. */
565 uint16_t cchPath;
566 /** Reserved for future use. */
567 uint16_t u16Reserved;
568 /** The offset of the filename suffix, offset of the NUL char if none. */
569 uint16_t offSuffix;
570 /** The lenght of the suffix. */
571 uint16_t cchSuffix;
572 /** Array of component descriptors (variable size).
573 * @note Don't try figure the end of the input path by adding up off and cch
574 * of the last component. If RTPATH_PROP_DIR_SLASH is set, there may
575 * be one or more trailing slashes that are unaccounted for! */
576 struct
577 {
578 /** The offset of the component. */
579 uint16_t off;
580 /** The length of the component. */
581 uint16_t cch;
582 } aComps[1];
583} RTPATHPARSED;
584/** Pointer to to a parsed path result. */
585typedef RTPATHPARSED *PRTPATHPARSED;
586/** Pointer to to a const parsed path result. */
587typedef RTPATHPARSED *PCRTPATHPARSED;
588
589
590/**
591 * Parses the path.
592 *
593 * @returns IPRT status code.
594 * @retval VERR_INVALID_POINTER if pParsed or pszPath is an invalid pointer.
595 * @retval VERR_INVALID_PARAMETER if cbOutput is less than the RTPATHPARSED
596 * strucuture. No output. (asserted)
597 * @retval VERR_BUFFER_OVERFLOW there are more components in the path than
598 * there is space in aComps. The required amount of space can be
599 * determined from the pParsed->cComps:
600 * @code
601 * RT_OFFSETOF(RTPATHPARSED, aComps[pParsed->cComps])
602 * @endcode
603 * @retval VERR_PATH_ZERO_LENGTH if the path is empty.
604 *
605 * @param pszPath The path to parse.
606 * @param pParsed Where to store the details of the parsed path.
607 * @param cbParsed The size of the buffer. Must be at least the
608 * size of RTPATHPARSED.
609 * @param fFlags Combination of RTPATH_STR_F_XXX flags.
610 * Most users will pass 0.
611 * @sa RTPathSplit, RTPathSplitA.
612 */
613RTDECL(int) RTPathParse(const char *pszPath, PRTPATHPARSED pParsed, size_t cbParsed, uint32_t fFlags);
614
615/**
616 * Output buffer for RTPathSplit and RTPathSplitA.
617 */
618typedef struct RTPATHSPLIT
619{
620 /** Number of path components.
621 * This will always be set on VERR_BUFFER_OVERFLOW returns from RTPathParsed
622 * so the caller can calculate the required buffer size. */
623 uint16_t cComps;
624 /** Path property flags, RTPATH_PROP_XXX */
625 uint16_t fProps;
626 /** On success this is the length of the described path, i.e. sum of all
627 * component lengths and necessary separators.
628 * Do NOT use this to index in the source path in case it contains
629 * unnecessary slashes that RTPathSplit has ignored here. */
630 uint16_t cchPath;
631 /** Reserved (internal use). */
632 uint16_t u16Reserved;
633 /** The amount of memory used (on success) or required (on
634 * VERR_BUFFER_OVERFLOW) of this structure and it's strings. */
635 uint32_t cbNeeded;
636 /** Pointer to the filename suffix (the dot), if any. Points to the NUL
637 * character of the last component if none or if RTPATH_PROP_DIR_SLASH is
638 * present. */
639 const char *pszSuffix;
640 /** Array of component strings (variable size). */
641 char *apszComps[1];
642} RTPATHSPLIT;
643/** Pointer to a split path buffer. */
644typedef RTPATHSPLIT *PRTPATHSPLIT;
645/** Pointer to a const split path buffer. */
646typedef RTPATHSPLIT const *PCRTPATHSPLIT;
647
648/**
649 * Splits the path into individual component strings, carved from user supplied
650 * the given buffer block.
651 *
652 * @returns IPRT status code.
653 * @retval VERR_INVALID_POINTER if pParsed or pszPath is an invalid pointer.
654 * @retval VERR_INVALID_PARAMETER if cbOutput is less than the RTPATHSPLIT
655 * strucuture. No output. (asserted)
656 * @retval VERR_BUFFER_OVERFLOW there are more components in the path than
657 * there is space in aComps. The required amount of space can be
658 * determined from the pParsed->cComps:
659 * @code
660 * RT_OFFSETOF(RTPATHPARSED, aComps[pParsed->cComps])
661 * @endcode
662 * @retval VERR_PATH_ZERO_LENGTH if the path is empty.
663 * @retval VERR_FILENAME_TOO_LONG if the filename is too long (close to 64 KB).
664 *
665 * @param pszPath The path to parse.
666 * @param pSplit Where to store the details of the parsed path.
667 * @param cbSplit The size of the buffer pointed to by @a pSplit
668 * (variable sized array at the end). Must be at
669 * least the size of RTPATHSPLIT.
670 * @param fFlags Combination of RTPATH_STR_F_XXX flags.
671 * Most users will pass 0.
672 *
673 * @sa RTPathSplitA, RTPathParse.
674 */
675RTDECL(int) RTPathSplit(const char *pszPath, PRTPATHSPLIT pSplit, size_t cbSplit, uint32_t fFlags);
676
677/**
678 * Splits the path into individual component strings, allocating the buffer on
679 * the default thread heap.
680 *
681 * @returns IPRT status code.
682 * @retval VERR_INVALID_POINTER if pParsed or pszPath is an invalid pointer.
683 * @retval VERR_PATH_ZERO_LENGTH if the path is empty.
684 *
685 * @param pszPath The path to parse.
686 * @param ppSplit Where to return the pointer to the output on
687 * success. This must be freed by calling
688 * RTPathSplitFree().
689 * @param fFlags Combination of RTPATH_STR_F_XXX flags.
690 * Most users will pass 0.
691 * @sa RTPathSplitFree, RTPathSplit, RTPathParse.
692 */
693#define RTPathSplitA(pszPath, ppSplit, fFlags) RTPathSplitATag(pszPath, ppSplit, fFlags, RTPATH_TAG)
694
695/**
696 * Splits the path into individual component strings, allocating the buffer on
697 * the default thread heap.
698 *
699 * @returns IPRT status code.
700 * @retval VERR_INVALID_POINTER if pParsed or pszPath is an invalid pointer.
701 * @retval VERR_PATH_ZERO_LENGTH if the path is empty.
702 *
703 * @param pszPath The path to parse.
704 * @param ppSplit Where to return the pointer to the output on
705 * success. This must be freed by calling
706 * RTPathSplitFree().
707 * @param fFlags Combination of RTPATH_STR_F_XXX flags.
708 * Most users will pass 0.
709 * @param pszTag Allocation tag used for statistics and such.
710 * @sa RTPathSplitFree, RTPathSplit, RTPathParse.
711 */
712RTDECL(int) RTPathSplitATag(const char *pszPath, PRTPATHSPLIT *ppSplit, uint32_t fFlags, const char *pszTag);
713
714/**
715 * Frees buffer returned by RTPathSplitA.
716 *
717 * @param pSplit What RTPathSplitA returned.
718 * @sa RTPathSplitA
719 */
720RTDECL(void) RTPathSplitFree(PRTPATHSPLIT pSplit);
721
722
723/**
724 * Compares two paths.
725 *
726 * The comparison takes platform-dependent details into account,
727 * such as:
728 * <ul>
729 * <li>On DOS-like platforms, both separator chars (|\| and |/|) are considered
730 * to be equal.
731 * <li>On platforms with case-insensitive file systems, mismatching characters
732 * are uppercased and compared again.
733 * </ul>
734 *
735 * @returns @< 0 if the first path less than the second path.
736 * @returns 0 if the first path identical to the second path.
737 * @returns @> 0 if the first path greater than the second path.
738 *
739 * @param pszPath1 Path to compare (must be an absolute path).
740 * @param pszPath2 Path to compare (must be an absolute path).
741 *
742 * @remarks File system details are currently ignored. This means that you won't
743 * get case-insensitive compares on unix systems when a path goes into a
744 * case-insensitive filesystem like FAT, HPFS, HFS, NTFS, JFS, or
745 * similar. For NT, OS/2 and similar you'll won't get case-sensitive
746 * compares on a case-sensitive file system.
747 */
748RTDECL(int) RTPathCompare(const char *pszPath1, const char *pszPath2);
749
750/**
751 * Checks if a path starts with the given parent path.
752 *
753 * This means that either the path and the parent path matches completely, or
754 * that the path is to some file or directory residing in the tree given by the
755 * parent directory.
756 *
757 * The path comparison takes platform-dependent details into account,
758 * see RTPathCompare() for details.
759 *
760 * @returns |true| when \a pszPath starts with \a pszParentPath (or when they
761 * are identical), or |false| otherwise.
762 *
763 * @param pszPath Path to check, must be an absolute path.
764 * @param pszParentPath Parent path, must be an absolute path.
765 * No trailing directory slash!
766 *
767 * @remarks This API doesn't currently handle root directory compares in a
768 * manner consistent with the other APIs. RTPathStartsWith(pszSomePath,
769 * "/") will not work if pszSomePath isn't "/".
770 */
771RTDECL(bool) RTPathStartsWith(const char *pszPath, const char *pszParentPath);
772
773/**
774 * Appends one partial path to another.
775 *
776 * The main purpose of this function is to deal correctly with the slashes when
777 * concatenating the two partial paths.
778 *
779 * @retval VINF_SUCCESS on success.
780 * @retval VERR_BUFFER_OVERFLOW if the result is too big to fit within
781 * cbPathDst bytes. No changes has been made.
782 * @retval VERR_INVALID_PARAMETER if the string pointed to by pszPath is longer
783 * than cbPathDst-1 bytes (failed to find terminator). Asserted.
784 *
785 * @param pszPath The path to append pszAppend to. This serves as both
786 * input and output. This can be empty, in which case
787 * pszAppend is just copied over.
788 * @param cbPathDst The size of the buffer pszPath points to, terminator
789 * included. This should NOT be strlen(pszPath).
790 * @param pszAppend The partial path to append to pszPath. This can be
791 * NULL, in which case nothing is done.
792 *
793 * @remarks See the RTPathAppendEx remarks.
794 */
795RTDECL(int) RTPathAppend(char *pszPath, size_t cbPathDst, const char *pszAppend);
796
797/**
798 * Appends one partial path to another.
799 *
800 * The main purpose of this function is to deal correctly with the slashes when
801 * concatenating the two partial paths.
802 *
803 * @retval VINF_SUCCESS on success.
804 * @retval VERR_BUFFER_OVERFLOW if the result is too big to fit within
805 * cbPathDst bytes. No changes has been made.
806 * @retval VERR_INVALID_PARAMETER if the string pointed to by pszPath is longer
807 * than cbPathDst-1 bytes (failed to find terminator). Asserted.
808 *
809 * @param pszPath The path to append pszAppend to. This serves as both
810 * input and output. This can be empty, in which case
811 * pszAppend is just copied over.
812 * @param cbPathDst The size of the buffer pszPath points to, terminator
813 * included. This should NOT be strlen(pszPath).
814 * @param pszAppend The partial path to append to pszPath. This can be
815 * NULL, in which case nothing is done.
816 * @param cchAppendMax The maximum number or characters to take from @a
817 * pszAppend. RTSTR_MAX is fine.
818 *
819 * @remarks On OS/2, Window and similar systems, concatenating a drive letter
820 * specifier with a slash prefixed path will result in an absolute
821 * path. Meaning, RTPathAppend(strcpy(szBuf, "C:"), sizeof(szBuf),
822 * "/bar") will result in "C:/bar". (This follows directly from the
823 * behavior when pszPath is empty.)
824 *
825 * On the other hand, when joining a drive letter specifier with a
826 * partial path that does not start with a slash, the result is not an
827 * absolute path. Meaning, RTPathAppend(strcpy(szBuf, "C:"),
828 * sizeof(szBuf), "bar") will result in "C:bar".
829 */
830RTDECL(int) RTPathAppendEx(char *pszPath, size_t cbPathDst, const char *pszAppend, size_t cchAppendMax);
831
832/**
833 * Like RTPathAppend, but with the base path as a separate argument instead of
834 * in the path buffer.
835 *
836 * @retval VINF_SUCCESS on success.
837 * @retval VERR_BUFFER_OVERFLOW if the result is too big to fit within
838 * cbPathDst bytes.
839 * @retval VERR_INVALID_PARAMETER if the string pointed to by pszPath is longer
840 * than cbPathDst-1 bytes (failed to find terminator). Asserted.
841 *
842 * @param pszPathDst Where to store the resulting path.
843 * @param cbPathDst The size of the buffer pszPathDst points to,
844 * terminator included.
845 * @param pszPathSrc The base path to copy into @a pszPathDst before
846 * appending @a pszAppend.
847 * @param pszAppend The partial path to append to pszPathSrc. This can
848 * be NULL, in which case nothing is done.
849 *
850 */
851RTDECL(int) RTPathJoin(char *pszPathDst, size_t cbPathDst, const char *pszPathSrc,
852 const char *pszAppend);
853
854/**
855 * Same as RTPathJoin, except that the output buffer is allocated.
856 *
857 * @returns Buffer containing the joined up path, call RTStrFree to free. NULL
858 * on allocation failure.
859 * @param pszPathSrc The base path to copy into @a pszPathDst before
860 * appending @a pszAppend.
861 * @param pszAppend The partial path to append to pszPathSrc. This can
862 * be NULL, in which case nothing is done.
863 *
864 */
865RTDECL(char *) RTPathJoinA(const char *pszPathSrc, const char *pszAppend);
866
867/**
868 * Extended version of RTPathJoin, both inputs can be specified as substrings.
869 *
870 * @retval VINF_SUCCESS on success.
871 * @retval VERR_BUFFER_OVERFLOW if the result is too big to fit within
872 * cbPathDst bytes.
873 * @retval VERR_INVALID_PARAMETER if the string pointed to by pszPath is longer
874 * than cbPathDst-1 bytes (failed to find terminator). Asserted.
875 *
876 * @param pszPathDst Where to store the resulting path.
877 * @param cbPathDst The size of the buffer pszPathDst points to,
878 * terminator included.
879 * @param pszPathSrc The base path to copy into @a pszPathDst before
880 * appending @a pszAppend.
881 * @param cchPathSrcMax The maximum number of bytes to copy from @a
882 * pszPathSrc. RTSTR_MAX is find.
883 * @param pszAppend The partial path to append to pszPathSrc. This can
884 * be NULL, in which case nothing is done.
885 * @param cchAppendMax The maximum number of bytes to copy from @a
886 * pszAppend. RTSTR_MAX is find.
887 *
888 */
889RTDECL(int) RTPathJoinEx(char *pszPathDst, size_t cbPathDst,
890 const char *pszPathSrc, size_t cchPathSrcMax,
891 const char *pszAppend, size_t cchAppendMax);
892
893/**
894 * Callback for RTPathTraverseList that's called for each element.
895 *
896 * @returns IPRT style status code. Return VERR_TRY_AGAIN to continue, any other
897 * value will abort the traversing and be returned to the caller.
898 *
899 * @param pchPath Pointer to the start of the current path. This is
900 * not null terminated.
901 * @param cchPath The length of the path.
902 * @param pvUser1 The first user parameter.
903 * @param pvUser2 The second user parameter.
904 */
905typedef DECLCALLBACK(int) FNRTPATHTRAVERSER(char const *pchPath, size_t cchPath, void *pvUser1, void *pvUser2);
906/** Pointer to a FNRTPATHTRAVERSER. */
907typedef FNRTPATHTRAVERSER *PFNRTPATHTRAVERSER;
908
909/**
910 * Traverses a string that can contain multiple paths separated by a special
911 * character.
912 *
913 * @returns IPRT style status code from the callback or VERR_END_OF_STRING if
914 * the callback returned VERR_TRY_AGAIN for all paths in the string.
915 *
916 * @param pszPathList The string to traverse.
917 * @param chSep The separator character. Using the null terminator
918 * is fine, but the result will simply be that there
919 * will only be one callback for the entire string
920 * (save any leading white space).
921 * @param pfnCallback The callback.
922 * @param pvUser1 First user argument for the callback.
923 * @param pvUser2 Second user argument for the callback.
924 */
925RTDECL(int) RTPathTraverseList(const char *pszPathList, char chSep, PFNRTPATHTRAVERSER pfnCallback, void *pvUser1, void *pvUser2);
926
927
928/**
929 * Calculate a relative path between the two given paths.
930 *
931 * @returns IPRT status code.
932 * @retval VINF_SUCCESS on success.
933 * @retval VERR_BUFFER_OVERFLOW if the result is too big to fit within
934 * cbPathDst bytes.
935 * @retval VERR_NOT_SUPPORTED if both paths start with different volume specifiers.
936 * @param pszPathDst Where to store the resulting path.
937 * @param cbPathDst The size of the buffer pszPathDst points to,
938 * terminator included.
939 * @param pszPathFrom The path to start from creating the relative path.
940 * @param pszPathTo The path to reach with the created relative path.
941 */
942RTDECL(int) RTPathCalcRelative(char *pszPathDst, size_t cbPathDst,
943 const char *pszPathFrom,
944 const char *pszPathTo);
945
946#ifdef IN_RING3
947
948/**
949 * Gets the path to the directory containing the executable.
950 *
951 * @returns iprt status code.
952 * @param pszPath Buffer where to store the path.
953 * @param cchPath Buffer size in bytes.
954 */
955RTDECL(int) RTPathExecDir(char *pszPath, size_t cchPath);
956
957/**
958 * Gets the user home directory.
959 *
960 * @returns iprt status code.
961 * @param pszPath Buffer where to store the path.
962 * @param cchPath Buffer size in bytes.
963 */
964RTDECL(int) RTPathUserHome(char *pszPath, size_t cchPath);
965
966/**
967 * Gets the user documents directory.
968 *
969 * The returned path isn't guaranteed to exist.
970 *
971 * @returns iprt status code.
972 * @param pszPath Buffer where to store the path.
973 * @param cchPath Buffer size in bytes.
974 */
975RTDECL(int) RTPathUserDocuments(char *pszPath, size_t cchPath);
976
977/**
978 * Gets the directory of shared libraries.
979 *
980 * This is not the same as RTPathAppPrivateArch() as Linux depends all shared
981 * libraries in a common global directory where ld.so can find them.
982 *
983 * Linux: /usr/lib
984 * Solaris: /opt/@<application@>/@<arch>@ or something
985 * Windows: @<program files directory@>/@<application@>
986 * Old path: same as RTPathExecDir()
987 *
988 * @returns iprt status code.
989 * @param pszPath Buffer where to store the path.
990 * @param cchPath Buffer size in bytes.
991 */
992RTDECL(int) RTPathSharedLibs(char *pszPath, size_t cchPath);
993
994/**
995 * Gets the directory for architecture-independent application data, for
996 * example NLS files, module sources, ...
997 *
998 * Linux: /usr/shared/@<application@>
999 * Solaris: /opt/@<application@>
1000 * Windows: @<program files directory@>/@<application@>
1001 * Old path: same as RTPathExecDir()
1002 *
1003 * @returns iprt status code.
1004 * @param pszPath Buffer where to store the path.
1005 * @param cchPath Buffer size in bytes.
1006 */
1007RTDECL(int) RTPathAppPrivateNoArch(char *pszPath, size_t cchPath);
1008
1009/**
1010 * Gets the directory for architecture-dependent application data, for
1011 * example modules which can be loaded at runtime.
1012 *
1013 * Linux: /usr/lib/@<application@>
1014 * Solaris: /opt/@<application@>/@<arch>@ or something
1015 * Windows: @<program files directory@>/@<application@>
1016 * Old path: same as RTPathExecDir()
1017 *
1018 * @returns iprt status code.
1019 * @param pszPath Buffer where to store the path.
1020 * @param cchPath Buffer size in bytes.
1021 */
1022RTDECL(int) RTPathAppPrivateArch(char *pszPath, size_t cchPath);
1023
1024/**
1025 * Gets the toplevel directory for architecture-dependent application data.
1026 *
1027 * This differs from RTPathAppPrivateArch on Solaris only where it will work
1028 * around the /opt/@<application@>/amd64 and /opt/@<application@>/i386 multi
1029 * architecture installation style.
1030 *
1031 * Linux: /usr/lib/@<application@>
1032 * Solaris: /opt/@<application@>
1033 * Windows: @<program files directory@>/@<application@>
1034 * Old path: same as RTPathExecDir()
1035 *
1036 * @returns iprt status code.
1037 * @param pszPath Buffer where to store the path.
1038 * @param cchPath Buffer size in bytes.
1039 */
1040RTDECL(int) RTPathAppPrivateArchTop(char *pszPath, size_t cchPath);
1041
1042/**
1043 * Gets the directory for documentation.
1044 *
1045 * Linux: /usr/share/doc/@<application@>
1046 * Solaris: /opt/@<application@>
1047 * Windows: @<program files directory@>/@<application@>
1048 * Old path: same as RTPathExecDir()
1049 *
1050 * @returns iprt status code.
1051 * @param pszPath Buffer where to store the path.
1052 * @param cchPath Buffer size in bytes.
1053 */
1054RTDECL(int) RTPathAppDocs(char *pszPath, size_t cchPath);
1055
1056/**
1057 * Gets the temporary directory path.
1058 *
1059 * @returns iprt status code.
1060 * @param pszPath Buffer where to store the path.
1061 * @param cchPath Buffer size in bytes.
1062 */
1063RTDECL(int) RTPathTemp(char *pszPath, size_t cchPath);
1064
1065/**
1066 * Query information about a file system object.
1067 *
1068 * This API will resolve NOT symbolic links in the last component (just like
1069 * unix lstat()).
1070 *
1071 * @returns IPRT status code.
1072 * @retval VINF_SUCCESS if the object exists, information returned.
1073 * @retval VERR_PATH_NOT_FOUND if any but the last component in the specified
1074 * path was not found or was not a directory.
1075 * @retval VERR_FILE_NOT_FOUND if the object does not exist (but path to the
1076 * parent directory exists).
1077 *
1078 * @param pszPath Path to the file system object.
1079 * @param pObjInfo Object information structure to be filled on successful
1080 * return.
1081 * @param enmAdditionalAttribs
1082 * Which set of additional attributes to request.
1083 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
1084 */
1085RTR3DECL(int) RTPathQueryInfo(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs);
1086
1087/**
1088 * Query information about a file system object.
1089 *
1090 * @returns IPRT status code.
1091 * @retval VINF_SUCCESS if the object exists, information returned.
1092 * @retval VERR_PATH_NOT_FOUND if any but the last component in the specified
1093 * path was not found or was not a directory.
1094 * @retval VERR_FILE_NOT_FOUND if the object does not exist (but path to the
1095 * parent directory exists).
1096 *
1097 * @param pszPath Path to the file system object.
1098 * @param pObjInfo Object information structure to be filled on successful return.
1099 * @param enmAdditionalAttribs
1100 * Which set of additional attributes to request.
1101 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
1102 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
1103 */
1104RTR3DECL(int) RTPathQueryInfoEx(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags);
1105
1106/**
1107 * Changes the mode flags of a file system object.
1108 *
1109 * The API requires at least one of the mode flag sets (Unix/Dos) to
1110 * be set. The type is ignored.
1111 *
1112 * This API will resolve symbolic links in the last component since
1113 * mode isn't important for symbolic links.
1114 *
1115 * @returns iprt status code.
1116 * @param pszPath Path to the file system object.
1117 * @param fMode The new file mode, see @ref grp_rt_fs for details.
1118 */
1119RTR3DECL(int) RTPathSetMode(const char *pszPath, RTFMODE fMode);
1120
1121/**
1122 * Gets the mode flags of a file system object.
1123 *
1124 * @returns iprt status code.
1125 * @param pszPath Path to the file system object.
1126 * @param pfMode Where to store the file mode, see @ref grp_rt_fs for details.
1127 *
1128 * @remark This is wrapper around RTPathQueryInfoEx(RTPATH_F_FOLLOW_LINK) and
1129 * exists to complement RTPathSetMode().
1130 */
1131RTR3DECL(int) RTPathGetMode(const char *pszPath, PRTFMODE pfMode);
1132
1133/**
1134 * Changes one or more of the timestamps associated of file system object.
1135 *
1136 * This API will not resolve symbolic links in the last component (just
1137 * like unix lutimes()).
1138 *
1139 * @returns iprt status code.
1140 * @param pszPath Path to the file system object.
1141 * @param pAccessTime Pointer to the new access time.
1142 * @param pModificationTime Pointer to the new modification time.
1143 * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
1144 * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
1145 *
1146 * @remark The file system might not implement all these time attributes,
1147 * the API will ignore the ones which aren't supported.
1148 *
1149 * @remark The file system might not implement the time resolution
1150 * employed by this interface, the time will be chopped to fit.
1151 *
1152 * @remark The file system may update the change time even if it's
1153 * not specified.
1154 *
1155 * @remark POSIX can only set Access & Modification and will always set both.
1156 */
1157RTR3DECL(int) RTPathSetTimes(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
1158 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
1159
1160/**
1161 * Changes one or more of the timestamps associated of file system object.
1162 *
1163 * @returns iprt status code.
1164 * @param pszPath Path to the file system object.
1165 * @param pAccessTime Pointer to the new access time.
1166 * @param pModificationTime Pointer to the new modification time.
1167 * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
1168 * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
1169 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
1170 *
1171 * @remark The file system might not implement all these time attributes,
1172 * the API will ignore the ones which aren't supported.
1173 *
1174 * @remark The file system might not implement the time resolution
1175 * employed by this interface, the time will be chopped to fit.
1176 *
1177 * @remark The file system may update the change time even if it's
1178 * not specified.
1179 *
1180 * @remark POSIX can only set Access & Modification and will always set both.
1181 */
1182RTR3DECL(int) RTPathSetTimesEx(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
1183 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime, uint32_t fFlags);
1184
1185/**
1186 * Gets one or more of the timestamps associated of file system object.
1187 *
1188 * @returns iprt status code.
1189 * @param pszPath Path to the file system object.
1190 * @param pAccessTime Where to store the access time. NULL is ok.
1191 * @param pModificationTime Where to store the modification time. NULL is ok.
1192 * @param pChangeTime Where to store the change time. NULL is ok.
1193 * @param pBirthTime Where to store the creation time. NULL is ok.
1194 *
1195 * @remark This is wrapper around RTPathQueryInfo() and exists to complement
1196 * RTPathSetTimes(). If the last component is a symbolic link, it will
1197 * not be resolved.
1198 */
1199RTR3DECL(int) RTPathGetTimes(const char *pszPath, PRTTIMESPEC pAccessTime, PRTTIMESPEC pModificationTime,
1200 PRTTIMESPEC pChangeTime, PRTTIMESPEC pBirthTime);
1201
1202/**
1203 * Changes the owner and/or group of a file system object.
1204 *
1205 * This API will not resolve symbolic links in the last component (just
1206 * like unix lchown()).
1207 *
1208 * @returns iprt status code.
1209 * @param pszPath Path to the file system object.
1210 * @param uid The new file owner user id. Pass NIL_RTUID to leave
1211 * this unchanged.
1212 * @param gid The new group id. Pass NIL_RTGUID to leave this
1213 * unchanged.
1214 */
1215RTR3DECL(int) RTPathSetOwner(const char *pszPath, uint32_t uid, uint32_t gid);
1216
1217/**
1218 * Changes the owner and/or group of a file system object.
1219 *
1220 * @returns iprt status code.
1221 * @param pszPath Path to the file system object.
1222 * @param uid The new file owner user id. Pass NIL_RTUID to leave
1223 * this unchanged.
1224 * @param gid The new group id. Pass NIL_RTGID to leave this
1225 * unchanged.
1226 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
1227 */
1228RTR3DECL(int) RTPathSetOwnerEx(const char *pszPath, uint32_t uid, uint32_t gid, uint32_t fFlags);
1229
1230/**
1231 * Gets the owner and/or group of a file system object.
1232 *
1233 * @returns iprt status code.
1234 * @param pszPath Path to the file system object.
1235 * @param pUid Where to store the owner user id. NULL is ok.
1236 * @param pGid Where to store the group id. NULL is ok.
1237 *
1238 * @remark This is wrapper around RTPathQueryInfo() and exists to complement
1239 * RTPathGetOwner(). If the last component is a symbolic link, it will
1240 * not be resolved.
1241 */
1242RTR3DECL(int) RTPathGetOwner(const char *pszPath, uint32_t *pUid, uint32_t *pGid);
1243
1244
1245/** @name RTPathRename, RTDirRename & RTFileRename flags.
1246 * @{ */
1247/** Do not replace anything. */
1248#define RTPATHRENAME_FLAGS_NO_REPLACE UINT32_C(0)
1249/** This will replace attempt any target which isn't a directory. */
1250#define RTPATHRENAME_FLAGS_REPLACE RT_BIT(0)
1251/** Don't allow symbolic links as part of the path.
1252 * @remarks this flag is currently not implemented and will be ignored. */
1253#define RTPATHRENAME_FLAGS_NO_SYMLINKS RT_BIT(1)
1254/** @} */
1255
1256/**
1257 * Renames a path within a filesystem.
1258 *
1259 * This will rename symbolic links. If RTPATHRENAME_FLAGS_REPLACE is used and
1260 * pszDst is a symbolic link, it will be replaced and not its target.
1261 *
1262 * @returns IPRT status code.
1263 * @param pszSrc The source path.
1264 * @param pszDst The destination path.
1265 * @param fRename Rename flags, RTPATHRENAME_FLAGS_*.
1266 */
1267RTR3DECL(int) RTPathRename(const char *pszSrc, const char *pszDst, unsigned fRename);
1268
1269/** @name RTPathUnlink flags.
1270 * @{ */
1271/** Don't allow symbolic links as part of the path.
1272 * @remarks this flag is currently not implemented and will be ignored. */
1273#define RTPATHUNLINK_FLAGS_NO_SYMLINKS RT_BIT(0)
1274/** @} */
1275
1276/**
1277 * Removes the last component of the path.
1278 *
1279 * @returns IPRT status code.
1280 * @param pszPath The path.
1281 * @param fUnlink Unlink flags, RTPATHUNLINK_FLAGS_*.
1282 */
1283RTR3DECL(int) RTPathUnlink(const char *pszPath, uint32_t fUnlink);
1284
1285/**
1286 * A /bin/rm tool.
1287 *
1288 * @returns Program exit code.
1289 *
1290 * @param cArgs The number of arguments.
1291 * @param papszArgs The argument vector. (Note that this may be
1292 * reordered, so the memory must be writable.)
1293 */
1294RTDECL(RTEXITCODE) RTPathRmCmd(unsigned cArgs, char **papszArgs);
1295
1296#endif /* IN_RING3 */
1297
1298/** @} */
1299
1300RT_C_DECLS_END
1301
1302#endif
1303
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette