diff options
author | gleb <gleb@FreeBSD.org> | 2012-05-19 12:44:27 +0000 |
---|---|---|
committer | gleb <gleb@FreeBSD.org> | 2012-05-19 12:44:27 +0000 |
commit | 53af2dbdcaab2b0af0595c7972b876b8ef9e9ae6 (patch) | |
tree | 52b234943a3ae78c62d839ca39a00589e970906a /lib/libc | |
parent | 9409c11a935c0490bedd5a31b003a34bb8caea1f (diff) | |
download | FreeBSD-src-53af2dbdcaab2b0af0595c7972b876b8ef9e9ae6.zip FreeBSD-src-53af2dbdcaab2b0af0595c7972b876b8ef9e9ae6.tar.gz |
Hide DIR definition by making it an opaque struct typedef.
Introduce dirfd() libc exported symbol replacing macro with same name,
preserve _dirfd() macro for internal use.
Replace dirp->dd_fd with dirfd() call. Avoid using dirfd as variable
name to prevent shadowing global symbol.
Sponsored by: Google Summer Of Code 2011
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/Makefile.inc | 2 | ||||
-rw-r--r-- | lib/libc/gen/Symbol.map | 1 | ||||
-rw-r--r-- | lib/libc/gen/closedir.c | 1 | ||||
-rw-r--r-- | lib/libc/gen/dirfd.c | 48 | ||||
-rw-r--r-- | lib/libc/gen/fts-compat.c | 4 | ||||
-rw-r--r-- | lib/libc/gen/fts.c | 4 | ||||
-rw-r--r-- | lib/libc/gen/gen-private.h | 59 | ||||
-rw-r--r-- | lib/libc/gen/getcwd.c | 10 | ||||
-rw-r--r-- | lib/libc/gen/opendir.c | 1 | ||||
-rw-r--r-- | lib/libc/gen/readdir.c | 1 | ||||
-rw-r--r-- | lib/libc/gen/rewinddir.c | 1 | ||||
-rw-r--r-- | lib/libc/gen/seekdir.c | 1 | ||||
-rw-r--r-- | lib/libc/gen/telldir.c | 1 |
13 files changed, 127 insertions, 7 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 0362ce0..98e8183 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -9,7 +9,7 @@ SRCS+= __getosreldate.c __xuname.c \ _thread_init.c \ alarm.c arc4random.c assert.c aux.c basename.c check_utility_compat.c \ clock.c closedir.c confstr.c \ - crypt.c ctermid.c daemon.c devname.c dirname.c disklabel.c \ + crypt.c ctermid.c daemon.c devname.c dirfd.c dirname.c disklabel.c \ dlfcn.c drand48.c elf_utils.c erand48.c err.c errlst.c errno.c \ exec.c fdevname.c feature_present.c fmtcheck.c fmtmsg.c fnmatch.c \ fpclassify.c frexp.c fstab.c ftok.c fts.c fts-compat.c ftw.c \ diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map index d794c0a..356bee5 100644 --- a/lib/libc/gen/Symbol.map +++ b/lib/libc/gen/Symbol.map @@ -382,6 +382,7 @@ FBSD_1.2 { }; FBSD_1.3 { + dirfd; fdlopen; __FreeBSD_libc_enter_restricted_mode; getcontextx; diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c index 5db351b..4b520cc 100644 --- a/lib/libc/gen/closedir.c +++ b/lib/libc/gen/closedir.c @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" #include "libc_private.h" +#include "gen-private.h" #include "telldir.h" /* diff --git a/lib/libc/gen/dirfd.c b/lib/libc/gen/dirfd.c new file mode 100644 index 0000000..ecff700 --- /dev/null +++ b/lib/libc/gen/dirfd.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include "namespace.h" +#include <sys/param.h> + +#include <dirent.h> +#include "un-namespace.h" + +#include "gen-private.h" + +int +dirfd(DIR *dirp) +{ + + return (_dirfd(dirp)); +} diff --git a/lib/libc/gen/fts-compat.c b/lib/libc/gen/fts-compat.c index a6ddde4..6585416 100644 --- a/lib/libc/gen/fts-compat.c +++ b/lib/libc/gen/fts-compat.c @@ -52,6 +52,8 @@ __FBSDID("$FreeBSD$"); #include "fts-compat.h" #include "un-namespace.h" +#include "gen-private.h" + FTSENT *__fts_children_44bsd(FTS *, int); int __fts_close_44bsd(FTS *); void *__fts_get_clientptr_44bsd(FTS *); @@ -711,7 +713,7 @@ fts_build(sp, type) */ cderrno = 0; if (nlinks || type == BREAD) { - if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { + if (fts_safe_changedir(sp, cur, _dirfd(dirp), NULL)) { if (nlinks && type == BREAD) cur->fts_errno = errno; cur->fts_flags |= FTS_DONTCHDIR; diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 1344464..153b8da 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -52,6 +52,8 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include "un-namespace.h" +#include "gen-private.h" + static FTSENT *fts_alloc(FTS *, char *, size_t); static FTSENT *fts_build(FTS *, int); static void fts_lfree(FTSENT *); @@ -697,7 +699,7 @@ fts_build(FTS *sp, int type) */ cderrno = 0; if (nlinks || type == BREAD) { - if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { + if (fts_safe_changedir(sp, cur, _dirfd(dirp), NULL)) { if (nlinks && type == BREAD) cur->fts_errno = errno; cur->fts_flags |= FTS_DONTCHDIR; diff --git a/lib/libc/gen/gen-private.h b/lib/libc/gen/gen-private.h new file mode 100644 index 0000000..e8854ad --- /dev/null +++ b/lib/libc/gen/gen-private.h @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _GEN_PRIVATE_H_ +#define _GEN_PRIVATE_H_ + +struct _telldir; /* see telldir.h */ +struct pthread_mutex; + +/* + * Structure describing an open directory. + * + * NOTE. Change structure layout with care, at least dd_fd field has to + * remain unchanged to guarantee backward compatibility. + */ +struct _dirdesc { + int dd_fd; /* file descriptor associated with directory */ + long dd_loc; /* offset in current buffer */ + long dd_size; /* amount of data returned by getdirentries */ + char *dd_buf; /* data buffer */ + int dd_len; /* size of data buffer */ + long dd_seek; /* magic cookie returned by getdirentries */ + long dd_rewind; /* magic cookie for rewinding */ + int dd_flags; /* flags for readdir */ + struct pthread_mutex *dd_lock; /* lock */ + struct _telldir *dd_td; /* telldir position recording */ +}; + +#define _dirfd(dirp) ((dirp)->dd_fd) + +#endif /* !_GEN_PRIVATE_H_ */ diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c index c886dde..40feedf 100644 --- a/lib/libc/gen/getcwd.c +++ b/lib/libc/gen/getcwd.c @@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include "un-namespace.h" +#include "gen-private.h" + #define ISDOT(dp) \ (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) @@ -117,7 +119,7 @@ getcwd(pt, size) for (first = 1;; first = 0) { /* Stat the current level. */ - if (dir != NULL ? _fstat(dirfd(dir), &s) : lstat(".", &s)) + if (dir != NULL ? _fstat(_dirfd(dir), &s) : lstat(".", &s)) goto err; /* Save current node values. */ @@ -139,13 +141,13 @@ getcwd(pt, size) } /* Open and stat parent directory. */ - fd = _openat(dir != NULL ? dirfd(dir) : AT_FDCWD, + fd = _openat(dir != NULL ? _dirfd(dir) : AT_FDCWD, "..", O_RDONLY); if (fd == -1) goto err; if (dir) (void) closedir(dir); - if (!(dir = fdopendir(fd)) || _fstat(dirfd(dir), &s)) { + if (!(dir = fdopendir(fd)) || _fstat(_dirfd(dir), &s)) { _close(fd); goto err; } @@ -171,7 +173,7 @@ getcwd(pt, size) continue; /* Save the first error for later. */ - if (fstatat(dirfd(dir), dp->d_name, &s, + if (fstatat(_dirfd(dir), dp->d_name, &s, AT_SYMLINK_NOFOLLOW)) { if (!save_errno) save_errno = errno; diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index 3beead7..4366399 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include "un-namespace.h" +#include "gen-private.h" #include "telldir.h" static DIR * __opendir_common(int, const char *, int); diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c index b4b4c39..324870b 100644 --- a/lib/libc/gen/readdir.c +++ b/lib/libc/gen/readdir.c @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" #include "libc_private.h" +#include "gen-private.h" #include "telldir.h" /* diff --git a/lib/libc/gen/rewinddir.c b/lib/libc/gen/rewinddir.c index 45e450d..0eb091a 100644 --- a/lib/libc/gen/rewinddir.c +++ b/lib/libc/gen/rewinddir.c @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <dirent.h> +#include "gen-private.h" #include "telldir.h" void diff --git a/lib/libc/gen/seekdir.c b/lib/libc/gen/seekdir.c index 45ed6b5..e9851a7 100644 --- a/lib/libc/gen/seekdir.c +++ b/lib/libc/gen/seekdir.c @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" #include "libc_private.h" +#include "gen-private.h" #include "telldir.h" /* diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c index c217333..4954b97 100644 --- a/lib/libc/gen/telldir.c +++ b/lib/libc/gen/telldir.c @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" #include "libc_private.h" +#include "gen-private.h" #include "telldir.h" /* |