/* this function is a POSIX compliant version, which will write specified data buffer length for an open file descriptor. */
ssize_t pwrite(int fd, const void *buf, size_t len, off_t offset)
/* this function is a POSIX compliant version, which will write specified data buffer length for an open file descriptor. */
ssize_t pwrite(int fd, const void *buf, size_t len, off_t offset)
{
    ssize_t result;
    off_t fpos;
    struct dfs_file *file;
    if (buf == NULL)
    {
        rt_set_errno(-EBADF);
        return -1;
    }
    file = fd_get(fd);
    if (file == NULL)
    {
        rt_set_errno(-EBADF);
        return -1;
    }
    fpos = dfs_file_get_fpos(file);
    dfs_file_lseek(file, offset, SEEK_SET);
    result = dfs_file_write(file, buf, len);
    dfs_file_lseek(file, fpos, SEEK_SET);
    dfs_file_set_fpos(file, fpos);
    if (result < 0)
    {
        rt_set_errno(result);
        return -1;
    }
    return result;
}