1 | /* Test for realpath/canonicalize function. |
2 | Copyright (C) 1998-2022 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
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. |
9 | |
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. |
14 | |
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/>. */ |
18 | |
19 | #include <errno.h> |
20 | #include <string.h> |
21 | |
22 | |
23 | /* Prototype for our test function. */ |
24 | extern void do_prepare (int argc, char *argv[]); |
25 | extern int do_test (int argc, char *argv[]); |
26 | |
27 | /* We have a preparation function. */ |
28 | #define PREPARE do_prepare |
29 | |
30 | #include <test-skeleton.c> |
31 | |
32 | /* Name of the temporary files we create. */ |
33 | char *name1; |
34 | char *name2; |
35 | |
36 | /* Preparation. */ |
37 | void |
38 | do_prepare (int argc, char *argv[]) |
39 | { |
40 | size_t test_dir_len; |
41 | |
42 | test_dir_len = strlen (test_dir); |
43 | |
44 | /* Generate the circular symlinks. */ |
45 | name1 = malloc (size: test_dir_len + sizeof ("/canonXXXXXX" )); |
46 | mempcpy (mempcpy (name1, test_dir, test_dir_len), |
47 | "/canonXXXXXX" , sizeof ("/canonXXXXXX" )); |
48 | name2 = strdup (s: name1); |
49 | |
50 | add_temp_file (name: mktemp (template: name1)); |
51 | add_temp_file (name: mktemp (template: name2)); |
52 | } |
53 | |
54 | |
55 | /* Run the test. */ |
56 | int |
57 | do_test (int argc, char *argv[]) |
58 | { |
59 | char *canon; |
60 | |
61 | printf (format: "create symlinks from %s to %s and vice versa\n" , name1, name2); |
62 | if (symlink (from: name1, to: name2) == -1 |
63 | || symlink (from: name2, to: name1) == -1) |
64 | /* We cannot test this. */ |
65 | return 0; |
66 | |
67 | /* Call the function. This is equivalent the using `realpath' but the |
68 | function allocates the room for the result. */ |
69 | errno = 0; |
70 | canon = canonicalize_file_name (name: name1); |
71 | |
72 | return canon != NULL || errno != ELOOP; |
73 | } |
74 | |