* * this function is a POSIX compliant version, which cause the regular file * referenced by fd to be truncated to a size of precisely length bytes. * @param fd the file descriptor. * @param length the length to be truncated. * * @return Upon successful completion, ftruncate() shall return 0; * otherwise, -1 shall be returned and errno set to indicate the error. */
| 550 | * otherwise, -1 shall be returned and errno set to indicate the error. |
| 551 | */ |
| 552 | int ftruncate(int fd, off_t length) |
| 553 | { |
| 554 | int result; |
| 555 | struct dfs_file *d; |
| 556 | |
| 557 | d = fd_get(fd); |
| 558 | if (d == NULL) |
| 559 | { |
| 560 | rt_set_errno(-EBADF); |
| 561 | |
| 562 | return -1; |
| 563 | } |
| 564 | |
| 565 | if (length < 0) |
| 566 | { |
| 567 | rt_set_errno(-EINVAL); |
| 568 | |
| 569 | return -1; |
| 570 | } |
| 571 | result = dfs_file_ftruncate(d, length); |
| 572 | if (result < 0) |
| 573 | { |
| 574 | rt_set_errno(result); |
| 575 | |
| 576 | return -1; |
| 577 | } |
| 578 | |
| 579 | return 0; |
| 580 | } |
| 581 | RTM_EXPORT(ftruncate); |
| 582 | |
| 583 | /** |
no test coverage detected