1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
26 * open|close directory stream
28 * POSIX compatible directory stream access routines:
30 * #include <sys/types.h>
33 * NOTE: readdir() returns a pointer to struct dirent
44 static const char id_dir
[] = "\n@(#)$Id: directory (AT&T Research) 1993-04-01 $\0\n";
46 static DIR* freedirp
; /* always keep one dirp */
49 opendir(register const char* path
)
51 register DIR* dirp
= 0;
55 if ((fd
= open(path
, O_RDONLY
)) < 0) return(0);
56 if (fstat(fd
, &st
) < 0 ||
57 !S_ISDIR(st
.st_mode
) && (errno
= ENOTDIR
) ||
58 fcntl(fd
, F_SETFD
, FD_CLOEXEC
) ||
59 !(dirp
= freedirp
? freedirp
:
60 #if defined(_DIR_PRIVATE_) || _ptr_dd_buf
61 newof(0, DIR, 1, DIRBLKSIZ
)
70 if (!freedirp
) freedirp
= dirp
;
77 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
78 #if defined(_DIR_PRIVATE_) || _ptr_dd_buf
79 dirp
->dd_buf
= (void*)((char*)dirp
+ sizeof(DIR));
85 closedir(register DIR* dirp
)
90 if (!freedirp
) freedirp
= dirp
;