/* this function is a POSIX compliant version, which will close a directory stream. */
int closedir(DIR *d)
/* this function is a POSIX compliant version, which will close a directory stream. */
int closedir(DIR *d)
{
    int result;
    struct dfs_file *file;
    if (d == NULL)
    {
        rt_set_errno(-EBADF);
        return -1;
    }
    file = fd_get(d->fd);
    if (file == NULL)
    {
        rt_set_errno(-EBADF);
        return -1;
    }
    result = dfs_file_close(file);
    if (result < 0)
    {
        rt_set_errno(result);
        return -1;
    }
    else
    {
        fd_release(d->fd);
        rt_free(d);
    }
    return 0;
}