/* this function is a POSIX compliant version, which will get file status. */
int fstat(int fildes, struct stat *buf)
/* this function is a POSIX compliant version, which will get file status. */
int fstat(int fildes, struct stat *buf)
{
    struct dfs_fd *d;
    d = fd_get(fildes);
    if (d == NULL)
    {
        rt_set_errno(-EBADF);
        return -1;
    }
    buf->st_dev = 0;
    buf->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH |
                   S_IWUSR | S_IWGRP | S_IWOTH;
    if (d->type == FT_DIRECTORY)
    {
        buf->st_mode &= ~S_IFREG;
        buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
    }
    buf->st_size    = d->size;
    buf->st_mtime   = 0;
    fd_put(d);
    return RT_EOK;
}