1 /* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>. */
22 /* Close the file descriptors from FIRST up to LAST, inclusive.
23 If CLOSE_RANGE_CLOEXEC is set in FLAGS, set the FD_CLOEXEC flag
24 instead of closing. */
26 __close_range (unsigned int first
, unsigned int last
,
32 return __hurd_fail (EINVAL
);
33 if (flags
& ~CLOSE_RANGE_CLOEXEC
)
34 return __hurd_fail (EINVAL
);
37 __mutex_lock (&_hurd_dtable_lock
);
39 for (i
= first
; i
<= last
&& i
< _hurd_dtablesize
; i
++)
41 struct hurd_fd
*fd
= _hurd_dtable
[i
];
43 if (fd
== NULL
|| fd
->port
.port
== MACH_PORT_NULL
)
46 __spin_lock (&fd
->port
.lock
);
48 if (flags
& CLOSE_RANGE_CLOEXEC
)
49 fd
->flags
|= FD_CLOEXEC
;
52 _hurd_port_set (&fd
->ctty
, MACH_PORT_NULL
);
53 _hurd_port_locked_set (&fd
->port
, MACH_PORT_NULL
);
56 __spin_unlock (&fd
->port
.lock
);
59 __mutex_unlock (&_hurd_dtable_lock
);
65 libc_hidden_def (__close_range
)
66 weak_alias (__close_range
, close_range
)