VirtualBox

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

Last change on this file since 56533 was 56291, checked in by vboxsync, 9 years ago

include: Updated (C) year.

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

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