summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgleb <gleb@FreeBSD.org>2012-05-19 12:44:27 +0000
committergleb <gleb@FreeBSD.org>2012-05-19 12:44:27 +0000
commit53af2dbdcaab2b0af0595c7972b876b8ef9e9ae6 (patch)
tree52b234943a3ae78c62d839ca39a00589e970906a
parent9409c11a935c0490bedd5a31b003a34bb8caea1f (diff)
downloadFreeBSD-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
-rw-r--r--include/dirent.h21
-rw-r--r--lib/libc/gen/Makefile.inc2
-rw-r--r--lib/libc/gen/Symbol.map1
-rw-r--r--lib/libc/gen/closedir.c1
-rw-r--r--lib/libc/gen/dirfd.c48
-rw-r--r--lib/libc/gen/fts-compat.c4
-rw-r--r--lib/libc/gen/fts.c4
-rw-r--r--lib/libc/gen/gen-private.h59
-rw-r--r--lib/libc/gen/getcwd.c10
-rw-r--r--lib/libc/gen/opendir.c1
-rw-r--r--lib/libc/gen/readdir.c1
-rw-r--r--lib/libc/gen/rewinddir.c1
-rw-r--r--lib/libc/gen/seekdir.c1
-rw-r--r--lib/libc/gen/telldir.c1
-rw-r--r--usr.sbin/cpucontrol/cpucontrol.c10
-rw-r--r--usr.sbin/lpr/common_source/common.c2
-rw-r--r--usr.sbin/newsyslog/newsyslog.c6
17 files changed, 139 insertions, 34 deletions
diff --git a/include/dirent.h b/include/dirent.h
index e3ef149..941a977 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -55,24 +55,8 @@
/* definitions for library routines operating on directories. */
#define DIRBLKSIZ 1024
-struct _telldir; /* see telldir.h */
-struct pthread_mutex;
-
-/* structure describing an open directory. */
-typedef 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 */
-} DIR;
-
-#define dirfd(dirp) ((dirp)->dd_fd)
+struct _dirdesc;
+typedef struct _dirdesc DIR;
/* flags for opendir2 */
#define DTF_HIDEW 0x0001 /* hide whiteout entries */
@@ -91,6 +75,7 @@ typedef void * DIR;
__BEGIN_DECLS
#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700
int alphasort(const struct dirent **, const struct dirent **);
+int dirfd(DIR *);
#endif
#if __BSD_VISIBLE
DIR *__opendir2(const char *, int);
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"
/*
diff --git a/usr.sbin/cpucontrol/cpucontrol.c b/usr.sbin/cpucontrol/cpucontrol.c
index 7477007..8738612 100644
--- a/usr.sbin/cpucontrol/cpucontrol.c
+++ b/usr.sbin/cpucontrol/cpucontrol.c
@@ -292,7 +292,7 @@ do_update(const char *dev)
int error;
struct ucode_handler *handler;
struct datadir *dir;
- DIR *dirfd;
+ DIR *dirp;
struct dirent *direntry;
char buf[MAXPATHLEN];
@@ -321,12 +321,12 @@ do_update(const char *dev)
* Process every image in specified data directories.
*/
SLIST_FOREACH(dir, &datadirs, next) {
- dirfd = opendir(dir->path);
- if (dirfd == NULL) {
+ dirp = opendir(dir->path);
+ if (dirp == NULL) {
WARNX(1, "skipping directory %s: not accessible", dir->path);
continue;
}
- while ((direntry = readdir(dirfd)) != NULL) {
+ while ((direntry = readdir(dirp)) != NULL) {
if (direntry->d_namlen == 0)
continue;
error = snprintf(buf, sizeof(buf), "%s/%s", dir->path,
@@ -340,7 +340,7 @@ do_update(const char *dev)
}
handler->update(dev, buf);
}
- error = closedir(dirfd);
+ error = closedir(dirp);
if (error != 0)
WARN(0, "closedir(%s)", dir->path);
}
diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c
index d28ac1f..819d7dd 100644
--- a/usr.sbin/lpr/common_source/common.c
+++ b/usr.sbin/lpr/common_source/common.c
@@ -130,7 +130,7 @@ getq(const struct printer *pp, struct jobqueue *(*namelist[]))
seteuid(uid);
return (-1);
}
- if (fstat(dirp->dd_fd, &stbuf) < 0)
+ if (fstat(dirfd(dirp), &stbuf) < 0)
goto errdone;
seteuid(uid);
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c
index 7ebdddc..227ea00 100644
--- a/usr.sbin/newsyslog/newsyslog.c
+++ b/usr.sbin/newsyslog/newsyslog.c
@@ -1451,7 +1451,7 @@ static void
delete_oldest_timelog(const struct conf_entry *ent, const char *archive_dir)
{
char *logfname, *s, *dir, errbuf[80];
- int dirfd, i, logcnt, max_logcnt, valid;
+ int dir_fd, i, logcnt, max_logcnt, valid;
struct oldlog_entry *oldlogs;
size_t logfname_len;
struct dirent *dp;
@@ -1486,7 +1486,7 @@ delete_oldest_timelog(const struct conf_entry *ent, const char *archive_dir)
/* First we create a 'list' of all archived logfiles */
if ((dirp = opendir(dir)) == NULL)
err(1, "Cannot open log directory '%s'", dir);
- dirfd = dirfd(dirp);
+ dir_fd = dirfd(dirp);
while ((dp = readdir(dirp)) != NULL) {
if (dp->d_type != DT_REG)
continue;
@@ -1578,7 +1578,7 @@ delete_oldest_timelog(const struct conf_entry *ent, const char *archive_dir)
if (noaction)
printf("\trm -f %s/%s\n", dir,
oldlogs[i].fname);
- else if (unlinkat(dirfd, oldlogs[i].fname, 0) != 0) {
+ else if (unlinkat(dir_fd, oldlogs[i].fname, 0) != 0) {
snprintf(errbuf, sizeof(errbuf),
"Could not delet old logfile '%s'",
oldlogs[i].fname);
OpenPOWER on IntegriCloud