opendir.c (69656) | opendir.c (69841) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * |
33 * $FreeBSD: head/lib/libc/gen/opendir.c 69656 2000-12-06 03:15:49Z deischen $ | 33 * $FreeBSD: head/lib/libc/gen/opendir.c 69841 2000-12-11 04:00:36Z deischen $ |
34 */ 35 36#if defined(LIBC_SCCS) && !defined(lint) 37static char sccsid[] = "@(#)opendir.c 8.8 (Berkeley) 5/1/95"; 38#endif /* LIBC_SCCS and not lint */ 39 40#include <sys/param.h> 41#include <sys/mount.h> 42#include <sys/stat.h> 43 44#include <dirent.h> 45#include <errno.h> 46#include <fcntl.h> 47#include <stdlib.h> 48#include <unistd.h> 49 | 34 */ 35 36#if defined(LIBC_SCCS) && !defined(lint) 37static char sccsid[] = "@(#)opendir.c 8.8 (Berkeley) 5/1/95"; 38#endif /* LIBC_SCCS and not lint */ 39 40#include <sys/param.h> 41#include <sys/mount.h> 42#include <sys/stat.h> 43 44#include <dirent.h> 45#include <errno.h> 46#include <fcntl.h> 47#include <stdlib.h> 48#include <unistd.h> 49 |
50#include "telldir.h" 51 |
|
50/* 51 * Open a directory. 52 */ 53DIR * 54opendir(name) 55 const char *name; 56{ 57 --- 27 unchanged lines hidden (view full) --- 85 dirp = NULL; 86 if (fstat(fd, &statb) != 0) 87 goto fail; 88 if (!S_ISDIR(statb.st_mode)) { 89 errno = ENOTDIR; 90 goto fail; 91 } 92 if (_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 || | 52/* 53 * Open a directory. 54 */ 55DIR * 56opendir(name) 57 const char *name; 58{ 59 --- 27 unchanged lines hidden (view full) --- 87 dirp = NULL; 88 if (fstat(fd, &statb) != 0) 89 goto fail; 90 if (!S_ISDIR(statb.st_mode)) { 91 errno = ENOTDIR; 92 goto fail; 93 } 94 if (_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 || |
93 (dirp = malloc(sizeof(DIR))) == NULL) | 95 (dirp = malloc(sizeof(DIR) + sizeof(struct _telldir))) == NULL) |
94 goto fail; 95 | 96 goto fail; 97 |
98 dirp->dd_td = (void *)dirp + sizeof(DIR); 99 LIST_INIT(&dirp->dd_td->td_locq); 100 dirp->dd_td->td_loccnt = 0; 101 |
|
96 /* 97 * Use the system page size if that is a multiple of DIRBLKSIZ. 98 * Hopefully this can be a big win someday by allowing page 99 * trades to user space to be done by getdirentries(). 100 */ 101 incr = getpagesize(); 102 if ((incr % DIRBLKSIZ) != 0) 103 incr = DIRBLKSIZ; --- 150 unchanged lines hidden (view full) --- 254 goto fail; 255 dirp->dd_seek = 0; 256 flags &= ~DTF_REWIND; 257 } 258 259 dirp->dd_loc = 0; 260 dirp->dd_fd = fd; 261 dirp->dd_flags = flags; | 102 /* 103 * Use the system page size if that is a multiple of DIRBLKSIZ. 104 * Hopefully this can be a big win someday by allowing page 105 * trades to user space to be done by getdirentries(). 106 */ 107 incr = getpagesize(); 108 if ((incr % DIRBLKSIZ) != 0) 109 incr = DIRBLKSIZ; --- 150 unchanged lines hidden (view full) --- 260 goto fail; 261 dirp->dd_seek = 0; 262 flags &= ~DTF_REWIND; 263 } 264 265 dirp->dd_loc = 0; 266 dirp->dd_fd = fd; 267 dirp->dd_flags = flags; |
262 dirp->dd_loccnt = 0; 263 LIST_INIT(&dirp->dd_locq); | |
264 265 /* 266 * Set up seek point for rewinddir. 267 */ 268 dirp->dd_rewind = telldir(dirp); 269 270 return (dirp); 271 272fail: 273 saved_errno = errno; 274 free(dirp); 275 (void)_close(fd); 276 errno = saved_errno; 277 return (NULL); 278} | 268 269 /* 270 * Set up seek point for rewinddir. 271 */ 272 dirp->dd_rewind = telldir(dirp); 273 274 return (dirp); 275 276fail: 277 saved_errno = errno; 278 free(dirp); 279 (void)_close(fd); 280 errno = saved_errno; 281 return (NULL); 282} |