MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / ftruncate

Function ftruncate

components/dfs/dfs_v2/src/dfs_posix.c:703–732  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

701 * otherwise, -1 shall be returned and errno set to indicate the error.
702 */
703int 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}
733RTM_EXPORT(ftruncate);
734
735/**

Callers

nothing calls this directly

Calls 3

rt_set_errnoFunction · 0.85
fd_getFunction · 0.70
dfs_file_ftruncateFunction · 0.70

Tested by

no test coverage detected