VirtualBox

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

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

IPRT: Changed the RTPATHPARSE_FLAGS_ into generic ones as they will be shared with RTPathSplit*. Introduced a new character called RTPATH_STYLE with can have two values (currently) RTPATH_STR_F_STYLE_DOS or RTPATH_STR_F_STYLE_UNIX. Some other minor adjustments.

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