1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is distributed in the hope that it will be useful, but
5 WITHOUT ANY WARRANTY. No author or distributor accepts responsibility for
6 the consequences of using it or for whether it serves any particular
7 purpose or works at all, unless he says so in writing. Refer to the GNU
8 C Library General Public License (in the file COPYING) for full details.
10 Everyone is granted permission to copy, modify and redistribute
11 the GNU C Library, but only under the conditions described in the
12 GNU C Library General Public License. Among other things, this notice
13 must not be changed and a copy of the license must be included. */
22 #include <sys/types.h>
27 /* Open a directory stream on NAME. */
29 DEFUN(opendir, (name), CONST char *name)
35 fd = __open(name, O_RDONLY);
40 int flags = FD_CLOEXEC;
41 if (fcntl(fd, F_SETFD, &flags) < 0)
45 dirp = (DIR *) malloc(sizeof(DIR) + NAME_MAX);
54 if (__fstat(fd, &statbuf) < 0 || statbuf.st_blksize < sizeof(struct direct))
55 dirp->__allocation = sizeof(struct direct);
57 dirp->__allocation = statbuf.st_blksize;
58 dirp->__data = (char *) malloc(dirp->__allocation);
59 if (dirp->__data == NULL)