* Truncate a file given a file descriptor. * * Can't use fget_write() here, since must return EINVAL and not EBADF if the * descriptor isn't writable. */
| 591 | * descriptor isn't writable. |
| 592 | */ |
| 593 | int |
| 594 | kern_ftruncate(struct thread *td, int fd, off_t length) |
| 595 | { |
| 596 | struct file *fp; |
| 597 | int error; |
| 598 | |
| 599 | AUDIT_ARG_FD(fd); |
| 600 | if (length < 0) |
| 601 | return (EINVAL); |
| 602 | error = fget(td, fd, &cap_ftruncate_rights, &fp); |
| 603 | if (error) |
| 604 | return (error); |
| 605 | AUDIT_ARG_FILE(td->td_proc, fp); |
| 606 | if (!(fp->f_flag & FWRITE)) { |
| 607 | fdrop(fp, td); |
| 608 | return (EINVAL); |
| 609 | } |
| 610 | error = fo_truncate(fp, length, td->td_ucred, td); |
| 611 | fdrop(fp, td); |
| 612 | return (error); |
| 613 | } |
| 614 | |
| 615 | #ifndef _SYS_SYSPROTO_H_ |
| 616 | struct ftruncate_args { |
no test coverage detected