- Timestamp:
- Jul 26, 2016 1:54:52 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/RTFileModeToFlags.cpp
r62477 r62559 36 36 37 37 38 RTR3DECL(int) RTFileModeToFlags(const char *pszMode, uint64_t *p uMode)38 RTR3DECL(int) RTFileModeToFlags(const char *pszMode, uint64_t *pfMode) 39 39 { 40 40 AssertPtrReturn(pszMode, VERR_INVALID_POINTER); 41 AssertPtrReturn(puMode, VERR_INVALID_POINTER); 42 43 int rc = VINF_SUCCESS; 41 AssertPtrReturn(pfMode, VERR_INVALID_POINTER); 44 42 45 43 const char *pszCur = pszMode; 46 uint64_t uMode = 0;47 char chPrev = 0;48 49 44 if (*pszCur == '\0') 50 45 return VERR_INVALID_PARAMETER; 51 46 47 uint64_t fMode = 0; 48 char chPrev = '\0'; 52 49 while ( pszCur 53 50 && *pszCur != '\0') … … 60 57 * created if it does not exist. */ 61 58 case 'a': 62 if ((uMode & RTFILE_O_ACTION_MASK) == 0) 63 { 64 uMode |= RTFILE_O_OPEN_CREATE 65 | RTFILE_O_WRITE 66 | RTFILE_O_APPEND; 67 } 68 else 69 rc = VERR_INVALID_PARAMETER; 59 if ((fMode & RTFILE_O_ACTION_MASK) == 0) 60 fMode |= RTFILE_O_OPEN_CREATE 61 | RTFILE_O_WRITE 62 | RTFILE_O_APPEND; 63 else 64 return VERR_INVALID_PARAMETER; 70 65 break; 71 66 … … 79 74 * at the beginning of the file.*/ 80 75 case 'c': 81 if ((uMode & RTFILE_O_ACTION_MASK) == 0) 82 { 83 uMode |= RTFILE_O_OPEN_CREATE 84 | RTFILE_O_WRITE; 85 } 86 else 87 rc = VERR_INVALID_PARAMETER; 76 if ((fMode & RTFILE_O_ACTION_MASK) == 0) 77 fMode |= RTFILE_O_OPEN_CREATE 78 | RTFILE_O_WRITE; 79 else 80 return VERR_INVALID_PARAMETER; 88 81 break; 89 82 … … 92 85 * file does not exist an error will be returned. */ 93 86 case 'r': 94 if ((uMode & RTFILE_O_ACTION_MASK) == 0) 95 { 96 uMode |= RTFILE_O_OPEN 97 | RTFILE_O_READ; 98 } 99 else 100 rc = VERR_INVALID_PARAMETER; 87 if ((fMode & RTFILE_O_ACTION_MASK) == 0) 88 fMode |= RTFILE_O_OPEN 89 | RTFILE_O_READ; 90 else 91 return VERR_INVALID_PARAMETER; 101 92 break; 102 93 … … 110 101 * An existing file will be truncated to 0 bytes. */ 111 102 case 'w': 112 if ((uMode & RTFILE_O_ACTION_MASK) == 0) 113 { 114 uMode |= RTFILE_O_CREATE_REPLACE 115 | RTFILE_O_WRITE 116 | RTFILE_O_TRUNCATE; 117 } 118 else 119 rc = VERR_INVALID_PARAMETER; 103 if ((fMode & RTFILE_O_ACTION_MASK) == 0) 104 fMode |= RTFILE_O_CREATE_REPLACE 105 | RTFILE_O_WRITE 106 | RTFILE_O_TRUNCATE; 107 else 108 return VERR_INVALID_PARAMETER; 120 109 break; 121 110 … … 124 113 * exists an error will be returned. */ 125 114 case 'x': 126 if ((uMode & RTFILE_O_ACTION_MASK) == 0) 127 { 128 uMode |= RTFILE_O_CREATE 129 | RTFILE_O_WRITE; 130 } 131 else 132 rc = VERR_INVALID_PARAMETER; 115 if ((fMode & RTFILE_O_ACTION_MASK) == 0) 116 fMode |= RTFILE_O_CREATE 117 | RTFILE_O_WRITE; 118 else 119 return VERR_INVALID_PARAMETER; 133 120 break; 134 121 … … 142 129 case 'x': 143 130 /* Also open / create file with read access. */ 144 uMode |= RTFILE_O_READ;131 fMode |= RTFILE_O_READ; 145 132 break; 146 133 147 134 case 'r': 148 135 /* Also open / create file with write access. */ 149 uMode |= RTFILE_O_WRITE;136 fMode |= RTFILE_O_WRITE; 150 137 break; 151 138 … … 163 150 164 151 default: 165 rc = VERR_INVALID_PARAMETER; 166 break; 152 return VERR_INVALID_PARAMETER; 167 153 } 168 154 … … 171 157 172 158 default: 173 rc = VERR_INVALID_PARAMETER; 174 break; 159 return VERR_INVALID_PARAMETER; 175 160 } 176 177 if (RT_FAILURE(rc))178 break;179 161 180 162 if (!fSkip) … … 184 166 185 167 /* No action mask set? */ 186 if ( RT_SUCCESS(rc) 187 && (uMode & RTFILE_O_ACTION_MASK) == 0) 188 rc = VERR_INVALID_PARAMETER; 189 190 /** @todo Handle sharing mode. */ 191 uMode |= RTFILE_O_DENY_NONE; 192 193 if (RT_SUCCESS(rc)) 194 *puMode = uMode; 195 196 return rc; 168 if ((fMode & RTFILE_O_ACTION_MASK) == 0) 169 return VERR_INVALID_PARAMETER; 170 171 /** @todo Handle sharing mode */ 172 fMode |= RTFILE_O_DENY_NONE; 173 174 /* Return. */ 175 *pfMode = fMode; 176 return VINF_SUCCESS; 197 177 } 198 178 RT_EXPORT_SYMBOL(RTFileModeToFlags); … … 200 180 201 181 RTR3DECL(int) RTFileModeToFlagsEx(const char *pszAccess, const char *pszDisposition, 202 const char *pszSharing, uint64_t *p uMode)182 const char *pszSharing, uint64_t *pfMode) 203 183 { 204 184 AssertPtrReturn(pszAccess, VERR_INVALID_POINTER); 205 185 AssertPtrReturn(pszDisposition, VERR_INVALID_POINTER); 206 /* pszSharing is not used yet. */ 207 AssertPtrReturn(puMode, VERR_INVALID_POINTER); 208 209 int rc = VINF_SUCCESS; 186 AssertPtrNullReturn(pszSharing, VERR_INVALID_POINTER); 187 AssertPtrReturn(pfMode, VERR_INVALID_POINTER); 210 188 211 189 const char *pszCur = pszAccess; 212 uint64_t uMode = 0;213 char chPrev = 0;214 215 190 if (*pszCur == '\0') 216 191 return VERR_INVALID_PARAMETER; … … 219 194 * Handle access mode. 220 195 */ 196 uint64_t fMode = 0; 197 char chPrev = '\0'; 221 198 while ( pszCur 222 199 && *pszCur != '\0') … … 231 208 232 209 case 'r': /* Read. */ 233 uMode |= RTFILE_O_READ;210 fMode |= RTFILE_O_READ; 234 211 break; 235 212 … … 240 217 241 218 case 'w': /* Write. */ 242 uMode |= RTFILE_O_WRITE;219 fMode |= RTFILE_O_WRITE; 243 220 break; 244 221 … … 249 226 case 'w': 250 227 /* Also use read access in write mode. */ 251 uMode |= RTFILE_O_READ;228 fMode |= RTFILE_O_READ; 252 229 break; 253 230 254 231 case 'r': 255 232 /* Also use write access in read mode. */ 256 uMode |= RTFILE_O_WRITE;233 fMode |= RTFILE_O_WRITE; 257 234 break; 258 235 … … 270 247 271 248 default: 272 rc = VERR_INVALID_PARAMETER; 273 break; 249 return VERR_INVALID_PARAMETER; 274 250 } 275 251 … … 278 254 279 255 default: 280 rc = VERR_INVALID_PARAMETER; 281 break; 256 return VERR_INVALID_PARAMETER; 282 257 } 283 284 if (RT_FAILURE(rc))285 break;286 258 287 259 if (!fSkip) … … 290 262 } 291 263 292 if (RT_FAILURE(rc))293 return rc;294 295 264 /* 296 265 * Handle disposition. … … 300 269 /* Create a new file, always, overwrite an existing file. */ 301 270 if (!RTStrCmp(pszCur, "ca")) 302 uMode |= RTFILE_O_CREATE_REPLACE;271 fMode |= RTFILE_O_CREATE_REPLACE; 303 272 /* Create a new file if it does not exist, fail if exist. */ 304 273 else if (!RTStrCmp(pszCur, "ce")) 305 uMode |= RTFILE_O_CREATE;274 fMode |= RTFILE_O_CREATE; 306 275 /* Open existing file, create file if does not exist. */ 307 276 else if (!RTStrCmp(pszCur, "oc")) 308 uMode |= RTFILE_O_OPEN_CREATE;277 fMode |= RTFILE_O_OPEN_CREATE; 309 278 /* Open existing file and place the file pointer at 310 279 * the end of the file, if opened with write access. 311 280 * Create the file if does not exist. */ 312 281 else if (!RTStrCmp(pszCur, "oa")) 313 uMode |= RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND;282 fMode |= RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND; 314 283 /* Open existing, fail if does not exist. */ 315 284 else if (!RTStrCmp(pszCur, "oe")) 316 uMode |= RTFILE_O_OPEN;285 fMode |= RTFILE_O_OPEN; 317 286 /* Open and truncate existing, fail of not exist. */ 318 287 else if (!RTStrCmp(pszCur, "ot")) 319 uMode |= RTFILE_O_OPEN | RTFILE_O_TRUNCATE;288 fMode |= RTFILE_O_OPEN | RTFILE_O_TRUNCATE; 320 289 else 321 r c =VERR_INVALID_PARAMETER;290 return VERR_INVALID_PARAMETER; 322 291 323 292 /* No action mask set? */ 324 if ( RT_SUCCESS(rc) 325 && (uMode & RTFILE_O_ACTION_MASK) == 0) 326 rc = VERR_INVALID_PARAMETER; 293 if ((fMode & RTFILE_O_ACTION_MASK) == 0) 294 return VERR_INVALID_PARAMETER; 327 295 328 296 /** @todo Handle sharing mode. */ 329 uMode |= RTFILE_O_DENY_NONE; 330 331 if (RT_SUCCESS(rc)) 332 *puMode = uMode; 333 334 return rc; 297 fMode |= RTFILE_O_DENY_NONE; 298 299 /* Return. */ 300 *pfMode = fMode; 301 return VINF_SUCCESS; 335 302 } 336 303 RT_EXPORT_SYMBOL(RTFileModeToFlagsEx);
Note:
See TracChangeset
for help on using the changeset viewer.