/* this function is a POSIX compliant version, which will return current location in directory stream. */
long telldir(DIR *d)
/* this function is a POSIX compliant version, which will return current location in directory stream. */
long telldir(DIR *d)
{
    struct dfs_file *file;
    long result;
    if (d == NULL)
    {
        rt_set_errno(-EBADF);
        return -1;
    }
    file = fd_get(d->fd);
    if (file == NULL)
    {
        rt_set_errno(-EBADF);
        return 0;
    }
    result = file->fpos - d->num + d->cur;
    return result;
}