Changeset 7ab7075f in mainline for uspace/lib/c/generic/io/io.c
- Timestamp:
- 2018-08-06T18:40:12Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1dcba91
- Parents:
- 7afd12e5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/io/io.c
r7afd12e5 r7ab7075f 185 185 } 186 186 187 static bool parse_mode(const char *fmode, int *mode, bool *create, bool *truncate) 187 static bool parse_mode(const char *fmode, int *mode, bool *create, bool *excl, 188 bool *truncate) 188 189 { 189 190 /* Parse mode except first character. */ 190 191 const char *mp = fmode; 191 if (*mp++ == 0) { 192 193 if (*mp++ == '\0') { 192 194 errno = EINVAL; 193 195 return false; … … 201 203 mp++; 202 204 plus = true; 203 } else 205 } else { 204 206 plus = false; 205 206 if (*mp != 0) { 207 } 208 209 bool ex; 210 if (*mp == 'x') { 211 mp++; 212 ex = true; 213 } else { 214 ex = false; 215 } 216 217 if (*mp != '\0') { 207 218 errno = EINVAL; 208 219 return false; … … 211 222 *create = false; 212 223 *truncate = false; 224 *excl = false; 213 225 214 226 /* Parse first character of fmode and determine mode for vfs_open(). */ … … 216 228 case 'r': 217 229 *mode = plus ? MODE_READ | MODE_WRITE : MODE_READ; 230 if (ex) { 231 errno = EINVAL; 232 return false; 233 } 218 234 break; 219 235 case 'w': 220 236 *mode = plus ? MODE_READ | MODE_WRITE : MODE_WRITE; 221 237 *create = true; 238 *excl = ex; 222 239 if (!plus) 223 240 *truncate = true; … … 227 244 if (plus) { 228 245 errno = ENOTSUP; 246 return false; 247 } 248 249 if (ex) { 250 errno = EINVAL; 229 251 return false; 230 252 } … … 307 329 * 308 330 * @param path Path of the file to open. 309 * @param mode Mode string, (r|w|a)[b|t][+] .331 * @param mode Mode string, (r|w|a)[b|t][+][x]. 310 332 * 311 333 */ … … 314 336 int mode; 315 337 bool create; 338 bool excl; 316 339 bool truncate; 317 340 318 if (!parse_mode(fmode, &mode, &create, & truncate))341 if (!parse_mode(fmode, &mode, &create, &excl, &truncate)) 319 342 return NULL; 320 343 … … 327 350 328 351 int flags = WALK_REGULAR; 329 if (create) 352 if (create && excl) 353 flags |= WALK_MUST_CREATE; 354 else if (create) 330 355 flags |= WALK_MAY_CREATE; 331 356 int file;
Note:
See TracChangeset
for help on using the changeset viewer.