Add fdopendir(), from Solaris/Linux.

This commit is contained in:
ad 2008-12-05 13:08:53 +00:00
parent 0ff35ddc5a
commit 117c67b2f2
6 changed files with 57 additions and 18 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.1215 2008/11/24 16:05:21 joerg Exp $ # $NetBSD: mi,v 1.1216 2008/12/05 13:08:53 ad Exp $
# #
# Note: don't delete entries from here - mark them as "obsolete" instead. # Note: don't delete entries from here - mark them as "obsolete" instead.
# #
@ -5292,6 +5292,7 @@
./usr/share/man/cat3/fabsf.0 comp-c-catman .cat ./usr/share/man/cat3/fabsf.0 comp-c-catman .cat
./usr/share/man/cat3/fclose.0 comp-c-catman .cat ./usr/share/man/cat3/fclose.0 comp-c-catman .cat
./usr/share/man/cat3/fdopen.0 comp-c-catman .cat ./usr/share/man/cat3/fdopen.0 comp-c-catman .cat
./usr/share/man/cat3/fdopendir.0 comp-c-catman .cat
./usr/share/man/cat3/feof.0 comp-c-catman .cat ./usr/share/man/cat3/feof.0 comp-c-catman .cat
./usr/share/man/cat3/ferror.0 comp-c-catman .cat ./usr/share/man/cat3/ferror.0 comp-c-catman .cat
./usr/share/man/cat3/fetch.0 comp-c-catman .cat ./usr/share/man/cat3/fetch.0 comp-c-catman .cat
@ -15839,6 +15840,7 @@
./usr/share/man/man3/fabsf.3 comp-c-man .man ./usr/share/man/man3/fabsf.3 comp-c-man .man
./usr/share/man/man3/fclose.3 comp-c-man .man ./usr/share/man/man3/fclose.3 comp-c-man .man
./usr/share/man/man3/fdopen.3 comp-c-man .man ./usr/share/man/man3/fdopen.3 comp-c-man .man
./usr/share/man/man3/fdopendir.3 comp-c-man .man
./usr/share/man/man3/feof.3 comp-c-man .man ./usr/share/man/man3/feof.3 comp-c-man .man
./usr/share/man/man3/ferror.3 comp-c-man .man ./usr/share/man/man3/ferror.3 comp-c-man .man
./usr/share/man/man3/fetch.3 comp-c-man .man ./usr/share/man/man3/fetch.3 comp-c-man .man

View File

@ -1,4 +1,4 @@
/* $NetBSD: dirent.h,v 1.30 2008/01/09 20:55:03 christos Exp $ */ /* $NetBSD: dirent.h,v 1.31 2008/12/05 13:08:53 ad Exp $ */
/*- /*-
* Copyright (c) 1989, 1993 * Copyright (c) 1989, 1993
@ -98,6 +98,7 @@ long telldir(DIR *);
#endif /* defined(_NETBSD_SOURCE) || defined(_XOPEN_SOURCE) */ #endif /* defined(_NETBSD_SOURCE) || defined(_XOPEN_SOURCE) */
#if defined(_NETBSD_SOURCE) #if defined(_NETBSD_SOURCE)
#ifndef __LIBC12_SOURCE__ #ifndef __LIBC12_SOURCE__
DIR *fdopendir(int);
DIR *__opendir2(const char *, int) __RENAME(__opendir230); DIR *__opendir2(const char *, int) __RENAME(__opendir230);
int scandir(const char *, struct dirent ***, int scandir(const char *, struct dirent ***,
int (*)(const struct dirent *), int (*)(const void *, const void *)) int (*)(const struct dirent *), int (*)(const void *, const void *))

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.inc,v 1.164 2008/11/20 23:50:08 matt Exp $ # $NetBSD: Makefile.inc,v 1.165 2008/12/05 13:08:53 ad Exp $
# from: @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 # from: @(#)Makefile.inc 8.6 (Berkeley) 5/4/95
# gen sources # gen sources
@ -81,7 +81,8 @@ MLINKS+=cpuset.3 cpuset_create.3 cpuset.3 cpuset_destroy.3 \
cpuset.3 cpuset_isset.3 cpuset.3 cpuset_size.3 cpuset.3 cpuset_isset.3 cpuset.3 cpuset_size.3
MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \ MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \
directory.3 readdir.3 directory.3 readdir_r.3 directory.3 \ directory.3 readdir.3 directory.3 readdir_r.3 directory.3 \
rewinddir.3 directory.3 seekdir.3 directory.3 telldir.3 rewinddir.3 directory.3 seekdir.3 directory.3 telldir.3 \
directory.3 fdopendir.3
MLINKS+=endutxent.3 getutxent.3 endutxent.3 getutxid.3 \ MLINKS+=endutxent.3 getutxent.3 endutxent.3 getutxid.3 \
endutxent.3 getutxline.3 endutxent.3 pututxline.3 \ endutxent.3 getutxline.3 endutxent.3 pututxline.3 \
endutxent.3 setutxent.3 endutxent.3 setutxent.3

