1 /* Copyright (C) 1993,94,95,96,97,98,2001,2003,2005
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 #include <sys/types.h>
33 #include "dirstream.h"
36 /* Open a directory stream on a file descriptor in Hurd internal form.
37 We do no checking here on the descriptor. */
39 _hurd_fd_opendir (struct hurd_fd
*d
)
49 dirp
= (DIR *) malloc (sizeof (DIR));
53 /* Set the descriptor to close on exec. */
54 __spin_lock (&d
->port
.lock
);
55 d
->flags
|= FD_CLOEXEC
;
56 __spin_unlock (&d
->port
.lock
);
59 dirp
->__data
= dirp
->__ptr
= NULL
;
60 dirp
->__entry_data
= dirp
->__entry_ptr
= 0;
61 dirp
->__allocation
= 0;
64 __libc_lock_init (dirp
->__lock
);
70 /* Open a directory stream on NAME. */
72 __opendir (const char *name
)
79 /* POSIX.1-1990 says an empty name gets ENOENT;
80 but `open' might like it fine. */
86 /* Append trailing slash to directory name to force ENOTDIR
87 if it's not a directory.
89 We open using the O_NONBLOCK flag so that a nondirectory with
90 blocking behavior (FIFO or device) gets ENOTDIR immediately
91 rather than waiting for the special file's open wakeup predicate. */
93 size_t len
= strlen (name
);
94 if (name
[len
- 1] == '/')
95 fd
= __open (name
, O_RDONLY
| O_NONBLOCK
);
99 memcpy (n
, name
, len
);
102 fd
= __open (n
, O_RDONLY
| O_NONBLOCK
);
108 /* Extract the pointer to the descriptor structure. */
109 dirp
= _hurd_fd_opendir (_hurd_fd_get (fd
));
115 weak_alias (__opendir
, opendir
)