2005-10-15 02:23:56 +00:00
|
|
|
/* Open a directory stream from a file descriptor. Hurd version.
|
2015-01-02 16:28:19 +00:00
|
|
|
Copyright (C) 2005-2015 Free Software Foundation, Inc.
|
2005-10-15 02:23:56 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2005-10-15 02:23:56 +00:00
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <hurd.h>
|
|
|
|
#include <hurd/fd.h>
|
2005-10-16 08:34:04 +00:00
|
|
|
#include <fcntl.h>
|
2005-10-15 02:23:56 +00:00
|
|
|
|
|
|
|
DIR *_hurd_fd_opendir (struct hurd_fd *d); /* opendir.c */
|
|
|
|
|
|
|
|
/* Open a directory stream on FD. */
|
|
|
|
DIR *
|
2006-02-12 21:41:44 +00:00
|
|
|
__fdopendir (int fd)
|
2005-10-15 02:23:56 +00:00
|
|
|
{
|
2005-10-16 08:34:04 +00:00
|
|
|
struct hurd_fd *d = _hurd_fd_get (fd);
|
2005-10-15 02:23:56 +00:00
|
|
|
|
|
|
|
if (d == NULL)
|
|
|
|
{
|
|
|
|
errno = EBADF;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure that it's a directory. */
|
|
|
|
error_t err = HURD_FD_PORT_USE
|
|
|
|
(d, ({
|
2006-03-05 11:38:04 +00:00
|
|
|
file_t dir = __file_name_lookup_under (port, "/",
|
|
|
|
O_DIRECTORY | O_NOTRANS, 0);;
|
2005-10-15 02:23:56 +00:00
|
|
|
if (dir != MACH_PORT_NULL)
|
|
|
|
__mach_port_deallocate (__mach_task_self (), dir);
|
|
|
|
dir != MACH_PORT_NULL ? 0 : errno;
|
|
|
|
}));
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
errno = err;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _hurd_fd_opendir (d);
|
|
|
|
}
|
2006-02-12 21:41:44 +00:00
|
|
|
weak_alias (__fdopendir, fdopendir)
|