MCPcopy Create free account
hub / github.com/F-Stack/f-stack / kern_ftruncate

Function kern_ftruncate

freebsd/kern/sys_generic.c:593–613  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

591 * descriptor isn't writable.
592 */
593int
594kern_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_
616struct ftruncate_args {

Callers 3

sys_ftruncateFunction · 0.85
oftruncateFunction · 0.85
freebsd6_ftruncateFunction · 0.85

Calls 2

fgetFunction · 0.85
fo_truncateFunction · 0.85

Tested by

no test coverage detected