VirtualBox

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

Last change on this file since 74653 was 74460, checked in by vboxsync, 6 years ago

IPRT: Implemented long filename support for windows (except for LoadLibrary). bugref:9248

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