Deleted Added
full compact
opendir.c (39327) opendir.c (55837)
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

--- 15 unchanged lines hidden (view full) ---

24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
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.
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

--- 15 unchanged lines hidden (view full) ---

24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
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 55837 2000-01-12 09:23:48Z jasone $
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char sccsid[] = "@(#)opendir.c 8.8 (Berkeley) 5/1/95";
36#endif /* LIBC_SCCS and not lint */
37
38#include <sys/param.h>
39#include <sys/mount.h>

--- 33 unchanged lines hidden (view full) ---

73 * harmful. fstat() after open because the file may have changed.
74 */
75 if (stat(name, &statb) != 0)
76 return (NULL);
77 if (!S_ISDIR(statb.st_mode)) {
78 errno = ENOTDIR;
79 return (NULL);
80 }
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>

--- 33 unchanged lines hidden (view full) ---

75 * harmful. fstat() after open because the file may have changed.
76 */
77 if (stat(name, &statb) != 0)
78 return (NULL);
79 if (!S_ISDIR(statb.st_mode)) {
80 errno = ENOTDIR;
81 return (NULL);
82 }
81 if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1)
83 if ((fd = _libc_open(name, O_RDONLY | O_NONBLOCK)) == -1)
82 return (NULL);
83 dirp = NULL;
84 if (fstat(fd, &statb) != 0)
85 goto fail;
86 if (!S_ISDIR(statb.st_mode)) {
87 errno = ENOTDIR;
88 goto fail;
89 }
84 return (NULL);
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 }
90 if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 ||
92 if (_libc_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 ||
91 (dirp = malloc(sizeof(DIR))) == NULL)
92 goto fail;
93
94 /*
95 * Use the system page size if that is a multiple of DIRBLKSIZ.
96 * Hopefully this can be a big win someday by allowing page
97 * trades to user space to be done by getdirentries().
98 */

--- 57 unchanged lines hidden (view full) ---

156 /*
157 * Re-open the directory.
158 * This has the effect of rewinding back to the
159 * top of the union stack and is needed by
160 * programs which plan to fchdir to a descriptor
161 * which has also been read -- see fts.c.
162 */
163 if (flags & DTF_REWIND) {
93 (dirp = malloc(sizeof(DIR))) == NULL)
94 goto fail;
95
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 */

--- 57 unchanged lines hidden (view full) ---

158 /*
159 * Re-open the directory.
160 * This has the effect of rewinding back to the
161 * top of the union stack and is needed by
162 * programs which plan to fchdir to a descriptor
163 * which has also been read -- see fts.c.
164 */
165 if (flags & DTF_REWIND) {
164 (void) close(fd);
165 if ((fd = open(name, O_RDONLY)) == -1) {
166 (void)_libc_close(fd);
167 if ((fd = _libc_open(name, O_RDONLY)) == -1) {
166 saved_errno = errno;
167 free(buf);
168 free(dirp);
169 errno = saved_errno;
170 return (NULL);
171 }
172 }
173

--- 89 unchanged lines hidden (view full) ---

263 */
264 dirp->dd_rewind = telldir(dirp);
265
266 return (dirp);
267
268fail:
269 saved_errno = errno;
270 free(dirp);
168 saved_errno = errno;
169 free(buf);
170 free(dirp);
171 errno = saved_errno;
172 return (NULL);
173 }
174 }
175

--- 89 unchanged lines hidden (view full) ---

265 */
266 dirp->dd_rewind = telldir(dirp);
267
268 return (dirp);
269
270fail:
271 saved_errno = errno;
272 free(dirp);
271 (void) close(fd);
273 (void)_libc_close(fd);
272 errno = saved_errno;
273 return (NULL);
274}
274 errno = saved_errno;
275 return (NULL);
276}