View File

@ -1,4 +1,4 @@
.\" $NetBSD: directory.3,v 1.26 2006/05/18 15:30:36 christos Exp $ .\" $NetBSD: directory.3,v 1.27 2008/12/05 13:08:53 ad Exp $
.\" .\"
.\" Copyright (c) 1983, 1991, 1993 .\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -33,6 +33,7 @@
.Dt DIRECTORY 3 .Dt DIRECTORY 3
.Os .Os
.Sh NAME .Sh NAME
.Nm fdopendir ,
.Nm opendir , .Nm opendir ,
.Nm readdir , .Nm readdir ,
.Nm readdir_r , .Nm readdir_r ,
@ -47,6 +48,8 @@
.Sh SYNOPSIS .Sh SYNOPSIS
.In dirent.h .In dirent.h
.Ft DIR * .Ft DIR *
.Fn fdopendir "int fd"
.Ft DIR *
.Fn opendir "const char *filename" .Fn opendir "const char *filename"
.Ft struct dirent * .Ft struct dirent *
.Fn readdir "DIR *dirp" .Fn readdir "DIR *dirp"
@ -65,14 +68,23 @@
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Fn opendir .Fn opendir
function function opens the directory named by
opens the directory named by .Fa filename
.Fa filename , and associates a
associates a
.Em directory stream .Em directory stream
with it with it.
and .Pp
returns a pointer to be used to identify the The
.Fn fdopendir
function associates a
.Em directory stream
with the directory file descriptor
.Fa fd .
The file descriptor
.Fa fd
must not be used further by the caller in any way.
.Pp
Both functions return a pointer to be used to identify the
.Em directory stream .Em directory stream
in subsequent operations. in subsequent operations.
The pointer The pointer

View File

@ -1,4 +1,4 @@
/* $NetBSD: opendir.c,v 1.33 2008/01/10 09:49:04 elad Exp $ */ /* $NetBSD: opendir.c,v 1.34 2008/12/05 13:08:53 ad Exp $ */
/* /*
* Copyright (c) 1983, 1993 * Copyright (c) 1983, 1993
@ -34,13 +34,14 @@
#if 0 #if 0
static char sccsid[] = "@(#)opendir.c 8.7 (Berkeley) 12/10/94"; static char sccsid[] = "@(#)opendir.c 8.7 (Berkeley) 12/10/94";
#else #else
__RCSID("$NetBSD: opendir.c,v 1.33 2008/01/10 09:49:04 elad Exp $"); __RCSID("$NetBSD: opendir.c,v 1.34 2008/12/05 13:08:53 ad Exp $");
#endif #endif
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include "namespace.h" #include "namespace.h"
#include "reentrant.h" #include "reentrant.h"
#include "extern.h" #include "extern.h"
#include <sys/param.h> #include <sys/param.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -57,6 +58,10 @@ __RCSID("$NetBSD: opendir.c,v 1.33 2008/01/10 09:49:04 elad Exp $");
#define MAXITERATIONS 100 #define MAXITERATIONS 100
static DIR *__opendir_common(int, const char *, int);
__weak_alias(fdopendir,_fdopendir)
/* /*
* Open a directory. * Open a directory.
*/ */
@ -72,8 +77,26 @@ opendir(const char *name)
DIR * DIR *
__opendir2(const char *name, int flags) __opendir2(const char *name, int flags)
{ {
DIR *dirp = NULL;
int fd; int fd;
if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1)
return NULL;
return __opendir_common(fd, name, flags);
}
#ifndef __LIBC12_SOURCE__
DIR *
_fdopendir(int fd)
{
return __opendir_common(fd, NULL, DTF_HIDEW|DTF_NODUP);
}
#endif
static DIR *
__opendir_common(int fd, const char *name, int flags)
{
DIR *dirp = NULL;
int serrno; int serrno;
struct stat sb; struct stat sb;
int pagesz; int pagesz;
@ -83,8 +106,7 @@ __opendir2(const char *name, int flags)
_DIAGASSERT(name != NULL); _DIAGASSERT(name != NULL);
if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1 || if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
goto error; goto error;
if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) { if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) {
errno = ENOTDIR; errno = ENOTDIR;

View File

@ -1,4 +1,4 @@
/* $NetBSD: namespace.h,v 1.135 2008/11/20 23:50:08 matt Exp $ */ /* $NetBSD: namespace.h,v 1.136 2008/12/05 13:08:53 ad Exp $ */
/*- /*-
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc. * Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@ -432,6 +432,7 @@
#define nsdispatch _nsdispatch #define nsdispatch _nsdispatch
#define offtime _offtime #define offtime _offtime
#define opendir _opendir #define opendir _opendir
#define fdopendir _fdopendir
#define openlog _openlog #define openlog _openlog
#define openlog_r _openlog_r #define openlog_r _openlog_r
#define pause _pause #define pause _pause