/* 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.  */
int ftruncate(int fd, off_t length)
/* 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.  */
int ftruncate(int fd, off_t length)
{
    int result;
    struct dfs_fd *d;
    d = fd_get(fd);
    if (d == NULL)
    {
        rt_set_errno(-EBADF);
        return -1;
    }
    if (length < 0)
    {
        fd_put(d);
        rt_set_errno(-EINVAL);
        return -1;
    }
    result = dfs_file_ftruncate(d, length);
    if (result < 0)
    {
        fd_put(d);
        rt_set_errno(result);
        return -1;
    }
    fd_put(d);
    return 0;
}