]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/PosixLib/Gen/opendir.c
4 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 Copyright (c) 1983, 1993
14 The Regents of the University of California. All rights reserved.
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions
19 1. Redistributions of source code must retain the above copyright
20 notice, this list of conditions and the following disclaimer.
21 2. Redistributions in binary form must reproduce the above copyright
22 notice, this list of conditions and the following disclaimer in the
23 documentation and/or other materials provided with the distribution.
24 3. Neither the name of the University nor the names of its contributors
25 may be used to endorse or promote products derived from this software
26 without specific prior written permission.
28 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 NetBSD: opendir.c,v 1.33 2008/01/10 09:49:04 elad Exp
41 opendir.c 8.7 (Berkeley) 12/10/94
43 #include <sys/cdefs.h>
45 #include <namespace.h>
46 #include <reentrant.h>
48 #include <sys/param.h>
49 //#include <sys/mount.h>
60 #define MAXITERATIONS 100
66 opendir(const char *name
)
68 _DIAGASSERT(name
!= NULL
);
70 return (__opendir2(name
, DTF_HIDEW
|DTF_NODUP
));
74 __opendir2(const char *name
, int flags
)
82 _DIAGASSERT(name
!= NULL
);
84 if ((fd
= open(name
, O_RDONLY
| O_NONBLOCK
, 0)) == -1 ||
85 fcntl(fd
, F_SETFD
, FD_CLOEXEC
) == -1)
87 if (fstat(fd
, &sb
) || !S_ISDIR(sb
.st_mode
)) {
91 if ((dirp
= (DIR *)malloc(sizeof(DIR))) == NULL
)
96 * If the machine's page size is an exact multiple of DIRBLKSIZ,
97 * use a buffer that is cluster boundary aligned.
98 * Hopefully this can be a big win someday by allowing page trades
99 * to user space to be done by getdirentries()
104 dirp
->dd_buf
= malloc((size_t)dirp
->dd_len
);
105 if (dirp
->dd_buf
== NULL
)
108 flags
&= ~DTF_REWIND
;
112 dirp
->dd_flags
= flags
;
115 * Set up seek point for rewinddir.
119 if ((dirp
->dd_lock
= malloc(sizeof(mutex_t
))) == NULL
)
121 mutex_init((mutex_t
*)dirp
->dd_lock
, NULL
);
124 dirp
->dd_internal
= NULL
;
128 if (dirp
&& dirp
->dd_buf
)