* * 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. */
| 701 | * otherwise, -1 shall be returned and errno set to indicate the error. |
| 702 | */ |
| 703 | int ftruncate(int fd, off_t length) |
| 704 | { |
| 705 | int result; |
| 706 | struct dfs_file *file; |
| 707 | |
| 708 | file = fd_get(fd); |
| 709 | if (file == NULL) |
| 710 | { |
| 711 | rt_set_errno(-EBADF); |
| 712 | |
| 713 | return -1; |
| 714 | } |
| 715 | |
| 716 | if (length < 0) |
| 717 | { |
| 718 | rt_set_errno(-EINVAL); |
| 719 | |
| 720 | return -1; |
| 721 | } |
| 722 | |
| 723 | result = dfs_file_ftruncate(file, length); |
| 724 | if (result < 0) |
| 725 | { |
| 726 | rt_set_errno(result); |
| 727 | |
| 728 | return -1; |
| 729 | } |
| 730 | |
| 731 | return 0; |
| 732 | } |
| 733 | RTM_EXPORT(ftruncate); |
| 734 | |
| 735 | /** |
nothing calls this directly
no test coverage detected