linux: Make fdopendir fail with O_PATH (BZ 30373)
[glibc.git] / sysdeps / unix / sysv / linux / tst-fdopendir-o_path.c
blob2531cf8ddb92ff45b9ca0fa831f028192ef56141
1 /* Check if fdopendir fails with file descriptor opened with O_PATH (BZ 30737)
2 Copyright (C) 2023 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, see
17 <https://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <fcntl.h>
21 #include <dirent.h>
22 #include <support/check.h>
23 #include <support/temp_file.h>
24 #include <support/xunistd.h>
26 static int
27 do_test (void)
29 char *dirname = support_create_temp_directory ("tst-fdopendir-o_path");
32 int fd = xopen (dirname, O_RDONLY | O_DIRECTORY, 0600);
33 DIR *dir = fdopendir (fd);
34 TEST_VERIFY_EXIT (dir != NULL);
35 closedir (dir);
39 int fd = xopen (dirname, O_RDONLY | O_PATH | O_DIRECTORY, 0600);
40 TEST_VERIFY (fdopendir (fd) == NULL);
41 TEST_COMPARE (errno, EBADF);
42 xclose (fd);
45 return 0;
48 #include <support/test-driver.c>