VirtualBox

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

Last change on this file since 69844 was 69818, checked in by vboxsync, 7 years ago

IPRT/VFS: Got rid of the pfnTraversalOpen method.

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