Changes in uspace/lib/c/generic/vfs/vfs.c [79ae36dd:8fd04ba9] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
r79ae36dd r8fd04ba9 417 417 } 418 418 419 /** Read entire buffer. 420 * 421 * In face of short reads this function continues reading until either 422 * the entire buffer is read or no more data is available (at end of file). 423 * 424 * @param fildes File descriptor 425 * @param buf Buffer, @a nbytes bytes long 426 * @param nbytes Number of bytes to read 427 * 428 * @return On success, positive number of bytes read. 429 * On failure, negative error code from read(). 430 */ 431 ssize_t read_all(int fildes, void *buf, size_t nbyte) 432 { 433 ssize_t cnt = 0; 434 size_t nread = 0; 435 uint8_t *bp = (uint8_t *) buf; 436 437 do { 438 bp += cnt; 439 nread += cnt; 440 cnt = read(fildes, bp, nbyte - nread); 441 } while (cnt > 0 && (nbyte - nread - cnt) > 0); 442 443 if (cnt < 0) 444 return cnt; 445 446 return nread + cnt; 447 } 448 449 /** Write entire buffer. 450 * 451 * This function fails if it cannot write exactly @a len bytes to the file. 452 * 453 * @param fildes File descriptor 454 * @param buf Data, @a nbytes bytes long 455 * @param nbytes Number of bytes to write 456 * 457 * @return EOK on error, return value from write() if writing 458 * failed. 459 */ 460 ssize_t write_all(int fildes, const void *buf, size_t nbyte) 461 { 462 ssize_t cnt = 0; 463 ssize_t nwritten = 0; 464 const uint8_t *bp = (uint8_t *) buf; 465 466 do { 467 bp += cnt; 468 nwritten += cnt; 469 cnt = write(fildes, bp, nbyte - nwritten); 470 } while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0); 471 472 if (cnt < 0) 473 return cnt; 474 475 if ((ssize_t)nbyte - nwritten - cnt > 0) 476 return EIO; 477 478 return nbyte; 479 } 480 419 481 int fsync(int fildes) 420 482 {
Note:
See TracChangeset
for help on using the changeset viewer.