1 | /* Verify that realpath returns NULL with ENAMETOOLONG if the result exceeds |
2 | NAME_MAX. |
3 | Copyright The GNU Toolchain Authors. |
4 | This file is part of the GNU C Library. |
5 | |
6 | The GNU C Library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2.1 of the License, or (at your option) any later version. |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Lesser General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Lesser General Public |
17 | License along with the GNU C Library; if not, see |
18 | <https://www.gnu.org/licenses/>. */ |
19 | |
20 | #include <errno.h> |
21 | #include <limits.h> |
22 | #include <stdlib.h> |
23 | #include <string.h> |
24 | #include <unistd.h> |
25 | #include <support/check.h> |
26 | #include <support/temp_file.h> |
27 | #include <sys/types.h> |
28 | #include <sys/stat.h> |
29 | |
30 | #define BASENAME "tst-realpath-toolong." |
31 | |
32 | #ifndef PATH_MAX |
33 | # define PATH_MAX 1024 |
34 | #endif |
35 | |
36 | int |
37 | do_test (void) |
38 | { |
39 | char *base = support_create_and_chdir_toolong_temp_directory (BASENAME); |
40 | |
41 | char buf[PATH_MAX + 1]; |
42 | const char *res = realpath (name: "." , resolved: buf); |
43 | |
44 | /* canonicalize.c states that if the real path is >= PATH_MAX, then |
45 | realpath returns NULL and sets ENAMETOOLONG. */ |
46 | TEST_VERIFY (res == NULL); |
47 | TEST_VERIFY (errno == ENAMETOOLONG); |
48 | |
49 | free (ptr: base); |
50 | return 0; |
51 | } |
52 | |
53 | #include <support/test-driver.c> |
54 | |