]>
Commit | Line | Data |
---|---|---|
f96c3e9f | 1 | /* Copyright (C) 1993,1994,1995,1996,1997,1998,2001,2003,2005,2006 |
63be256a | 2 | Free Software Foundation, Inc. |
478b92f0 | 3 | This file is part of the GNU C Library. |
28f540f4 | 4 | |
478b92f0 | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
28f540f4 | 9 | |
478b92f0 UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
28f540f4 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
28f540f4 | 18 | |
28f540f4 RM |
19 | #include <errno.h> |
20 | #include <limits.h> | |
21 | #include <stddef.h> | |
22 | #include <stdlib.h> | |
8a0746ae | 23 | #include <string.h> |
28f540f4 RM |
24 | #include <dirent.h> |
25 | #include <fcntl.h> | |
26 | #include <sys/types.h> | |
27 | #include <sys/stat.h> | |
28 | #include <unistd.h> | |
29 | #include <stdio.h> | |
30 | #include <hurd.h> | |
f0bf9cb9 | 31 | #include <hurd/fd.h> |
9e865ade | 32 | #include "dirstream.h" |
28f540f4 RM |
33 | |
34 | ||
63be256a RM |
35 | /* Open a directory stream on a file descriptor in Hurd internal form. |
36 | We do no checking here on the descriptor. */ | |
37 | DIR * | |
38 | _hurd_fd_opendir (struct hurd_fd *d) | |
39 | { | |
40 | DIR *dirp; | |
41 | ||
42 | if (d == NULL) | |
43 | { | |
44 | errno = EBADF; | |
45 | return NULL; | |
46 | } | |
47 | ||
48 | dirp = (DIR *) malloc (sizeof (DIR)); | |
49 | if (dirp == NULL) | |
50 | return NULL; | |
51 | ||
52 | /* Set the descriptor to close on exec. */ | |
53 | __spin_lock (&d->port.lock); | |
54 | d->flags |= FD_CLOEXEC; | |
55 | __spin_unlock (&d->port.lock); | |
56 | ||
57 | dirp->__fd = d; | |
58 | dirp->__data = dirp->__ptr = NULL; | |
59 | dirp->__entry_data = dirp->__entry_ptr = 0; | |
60 | dirp->__allocation = 0; | |
61 | dirp->__size = 0; | |
62 | ||
63 | __libc_lock_init (dirp->__lock); | |
64 | ||
65 | return dirp; | |
66 | } | |
67 | ||
68 | ||
a334319f | 69 | /* Open a directory stream on NAME. */ |
28f540f4 | 70 | DIR * |
a334319f | 71 | __opendir (const char *name) |
28f540f4 | 72 | { |
a334319f | 73 | if (name[0] == '\0') |
8db34fe1 | 74 | { |
a334319f UD |
75 | /* POSIX.1-1990 says an empty name gets ENOENT; |
76 | but `open' might like it fine. */ | |
77 | __set_errno (ENOENT); | |
8db34fe1 RM |
78 | return NULL; |
79 | } | |
80 | ||
f96c3e9f | 81 | int fd = __open (name, O_RDONLY | O_NONBLOCK | O_DIRECTORY); |
a334319f UD |
82 | if (fd < 0) |
83 | return NULL; | |
84 | ||
a334319f | 85 | /* Extract the pointer to the descriptor structure. */ |
f96c3e9f | 86 | DIR *dirp = _hurd_fd_opendir (_hurd_fd_get (fd)); |
63be256a RM |
87 | if (dirp == NULL) |
88 | __close (fd); | |
28f540f4 RM |
89 | |
90 | return dirp; | |
91 | } | |
23396375 | 92 | weak_alias (__opendir, opendir) |