1 /* Copyright (C) 1993-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
25 #include <sys/types.h>
31 #include <not-cancel.h>
32 #include "dirstream.h"
35 /* Open a directory stream on a file descriptor in Hurd internal form.
36 We do no checking here on the descriptor. */
38 _hurd_fd_opendir (struct hurd_fd
*d
)
48 dirp
= (DIR *) malloc (sizeof (DIR));
52 /* Set the descriptor to close on exec. */
54 __spin_lock (&d
->port
.lock
);
55 d
->flags
|= FD_CLOEXEC
;
56 __spin_unlock (&d
->port
.lock
);
60 dirp
->__data
= dirp
->__ptr
= NULL
;
61 dirp
->__entry_data
= dirp
->__entry_ptr
= 0;
62 dirp
->__allocation
= 0;
65 __libc_lock_init (dirp
->__lock
);
72 __opendirat (int dfd
, const char *name
)
76 /* POSIX.1-1990 says an empty name gets ENOENT;
77 but `open' might like it fine. */
82 int flags
= O_RDONLY
| O_NONBLOCK
| O_DIRECTORY
| O_CLOEXEC
;
85 assert (dfd
== AT_FDCWD
);
86 fd
= __open_nocancel (name
, flags
);
88 fd
= __openat_nocancel (dfd
, name
, flags
);
93 /* Extract the pointer to the descriptor structure. */
94 DIR *dirp
= _hurd_fd_opendir (_hurd_fd_get (fd
));
102 /* Open a directory stream on NAME. */
104 __opendir (const char *name
)
107 return __opendirat (AT_FDCWD
, name
);
111 /* POSIX.1-1990 says an empty name gets ENOENT;
112 but `open' might like it fine. */
113 __set_errno (ENOENT
);
117 int fd
= __open (name
, O_RDONLY
| O_NONBLOCK
| O_DIRECTORY
);
121 /* Extract the pointer to the descriptor structure. */
122 DIR *dirp
= _hurd_fd_opendir (_hurd_fd_get (fd
));
129 weak_alias (__opendir
, opendir
)