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

Function ftruncate

components/dfs/dfs_v1/src/dfs_posix.c:552–580  ·  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

550 * otherwise, -1 shall be returned and errno set to indicate the error.
551 */
552int 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}
581RTM_EXPORT(ftruncate);
582
583/**

Callers 1

sys_ftruncateFunction · 0.50

Calls 3

rt_set_errnoFunction · 0.85
fd_getFunction · 0.70
dfs_file_ftruncateFunction · 0.70

Tested by

no test coverage detected