[33426] | 1 | /** @file
|
---|
| 2 | * IPRT - Symbolic Link Manipulation.
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
[76553] | 6 | * Copyright (C) 2010-2019 Oracle Corporation
|
---|
[33426] | 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 |
|
---|
[76557] | 26 | #ifndef IPRT_INCLUDED_symlink_h
|
---|
| 27 | #define IPRT_INCLUDED_symlink_h
|
---|
[76507] | 28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 29 | # pragma once
|
---|
| 30 | #endif
|
---|
[33426] | 31 |
|
---|
| 32 | #include <iprt/cdefs.h>
|
---|
| 33 | #include <iprt/types.h>
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | RT_C_DECLS_BEGIN
|
---|
| 38 |
|
---|
| 39 | /** @defgroup grp_rt_symlink RTSymlink - Symbolic Link Manipulation
|
---|
| 40 | * @ingroup grp_rt
|
---|
| 41 | *
|
---|
| 42 | * For querying and changing symlink info (mode, ownership, etc) please refer
|
---|
| 43 | * to the @ref grp_rt_path "RTPath" API: RTPathQueryInfoEx, RTPathSetOwnerEx,
|
---|
| 44 | * RTPathSetModeEx and RTPathSetTimesEx.
|
---|
| 45 | *
|
---|
| 46 | * @{
|
---|
| 47 | */
|
---|
| 48 |
|
---|
| 49 | /**
|
---|
| 50 | * Checks if the specified path exists and is a symlink.
|
---|
| 51 | *
|
---|
| 52 | * @returns true if it's a symlink, false if it isn't.
|
---|
| 53 | * @param pszSymlink The path to the symlink.
|
---|
| 54 | *
|
---|
| 55 | * @sa RTDirExists, RTPathExists, RTSymlinkExists.
|
---|
| 56 | */
|
---|
| 57 | RTDECL(bool) RTSymlinkExists(const char *pszSymlink);
|
---|
| 58 |
|
---|
| 59 | /**
|
---|
| 60 | * Checks if this is a dangling link or not.
|
---|
| 61 | *
|
---|
| 62 | * If the target of @a pszSymlink is a symbolic link, this may return false if
|
---|
| 63 | * that or any subsequent links are dangling.
|
---|
| 64 | *
|
---|
| 65 | * @returns true if it's dangling, false if it isn't.
|
---|
| 66 | * @param pszSymlink The path to the symlink.
|
---|
| 67 | */
|
---|
| 68 | RTDECL(bool) RTSymlinkIsDangling(const char *pszSymlink);
|
---|
| 69 |
|
---|
| 70 | /**
|
---|
| 71 | * RTSymlinkCreate link type argument.
|
---|
| 72 | */
|
---|
| 73 | typedef enum RTSYMLINKTYPE
|
---|
| 74 | {
|
---|
| 75 | /** Invalid value. */
|
---|
| 76 | RTSYMLINKTYPE_INVALID = 0,
|
---|
| 77 | /** The link targets a directory. */
|
---|
| 78 | RTSYMLINKTYPE_DIR,
|
---|
| 79 | /** The link targets a file (or whatever else). */
|
---|
| 80 | RTSYMLINKTYPE_FILE,
|
---|
| 81 | /** It is not known what is being targeted.
|
---|
| 82 | * @remarks The RTSymlinkCreate API may probe the target to try figure
|
---|
| 83 | * out what is being targeted. */
|
---|
| 84 | RTSYMLINKTYPE_UNKNOWN,
|
---|
| 85 | /** The end of the valid type values. */
|
---|
| 86 | RTSYMLINKTYPE_END,
|
---|
| 87 | /** Blow the type up to 32-bit. */
|
---|
| 88 | RTSYMLINKTYPE_32BIT_HACK = 0x7fffffff
|
---|
| 89 | } RTSYMLINKTYPE;
|
---|
| 90 |
|
---|
[39612] | 91 | /** @name RTSymlinkCreate flags.
|
---|
| 92 | * @{ */
|
---|
[39641] | 93 | /** Don't allow symbolic links as part of the path.
|
---|
| 94 | * @remarks this flag is currently not implemented and will be ignored. */
|
---|
[39612] | 95 | #define RTSYMLINKCREATE_FLAGS_NO_SYMLINKS RT_BIT(0)
|
---|
| 96 | /** @} */
|
---|
| 97 |
|
---|
[33426] | 98 | /**
|
---|
| 99 | * Creates a symbolic link (@a pszSymlink) targeting @a pszTarget.
|
---|
| 100 | *
|
---|
| 101 | * @returns IPRT status code.
|
---|
| 102 | *
|
---|
| 103 | * @param pszSymlink The name of the symbolic link.
|
---|
| 104 | * @param pszTarget The path to the symbolic link target. This is
|
---|
[39641] | 105 | * relative to @a pszSymlink or an absolute path.
|
---|
[33426] | 106 | * @param enmType The symbolic link type. For Windows compatability
|
---|
| 107 | * it is very important to set this correctly. When
|
---|
| 108 | * RTSYMLINKTYPE_UNKNOWN is used, the API will try
|
---|
| 109 | * make a guess and may attempt query information
|
---|
| 110 | * about @a pszTarget in the process.
|
---|
[39612] | 111 | * @param fCreate Create flags, RTSYMLINKCREATE_FLAGS_*.
|
---|
[33426] | 112 | */
|
---|
[39612] | 113 | RTDECL(int) RTSymlinkCreate(const char *pszSymlink, const char *pszTarget,
|
---|
| 114 | RTSYMLINKTYPE enmType, uint32_t fCreate);
|
---|
[33426] | 115 |
|
---|
[39612] | 116 | /** @name RTSymlinkDelete flags.
|
---|
| 117 | * @{ */
|
---|
[39641] | 118 | /** Don't allow symbolic links as part of the path.
|
---|
| 119 | * @remarks this flag is currently not implemented and will be ignored. */
|
---|
[39612] | 120 | #define RTSYMLINKDELETE_FLAGS_NO_SYMLINKS RT_BIT(0)
|
---|
| 121 | /** @} */
|
---|
| 122 |
|
---|
[33426] | 123 | /**
|
---|
| 124 | * Deletes the specified symbolic link.
|
---|
| 125 | *
|
---|
| 126 | * This will try to refuse deleting non-symlinks, however there are usually
|
---|
| 127 | * races in the implementation of this check so no guarantees can be are made.
|
---|
| 128 | *
|
---|
| 129 | * @returns IPRT status code.
|
---|
| 130 | * @retval VERR_NOT_SYMLINK if @a pszSymlink does not specify a symbolic link.
|
---|
| 131 | *
|
---|
| 132 | * @param pszSymlink The symbolic link that should be removed.
|
---|
[39612] | 133 | * @param fDelete Delete flags, RTSYMLINKDELETE_FLAGS_*.
|
---|
[33426] | 134 | */
|
---|
[39612] | 135 | RTDECL(int) RTSymlinkDelete(const char *pszSymlink, uint32_t fDelete);
|
---|
[33426] | 136 |
|
---|
[39612] | 137 | /** @name RTSymlinkRead flags.
|
---|
| 138 | * @{ */
|
---|
[39641] | 139 | /** Don't allow symbolic links as part of the path.
|
---|
| 140 | * @remarks this flag is currently not implemented and will be ignored. */
|
---|
[39612] | 141 | #define RTSYMLINKREAD_FLAGS_NO_SYMLINKS RT_BIT(0)
|
---|
| 142 | /** @} */
|
---|
| 143 |
|
---|
[33426] | 144 | /**
|
---|
| 145 | * Read the symlink target.
|
---|
| 146 | *
|
---|
| 147 | * @returns IPRT status code.
|
---|
| 148 | * @retval VERR_NOT_SYMLINK if @a pszSymlink does not specify a symbolic link.
|
---|
| 149 | * @retval VERR_BUFFER_OVERFLOW if the link is larger than @a cbTarget. The
|
---|
| 150 | * buffer will contain what all we managed to read, fully terminated
|
---|
| 151 | * if @a cbTarget > 0.
|
---|
| 152 | *
|
---|
| 153 | * @param pszSymlink The symbolic link that should be read.
|
---|
| 154 | * @param pszTarget The target buffer.
|
---|
| 155 | * @param cbTarget The size of the target buffer.
|
---|
[39612] | 156 | * @param fRead Read flags, RTSYMLINKREAD_FLAGS_*.
|
---|
[33426] | 157 | */
|
---|
[39612] | 158 | RTDECL(int) RTSymlinkRead(const char *pszSymlink, char *pszTarget, size_t cbTarget, uint32_t fRead);
|
---|
[33426] | 159 |
|
---|
| 160 | /**
|
---|
| 161 | * Read the symlink target into an API allocated buffer.
|
---|
| 162 | *
|
---|
| 163 | * This API eliminates the race involved in determining the right buffer size.
|
---|
| 164 | *
|
---|
| 165 | * @returns IPRT status code.
|
---|
| 166 | * @retval VERR_NOT_SYMLINK if @a pszSymlink does not specify a symbolic link.
|
---|
| 167 | *
|
---|
| 168 | * @param pszSymlink The symbolic link that should be read.
|
---|
| 169 | * @param ppszTarget Where to return the target string. Free the string
|
---|
| 170 | * by calling RTStrFree.
|
---|
| 171 | */
|
---|
| 172 | RTDECL(int) RTSymlinkReadA(const char *pszSymlink, char **ppszTarget);
|
---|
| 173 |
|
---|
| 174 | /** @} */
|
---|
| 175 |
|
---|
| 176 | RT_C_DECLS_END
|
---|
| 177 |
|
---|
[76585] | 178 | #endif /* !IPRT_INCLUDED_symlink_h */
|
---|
[33426] | 179 |
|
---|