Add fdopendir(), from Solaris/Linux.
This commit is contained in:
parent
0ff35ddc5a
commit
117c67b2f2
@ -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.
|
||||
#
|
||||
@ -5292,6 +5292,7 @@
|
||||
./usr/share/man/cat3/fabsf.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/fdopendir.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/fetch.0 comp-c-catman .cat
|
||||
@ -15839,6 +15840,7 @@
|
||||
./usr/share/man/man3/fabsf.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/fdopendir.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/fetch.3 comp-c-man .man
|
||||
|
@ -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
|
||||
@ -98,6 +98,7 @@ long telldir(DIR *);
|
||||
#endif /* defined(_NETBSD_SOURCE) || defined(_XOPEN_SOURCE) */
|
||||
#if defined(_NETBSD_SOURCE)
|
||||
#ifndef __LIBC12_SOURCE__
|
||||
DIR *fdopendir(int);
|
||||
DIR *__opendir2(const char *, int) __RENAME(__opendir230);
|
||||
int scandir(const char *, struct dirent ***,
|
||||
int (*)(const struct dirent *), int (*)(const void *, const void *))
|
||||
|
@ -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
|
||||
|
||||
# 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
|
||||
MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.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 \
|
||||
endutxent.3 getutxline.3 endutxent.3 pututxline.3 \
|
||||
endutxent.3 setutxent.3
|
||||
|
@ -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
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -33,6 +33,7 @@
|
||||
.Dt DIRECTORY 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm fdopendir ,
|
||||
.Nm opendir ,
|
||||
.Nm readdir ,
|
||||
.Nm readdir_r ,
|
||||
@ -47,6 +48,8 @@
|
||||
.Sh SYNOPSIS
|
||||
.In dirent.h
|
||||
.Ft DIR *
|
||||
.Fn fdopendir "int fd"
|
||||
.Ft DIR *
|
||||
.Fn opendir "const char *filename"
|
||||
.Ft struct dirent *
|
||||
.Fn readdir "DIR *dirp"
|
||||
@ -65,14 +68,23 @@
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn opendir
|
||||
function
|
||||
opens the directory named by
|
||||
.Fa filename ,
|
||||
associates a
|
||||
function opens the directory named by
|
||||
.Fa filename
|
||||
and associates a
|
||||
.Em directory stream
|
||||
with it
|
||||
and
|
||||
returns a pointer to be used to identify the
|
||||
with it.
|
||||
.Pp
|
||||
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
|
||||
in subsequent operations.
|
||||
The pointer
|
||||
|
@ -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
|
||||
@ -34,13 +34,14 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)opendir.c 8.7 (Berkeley) 12/10/94";
|
||||
#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 /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include "reentrant.h"
|
||||
#include "extern.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.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
|
||||
|
||||
static DIR *__opendir_common(int, const char *, int);
|
||||
|
||||
__weak_alias(fdopendir,_fdopendir)
|
||||
|
||||
/*
|
||||
* Open a directory.
|
||||
*/
|
||||
@ -72,8 +77,26 @@ opendir(const char *name)
|
||||
DIR *
|
||||
__opendir2(const char *name, int flags)
|
||||
{
|
||||
DIR *dirp = NULL;
|
||||
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;
|
||||
struct stat sb;
|
||||
int pagesz;
|
||||
@ -83,8 +106,7 @@ __opendir2(const char *name, int flags)
|
||||
|
||||
_DIAGASSERT(name != NULL);
|
||||
|
||||
if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1 ||
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
|
||||
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
|
||||
goto error;
|
||||
if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) {
|
||||
errno = ENOTDIR;
|
||||
|
@ -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.
|
||||
@ -432,6 +432,7 @@
|
||||
#define nsdispatch _nsdispatch
|
||||
#define offtime _offtime
|
||||
#define opendir _opendir
|
||||
#define fdopendir _fdopendir
|
||||
#define openlog _openlog
|
||||
#define openlog_r _openlog_r
|
||||
#define pause _pause
|
||||
|
Loading…
Reference in New Issue
Block a user