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 2784221Sdillon#include <sys/cdefs.h> 2884221Sdillon__FBSDID("$FreeBSD$"); 2984221Sdillon 3059766Sjlemon#include <sys/param.h> 3159766Sjlemon#include "stand.h" 3259766Sjlemon 3359766Sjlemonstruct dirent * 3459766Sjlemonreaddirfd(int fd) 3559766Sjlemon{ 3659766Sjlemon static struct dirent dir; /* XXX not thread safe */ 3759766Sjlemon struct open_file *f = &files[fd]; 3859766Sjlemon 3959766Sjlemon if ((unsigned)fd >= SOPEN_MAX || !(f->f_flags & F_READ)) { 4059766Sjlemon errno = EBADF; 4159766Sjlemon return (NULL); 4259766Sjlemon } 4359766Sjlemon if (f->f_flags & F_RAW) { 4459766Sjlemon errno = EIO; 4559766Sjlemon return (NULL); 4659766Sjlemon } 4759766Sjlemon errno = (f->f_ops->fo_readdir)(f, &dir); 4859766Sjlemon if (errno) 4959766Sjlemon return (NULL); 5059766Sjlemon return (&dir); 5159766Sjlemon} 52