VirtualBox

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

Last change on this file since 28412 was 26520, checked in by vboxsync, 15 years ago

iprt: Added RTPathChangeToUnixSlashes and RTPathChangeToDosSlashes.

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