readdir.c revision 59766
159766Sjlemon/*-
259766Sjlemon * Copyright (c) 1999,2000 Jonathan Lemon <jlemon@freebsd.org>
359766Sjlemon * All rights reserved.
459766Sjlemon *
559766Sjlemon * Redistribution and use in source and binary forms, with or without
659766Sjlemon * modification, are permitted provided that the following conditions
759766Sjlemon * are met:
859766Sjlemon * 1. Redistributions of source code must retain the above copyright
959766Sjlemon *    notice, this list of conditions and the following disclaimer.
1059766Sjlemon * 2. Redistributions in binary form must reproduce the above copyright
1159766Sjlemon *    notice, this list of conditions and the following disclaimer in the
1259766Sjlemon *    documentation and/or other materials provided with the distribution.
1359766Sjlemon *
1459766Sjlemon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1559766Sjlemon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1659766Sjlemon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1759766Sjlemon * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1859766Sjlemon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1959766Sjlemon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2059766Sjlemon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2159766Sjlemon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2259766Sjlemon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2359766Sjlemon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2459766Sjlemon * SUCH DAMAGE.
2559766Sjlemon *
2659766Sjlemon *	$FreeBSD: head/lib/libstand/readdir.c 59766 2000-04-29 20:47:10Z jlemon $
2759766Sjlemon */
2859766Sjlemon
2959766Sjlemon#include <sys/param.h>
3059766Sjlemon#include "stand.h"
3159766Sjlemon
3259766Sjlemonstruct dirent *
3359766Sjlemonreaddirfd(int fd)
3459766Sjlemon{
3559766Sjlemon	static struct dirent dir;		/* XXX not thread safe */
3659766Sjlemon	struct open_file *f = &files[fd];
3759766Sjlemon
3859766Sjlemon	if ((unsigned)fd >= SOPEN_MAX || !(f->f_flags & F_READ)) {
3959766Sjlemon		errno = EBADF;
4059766Sjlemon		return (NULL);
4159766Sjlemon	}
4259766Sjlemon	if (f->f_flags & F_RAW) {
4359766Sjlemon		errno = EIO;
4459766Sjlemon		return (NULL);
4559766Sjlemon	}
4659766Sjlemon	errno = (f->f_ops->fo_readdir)(f, &dir);
4759766Sjlemon	if (errno)
4859766Sjlemon		return (NULL);
4959766Sjlemon	return (&dir);
5059766Sjlemon}
51