VirtualBox

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

Last change on this file since 33802 was 33802, checked in by vboxsync, 14 years ago

iprt/path.h: Added RTPATHRENAME_FLAGS_NO_REPLACE to make RT[Path|Dir|File]Rename easier to read.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.7 KB
Line 
1/** @file
2 * IPRT - Path Manipulation.
3 */
4
5/*
6 * Copyright (C) 2006-2007 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/** @def RTPATH_SLASH
46 * The preferred slash character.
47 *
48 * @remark IPRT will always accept unix slashes. So, normally you would
49 * never have to use this define.
50 */
51#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
52# define RTPATH_SLASH '\\'
53#else
54# define RTPATH_SLASH '/'
55#endif
56
57/** @deprecated Use '/'! */
58#define RTPATH_DELIMITER RTPATH_SLASH
59
60
61/** @def RTPATH_SLASH_STR
62 * The preferred slash character as a string, handy for concatenations
63 * with other strings.
64 *
65 * @remark IPRT will always accept unix slashes. So, normally you would
66 * never have to use this define.
67 */
68#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
69# define RTPATH_SLASH_STR "\\"
70#else
71# define RTPATH_SLASH_STR "/"
72#endif
73
74
75/** @def RTPATH_IS_SLASH
76 * Checks if a character is a slash.
77 *
78 * @returns true if it's a slash and false if not.
79 * @returns @param ch Char to check.
80 */
81#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
82# define RTPATH_IS_SLASH(ch) ( (ch) == '\\' || (ch) == '/' )
83#else
84# define RTPATH_IS_SLASH(ch) ( (ch) == '/' )
85#endif
86
87
88/** @def RTPATH_IS_VOLSEP
89 * Checks if a character marks the end of the volume specification.
90 *
91 * @remark This is sufficient for the drive letter concept on PC.
92 * However it might be insufficient on other platforms
93 * and even on PC a UNC volume spec won't be detected this way.
94 * Use the RTPath@<too be created@>() instead.
95 *
96 * @returns true if it is and false if it isn't.
97 * @returns @param ch Char to check.
98 */
99#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
100# define RTPATH_IS_VOLSEP(ch) ( (ch) == ':' )
101#else
102# define RTPATH_IS_VOLSEP(ch) (false)
103#endif
104
105
106/** @def RTPATH_IS_SEP
107 * Checks if a character is path component separator
108 *
109 * @returns true if it is and false if it isn't.
110 * @returns @param ch Char to check.
111 * @
112 */
113#define RTPATH_IS_SEP(ch) ( RTPATH_IS_SLASH(ch) || RTPATH_IS_VOLSEP(ch) )
114
115
116/** @name Generic RTPath flags
117 * @{ */
118/** Last component: Work on the link. */
119#define RTPATH_F_ON_LINK RT_BIT_32(0)
120/** Last component: Follow if link. */
121#define RTPATH_F_FOLLOW_LINK RT_BIT_32(1)
122/** @} */
123
124
125/** Validates a flags parameter containing RTPATH_F_*.
126 * @remarks The parameters will be referenced multiple times. */
127#define RTPATH_F_IS_VALID(fFlags, fIgnore) \
128 ( ((fFlags) & ~(uint32_t)(fIgnore)) == RTPATH_F_ON_LINK \
129 || ((fFlags) & ~(uint32_t)(fIgnore)) == RTPATH_F_FOLLOW_LINK )
130
131
132/**
133 * Checks if the path exists.
134 *
135 * Symbolic links will all be attempted resolved and broken links means false.
136 *
137 * @returns true if it exists and false if it doesn't.
138 * @param pszPath The path to check.
139 */
140RTDECL(bool) RTPathExists(const char *pszPath);
141
142/**
143 * Checks if the path exists.
144 *
145 * @returns true if it exists and false if it doesn't.
146 * @param pszPath The path to check.
147 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
148 */
149RTDECL(bool) RTPathExistsEx(const char *pszPath, uint32_t fFlags);
150
151/**
152 * Sets the current working directory of the process.
153 *
154 * @returns IPRT status code.
155 * @param pszPath The path to the new working directory.
156 */
157RTDECL(int) RTPathSetCurrent(const char *pszPath);
158
159/**
160 * Gets the current working directory of the process.
161 *
162 * @returns IPRT status code.
163 * @param pszPath Where to store the path.
164 * @param cchPath The size of the buffer pszPath points to.
165 */
166RTDECL(int) RTPathGetCurrent(char *pszPath, size_t cchPath);
167
168/**
169 * Get the real path (no symlinks, no . or .. components), must exist.
170 *
171 * @returns iprt status code.
172 * @param pszPath The path to resolve.
173 * @param pszRealPath Where to store the real path.
174 * @param cchRealPath Size of the buffer.
175 */
176RTDECL(int) RTPathReal(const char *pszPath, char *pszRealPath, size_t cchRealPath);
177
178/**
179 * Same as RTPathReal only the result is RTStrDup()'ed.
180 *
181 * @returns Pointer to real path. Use RTStrFree() to free this string.
182 * @returns NULL if RTPathReal() or RTStrDup() fails.
183 * @param pszPath The path to resolve.
184 */
185RTDECL(char *) RTPathRealDup(const char *pszPath);
186
187/**
188 * Get the absolute path (starts from root, no . or .. components), doesn't have
189 * to exist. Note that this method is designed to never perform actual file
190 * system access, therefore symlinks are not resolved.
191 *
192 * @returns iprt status code.
193 * @param pszPath The path to resolve.
194 * @param pszAbsPath Where to store the absolute path.
195 * @param cchAbsPath Size of the buffer.
196 */
197RTDECL(int) RTPathAbs(const char *pszPath, char *pszAbsPath, size_t cchAbsPath);
198
199/**
200 * Same as RTPathAbs only the result is RTStrDup()'ed.
201 *
202 * @returns Pointer to the absolute path. Use RTStrFree() to free this string.
203 * @returns NULL if RTPathAbs() or RTStrDup() fails.
204 * @param pszPath The path to resolve.
205 */
206RTDECL(char *) RTPathAbsDup(const char *pszPath);
207
208/**
209 * Get the absolute path (no symlinks, no . or .. components), assuming the
210 * given base path as the current directory. The resulting path doesn't have
211 * to exist.
212 *
213 * @returns iprt status code.
214 * @param pszBase The base path to act like a current directory.
215 * When NULL, the actual cwd is used (i.e. the call
216 * is equivalent to RTPathAbs(pszPath, ...).
217 * @param pszPath The path to resolve.
218 * @param pszAbsPath Where to store the absolute path.
219 * @param cchAbsPath Size of the buffer.
220 */
221RTDECL(int) RTPathAbsEx(const char *pszBase, const char *pszPath, char *pszAbsPath, size_t cchAbsPath);
222
223/**
224 * Same as RTPathAbsEx only the result is RTStrDup()'ed.
225 *
226 * @returns Pointer to the absolute path. Use RTStrFree() to free this string.
227 * @returns NULL if RTPathAbsEx() or RTStrDup() fails.
228 * @param pszBase The base path to act like a current directory.
229 * When NULL, the actual cwd is used (i.e. the call
230 * is equivalent to RTPathAbs(pszPath, ...).
231 * @param pszPath The path to resolve.
232 */
233RTDECL(char *) RTPathAbsExDup(const char *pszBase, const char *pszPath);
234
235/**
236 * Strips the filename from a path. Truncates the given string in-place by overwriting the
237 * last path separator character with a null byte in a platform-neutral way.
238 *
239 * @param pszPath Path from which filename should be extracted, will be truncated.
240 * If the string contains no path separator, it will be changed to a "." string.
241 */
242RTDECL(void) RTPathStripFilename(char *pszPath);
243
244/**
245 * Strips the extension from a path.
246 *
247 * @param pszPath Path which extension should be stripped.
248 */
249RTDECL(void) RTPathStripExt(char *pszPath);
250
251/**
252 * Strips the trailing slashes of a path name.
253 *
254 * Won't strip root slashes.
255 *
256 * @returns The new length of pszPath.
257 * @param pszPath Path to strip.
258 */
259RTDECL(size_t) RTPathStripTrailingSlash(char *pszPath);
260
261/**
262 * Changes all the slashes in the specified path to DOS style.
263 *
264 * Unless @a fForce is set, nothing will be done when on a UNIX flavored system
265 * since paths wont work with DOS style slashes there.
266 *
267 * @returns @a pszPath.
268 * @param pszPath The path to modify.
269 * @param fForce Whether to force the conversion on non-DOS OSes.
270 */
271RTDECL(char *) RTPathChangeToDosSlashes(char *pszPath, bool fForce);
272
273/**
274 * Changes all the slashes in the specified path to unix style.
275 *
276 * Unless @a fForce is set, nothing will be done when on a UNIX flavored system
277 * since paths wont work with DOS style slashes there.
278 *
279 * @returns @a pszPath.
280 * @param pszPath The path to modify.
281 * @param fForce Whether to force the conversion on non-DOS OSes.
282 */
283RTDECL(char *) RTPathChangeToUnixSlashes(char *pszPath, bool fForce);
284
285/**
286 * Parses a path.
287 *
288 * It figures the length of the directory component, the offset of
289 * the file name and the location of the suffix dot.
290 *
291 * @returns The path length.
292 *
293 * @param pszPath Path to find filename in.
294 * @param pcchDir Where to put the length of the directory component. If
295 * no directory, this will be 0. Optional.
296 * @param poffName Where to store the filename offset.
297 * If empty string or if it's ending with a slash this
298 * will be set to -1. Optional.
299 * @param poffSuff Where to store the suffix offset (the last dot).
300 * If empty string or if it's ending with a slash this
301 * will be set to -1. Optional.
302 */
303RTDECL(size_t) RTPathParse(const char *pszPath, size_t *pcchDir, ssize_t *poffName, ssize_t *poffSuff);
304
305/**
306 * Finds the filename in a path.
307 *
308 * @returns Pointer to filename within pszPath.
309 * @returns NULL if no filename (i.e. empty string or ends with a slash).
310 * @param pszPath Path to find filename in.
311 */
312RTDECL(char *) RTPathFilename(const char *pszPath);
313
314/**
315 * Finds the extension part of in a path.
316 *
317 * @returns Pointer to extension within pszPath.
318 * @returns NULL if no extension.
319 * @param pszPath Path to find extension in.
320 */
321RTDECL(char *) RTPathExt(const char *pszPath);
322
323/**
324 * Checks if a path have an extension.
325 *
326 * @returns true if extension present.
327 * @returns false if no extension.
328 * @param pszPath Path to check.
329 */
330RTDECL(bool) RTPathHaveExt(const char *pszPath);
331
332/**
333 * Checks if a path includes more than a filename.
334 *
335 * @returns true if path present.
336 * @returns false if no path.
337 * @param pszPath Path to check.
338 */
339RTDECL(bool) RTPathHavePath(const char *pszPath);
340
341/**
342 * Checks if the path starts with a root specifier or not.
343 *
344 * @returns @c true if it starts with root, @c false if not.
345 *
346 * @param pszPath Path to check.
347 */
348RTDECL(bool) RTPathStartsWithRoot(const char *pszPath);
349
350/**
351 * Counts the components in the specified path.
352 *
353 * An empty string has zero components. A lone root slash is considered have
354 * one. The paths "/init" and "/bin/" are considered having two components. An
355 * UNC share specifier like "\\myserver\share" will be considered as one single
356 * component.
357 *
358 * @returns The number of path components.
359 * @param pszPath The path to parse.
360 */
361RTDECL(size_t) RTPathCountComponents(const char *pszPath);
362
363/**
364 * Copies the specified number of path components from @a pszSrc and into @a
365 * pszDst.
366 *
367 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW. In the latter case the buffer
368 * is not touched.
369 *
370 * @param pszDst The destination buffer.
371 * @param cbDst The size of the destination buffer.
372 * @param pszSrc The source path.
373 * @param cComponents The number of components to copy from @a pszSrc.
374 */
375RTDECL(int) RTPathCopyComponents(char *pszDst, size_t cbDst, const char *pszSrc, size_t cComponents);
376
377/**
378 * Compares two paths.
379 *
380 * The comparison takes platform-dependent details into account,
381 * such as:
382 * <ul>
383 * <li>On DOS-like platforms, both separator chars (|\| and |/|) are considered
384 * to be equal.
385 * <li>On platforms with case-insensitive file systems, mismatching characters
386 * are uppercased and compared again.
387 * </ul>
388 *
389 * @returns @< 0 if the first path less than the second path.
390 * @returns 0 if the first path identical to the second path.
391 * @returns @> 0 if the first path greater than the second path.
392 *
393 * @param pszPath1 Path to compare (must be an absolute path).
394 * @param pszPath2 Path to compare (must be an absolute path).
395 *
396 * @remarks File system details are currently ignored. This means that you won't
397 * get case-insensitive compares on unix systems when a path goes into a
398 * case-insensitive filesystem like FAT, HPFS, HFS, NTFS, JFS, or
399 * similar. For NT, OS/2 and similar you'll won't get case-sensitive
400 * compares on a case-sensitive file system.
401 */
402RTDECL(int) RTPathCompare(const char *pszPath1, const char *pszPath2);
403
404/**
405 * Checks if a path starts with the given parent path.
406 *
407 * This means that either the path and the parent path matches completely, or
408 * that the path is to some file or directory residing in the tree given by the
409 * parent directory.
410 *
411 * The path comparison takes platform-dependent details into account,
412 * see RTPathCompare() for details.
413 *
414 * @returns |true| when \a pszPath starts with \a pszParentPath (or when they
415 * are identical), or |false| otherwise.
416 *
417 * @param pszPath Path to check, must be an absolute path.
418 * @param pszParentPath Parent path, must be an absolute path.
419 * No trailing directory slash!
420 *
421 * @remarks This API doesn't currently handle root directory compares in a
422 * manner consistent with the other APIs. RTPathStartsWith(pszSomePath,
423 * "/") will not work if pszSomePath isn't "/".
424 */
425RTDECL(bool) RTPathStartsWith(const char *pszPath, const char *pszParentPath);
426
427/**
428 * Appends one partial path to another.
429 *
430 * The main purpose of this function is to deal correctly with the slashes when
431 * concatenating the two partial paths.
432 *
433 * @retval VINF_SUCCESS on success.
434 * @retval VERR_BUFFER_OVERFLOW if the result is too big to fit within
435 * cbPathDst bytes. No changes has been made.
436 * @retval VERR_INVALID_PARAMETER if the string pointed to by pszPath is longer
437 * than cbPathDst-1 bytes (failed to find terminator). Asserted.
438 *
439 * @param pszPath The path to append pszAppend to. This serves as both
440 * input and output. This can be empty, in which case
441 * pszAppend is just copied over.
442 * @param cbPathDst The size of the buffer pszPath points to, terminator
443 * included. This should NOT be strlen(pszPath).
444 * @param pszAppend The partial path to append to pszPath. This can be
445 * NULL, in which case nothing is done.
446 *
447 * @remarks On OS/2, Window and similar systems, concatenating a drive letter
448 * specifier with a slash prefixed path will result in an absolute
449 * path. Meaning, RTPathAppend(strcpy(szBuf, "C:"), sizeof(szBuf),
450 * "/bar") will result in "C:/bar". (This follows directly from the
451 * behavior when pszPath is empty.)
452 *
453 * On the other hand, when joining a drive letter specifier with a
454 * partial path that does not start with a slash, the result is not an
455 * absolute path. Meaning, RTPathAppend(strcpy(szBuf, "C:"),
456 * sizeof(szBuf), "bar") will result in "C:bar".
457 */
458RTDECL(int) RTPathAppend(char *pszPath, size_t cbPathDst, const char *pszAppend);
459
460/**
461 * Like RTPathAppend, but with the base path as a separate argument instead of
462 * in the path buffer.
463 *
464 * @retval VINF_SUCCESS on success.
465 * @retval VERR_BUFFER_OVERFLOW if the result is too big to fit within
466 * cbPathDst bytes.
467 * @retval VERR_INVALID_PARAMETER if the string pointed to by pszPath is longer
468 * than cbPathDst-1 bytes (failed to find terminator). Asserted.
469 *
470 * @param pszPathDst Where to store the resulting path.
471 * @param cbPathDst The size of the buffer pszPathDst points to,
472 * terminator included.
473 * @param pszPathSrc The base path to copy into @a pszPathDst before
474 * appending @a pszAppend.
475 * @param pszAppend The partial path to append to pszPathSrc. This can
476 * be NULL, in which case nothing is done.
477 *
478 */
479RTDECL(int) RTPathJoin(char *pszPathDst, size_t cbPathDst, const char *pszPathSrc,
480 const char *pszAppend);
481
482/**
483 * Same as RTPathJoin, except that the output buffer is allocated.
484 *
485 * @returns Buffer containing the joined up path, call RTStrFree to free. NULL
486 * on allocation failure.
487 * @param pszPathSrc The base path to copy into @a pszPathDst before
488 * appending @a pszAppend.
489 * @param pszAppend The partial path to append to pszPathSrc. This can
490 * be NULL, in which case nothing is done.
491 *
492 */
493RTDECL(char *) RTPathJoinA(const char *pszPathSrc, const char *pszAppend);
494
495/**
496 * Callback for RTPathTraverseList that's called for each element.
497 *
498 * @returns IPRT style status code. Return VINF_TRY_AGAIN to continue, any other
499 * value will abort the traversing and be returned to the caller.
500 *
501 * @param pchPath Pointer to the start of the current path. This is
502 * not null terminated.
503 * @param cchPath The length of the path.
504 * @param pvUser1 The first user parameter.
505 * @param pvUser2 The second user parameter.
506 */
507typedef DECLCALLBACK(int) FNRTPATHTRAVERSER(char const *pchPath, size_t cchPath, void *pvUser1, void *pvUser2);
508/** Pointer to a FNRTPATHTRAVERSER. */
509typedef FNRTPATHTRAVERSER *PFNRTPATHTRAVERSER;
510
511/**
512 * Traverses a string that can contain multiple paths separated by a special
513 * character.
514 *
515 * @returns IPRT style status code from the callback or VERR_END_OF_STRING if
516 * the callback returned VINF_TRY_AGAIN for all paths in the string.
517 *
518 * @param pszPathList The string to traverse.
519 * @param chSep The separator character. Using the null terminator
520 * is fine, but the result will simply be that there
521 * will only be one callback for the entire string
522 * (save any leading white space).
523 * @param pfnCallback The callback.
524 * @param pvUser1 First user argument for the callback.
525 * @param pvUser2 Second user argument for the callback.
526 */
527RTDECL(int) RTPathTraverseList(const char *pszPathList, char chSep, PFNRTPATHTRAVERSER pfnCallback, void *pvUser1, void *pvUser2);
528
529
530#ifdef IN_RING3
531
532/**
533 * Gets the path to the directory containing the executable.
534 *
535 * @returns iprt status code.
536 * @param pszPath Buffer where to store the path.
537 * @param cchPath Buffer size in bytes.
538 */
539RTDECL(int) RTPathExecDir(char *pszPath, size_t cchPath);
540
541/**
542 * Gets the user home directory.
543 *
544 * @returns iprt status code.
545 * @param pszPath Buffer where to store the path.
546 * @param cchPath Buffer size in bytes.
547 */
548RTDECL(int) RTPathUserHome(char *pszPath, size_t cchPath);
549
550/**
551 * Gets the directory of shared libraries.
552 *
553 * This is not the same as RTPathAppPrivateArch() as Linux depends all shared
554 * libraries in a common global directory where ld.so can found them.
555 *
556 * Linux: /usr/lib
557 * Windows: @<program files directory@>/@<application@>
558 * Old path: same as RTPathExecDir()
559 *
560 * @returns iprt status code.
561 * @param pszPath Buffer where to store the path.
562 * @param cchPath Buffer size in bytes.
563 */
564RTDECL(int) RTPathSharedLibs(char *pszPath, size_t cchPath);
565
566/**
567 * Gets the directory for architecture-independent application data, for
568 * example NLS files, module sources, ...
569 *
570 * Linux: /usr/shared/@<application@>
571 * Windows: @<program files directory@>/@<application@>
572 * Old path: same as RTPathExecDir()
573 *
574 * @returns iprt status code.
575 * @param pszPath Buffer where to store the path.
576 * @param cchPath Buffer size in bytes.
577 */
578RTDECL(int) RTPathAppPrivateNoArch(char *pszPath, size_t cchPath);
579
580/**
581 * Gets the directory for architecture-dependent application data, for
582 * example modules which can be loaded at runtime.
583 *
584 * Linux: /usr/lib/@<application@>
585 * Windows: @<program files directory@>/@<application@>
586 * Old path: same as RTPathExecDir()
587 *
588 * @returns iprt status code.
589 * @param pszPath Buffer where to store the path.
590 * @param cchPath Buffer size in bytes.
591 */
592RTDECL(int) RTPathAppPrivateArch(char *pszPath, size_t cchPath);
593
594/**
595 * Gets the directory for documentation.
596 *
597 * Linux: /usr/share/doc/@<application@>
598 * Windows: @<program files directory@>/@<application@>
599 * Old path: same as RTPathExecDir()
600 *
601 * @returns iprt status code.
602 * @param pszPath Buffer where to store the path.
603 * @param cchPath Buffer size in bytes.
604 */
605RTDECL(int) RTPathAppDocs(char *pszPath, size_t cchPath);
606
607/**
608 * Gets the temporary directory path.
609 *
610 * @returns iprt status code.
611 * @param pszPath Buffer where to store the path.
612 * @param cchPath Buffer size in bytes.
613 */
614RTDECL(int) RTPathTemp(char *pszPath, size_t cchPath);
615
616/**
617 * Query information about a file system object.
618 *
619 * This API will resolve NOT symbolic links in the last component (just like
620 * unix lstat()).
621 *
622 * @returns IPRT status code.
623 * @retval VINF_SUCCESS if the object exists, information returned.
624 * @retval VERR_PATH_NOT_FOUND if any but the last component in the specified
625 * path was not found or was not a directory.
626 * @retval VERR_FILE_NOT_FOUND if the object does not exist (but path to the
627 * parent directory exists).
628 *
629 * @param pszPath Path to the file system object.
630 * @param pObjInfo Object information structure to be filled on successful return.
631 * @param enmAdditionalAttribs
632 * Which set of additional attributes to request.
633 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
634 */
635RTR3DECL(int) RTPathQueryInfo(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs);
636
637/**
638 * Query information about a file system object.
639 *
640 * @returns IPRT status code.
641 * @retval VINF_SUCCESS if the object exists, information returned.
642 * @retval VERR_PATH_NOT_FOUND if any but the last component in the specified
643 * path was not found or was not a directory.
644 * @retval VERR_FILE_NOT_FOUND if the object does not exist (but path to the
645 * parent directory exists).
646 *
647 * @param pszPath Path to the file system object.
648 * @param pObjInfo Object information structure to be filled on successful return.
649 * @param enmAdditionalAttribs
650 * Which set of additional attributes to request.
651 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
652 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
653 */
654RTR3DECL(int) RTPathQueryInfoEx(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags);
655
656/**
657 * Changes the mode flags of a file system object.
658 *
659 * The API requires at least one of the mode flag sets (Unix/Dos) to
660 * be set. The type is ignored.
661 *
662 * This API will resolve symbolic links in the last component since
663 * mode isn't important for symbolic links.
664 *
665 * @returns iprt status code.
666 * @param pszPath Path to the file system object.
667 * @param fMode The new file mode, see @ref grp_rt_fs for details.
668 */
669RTR3DECL(int) RTPathSetMode(const char *pszPath, RTFMODE fMode);
670
671/**
672 * Gets the mode flags of a file system object.
673 *
674 * @returns iprt status code.
675 * @param pszPath Path to the file system object.
676 * @param pfMode Where to store the file mode, see @ref grp_rt_fs for details.
677 *
678 * @remark This is wrapper around RTPathQueryInfoEx(RTPATH_F_FOLLOW_LINK) and
679 * exists to complement RTPathSetMode().
680 */
681RTR3DECL(int) RTPathGetMode(const char *pszPath, PRTFMODE pfMode);
682
683/**
684 * Changes one or more of the timestamps associated of file system object.
685 *
686 * This API will not resolve symbolic links in the last component (just
687 * like unix lutimes()).
688 *
689 * @returns iprt status code.
690 * @param pszPath Path to the file system object.
691 * @param pAccessTime Pointer to the new access time.
692 * @param pModificationTime Pointer to the new modification time.
693 * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
694 * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
695 *
696 * @remark The file system might not implement all these time attributes,
697 * the API will ignore the ones which aren't supported.
698 *
699 * @remark The file system might not implement the time resolution
700 * employed by this interface, the time will be chopped to fit.
701 *
702 * @remark The file system may update the change time even if it's
703 * not specified.
704 *
705 * @remark POSIX can only set Access & Modification and will always set both.
706 */
707RTR3DECL(int) RTPathSetTimes(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
708 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
709
710/**
711 * Changes one or more of the timestamps associated of file system object.
712 *
713 * @returns iprt status code.
714 * @param pszPath Path to the file system object.
715 * @param pAccessTime Pointer to the new access time.
716 * @param pModificationTime Pointer to the new modification time.
717 * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
718 * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
719 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
720 *
721 * @remark The file system might not implement all these time attributes,
722 * the API will ignore the ones which aren't supported.
723 *
724 * @remark The file system might not implement the time resolution
725 * employed by this interface, the time will be chopped to fit.
726 *
727 * @remark The file system may update the change time even if it's
728 * not specified.
729 *
730 * @remark POSIX can only set Access & Modification and will always set both.
731 */
732RTR3DECL(int) RTPathSetTimesEx(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
733 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime, uint32_t fFlags);
734
735/**
736 * Gets one or more of the timestamps associated of file system object.
737 *
738 * @returns iprt status code.
739 * @param pszPath Path to the file system object.
740 * @param pAccessTime Where to store the access time. NULL is ok.
741 * @param pModificationTime Where to store the modification time. NULL is ok.
742 * @param pChangeTime Where to store the change time. NULL is ok.
743 * @param pBirthTime Where to store the creation time. NULL is ok.
744 *
745 * @remark This is wrapper around RTPathQueryInfo() and exists to complement
746 * RTPathSetTimes(). If the last component is a symbolic link, it will
747 * not be resolved.
748 */
749RTR3DECL(int) RTPathGetTimes(const char *pszPath, PRTTIMESPEC pAccessTime, PRTTIMESPEC pModificationTime,
750 PRTTIMESPEC pChangeTime, PRTTIMESPEC pBirthTime);
751
752/**
753 * Changes the owner and/or group of a file system object.
754 *
755 * This API will not resolve symbolic links in the last component (just
756 * like unix lchown()).
757 *
758 * @returns iprt status code.
759 * @param pszPath Path to the file system object.
760 * @param uid The new file owner user id. Use -1 (or ~0) to leave this unchanged.
761 * @param gid The new group id. Use -1 (or ~0) to leave this unchanged.
762 */
763RTR3DECL(int) RTPathSetOwner(const char *pszPath, uint32_t uid, uint32_t gid);
764
765/**
766 * Changes the owner and/or group of a file system object.
767 *
768 * @returns iprt status code.
769 * @param pszPath Path to the file system object.
770 * @param uid The new file owner user id. Use -1 (or ~0) to leave this unchanged.
771 * @param gid The new group id. Use -1 (or ~0) to leave this unchanged.
772 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
773 */
774RTR3DECL(int) RTPathSetOwnerEx(const char *pszPath, uint32_t uid, uint32_t gid, uint32_t fFlags);
775
776/**
777 * Gets the owner and/or group of a file system object.
778 *
779 * @returns iprt status code.
780 * @param pszPath Path to the file system object.
781 * @param pUid Where to store the owner user id. NULL is ok.
782 * @param pGid Where to store the group id. NULL is ok.
783 *
784 * @remark This is wrapper around RTPathQueryInfo() and exists to complement
785 * RTPathGetOwner(). If the last component is a symbolic link, it will
786 * not be resolved.
787 */
788RTR3DECL(int) RTPathGetOwner(const char *pszPath, uint32_t *pUid, uint32_t *pGid);
789
790
791/** @name RTPathRename, RTDirRename & RTFileRename flags.
792 * @{ */
793/** Do not replace anything. */
794#define RTPATHRENAME_FLAGS_NO_REPLACE UINT32_C(0)
795/** This will replace attempt any target which isn't a directory. */
796#define RTPATHRENAME_FLAGS_REPLACE RT_BIT(0)
797/** @} */
798
799/**
800 * Renames a path within a filesystem.
801 *
802 * This will rename symbolic links. If RTPATHRENAME_FLAGS_REPLACE is used and
803 * pszDst is a symbolic link, it will be replaced and not its target.
804 *
805 * @returns IPRT status code.
806 * @param pszSrc The source path.
807 * @param pszDst The destination path.
808 * @param fRename Rename flags, RTPATHRENAME_FLAGS_*.
809 */
810RTR3DECL(int) RTPathRename(const char *pszSrc, const char *pszDst, unsigned fRename);
811
812#endif /* IN_RING3 */
813
814/** @} */
815
816RT_C_DECLS_END
817
818#endif
819
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