]>
Commit | Line | Data |
---|---|---|
310b3460 | 1 | /* Test for realpath/canonicalize function. |
b168057a | 2 | Copyright (C) 1998-2015 Free Software Foundation, Inc. |
41bdb6e2 | 3 | This file is part of the GNU C Library. |
310b3460 UD |
4 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
310b3460 UD |
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 | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
310b3460 | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
17 | License along with the GNU C Library; if not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
310b3460 UD |
19 | |
20 | #include <errno.h> | |
21 | #include <string.h> | |
22 | ||
23 | ||
24 | /* Prototype for our test function. */ | |
25 | extern void do_prepare (int argc, char *argv[]); | |
26 | extern int do_test (int argc, char *argv[]); | |
27 | ||
28 | /* We have a preparation function. */ | |
29 | #define PREPARE do_prepare | |
30 | ||
31 | #include <test-skeleton.c> | |
32 | ||
33 | /* Name of the temporary files we create. */ | |
34 | char *name1; | |
35 | char *name2; | |
36 | ||
37 | /* Preparation. */ | |
38 | void | |
39 | do_prepare (int argc, char *argv[]) | |
40 | { | |
30aa5785 | 41 | size_t test_dir_len; |
310b3460 UD |
42 | |
43 | test_dir_len = strlen (test_dir); | |
44 | ||
45 | /* Generate the circular symlinks. */ | |
46 | name1 = malloc (test_dir_len + sizeof ("/canonXXXXXX")); | |
47 | mempcpy (mempcpy (name1, test_dir, test_dir_len), | |
48 | "/canonXXXXXX", sizeof ("/canonXXXXXX")); | |
49 | name2 = strdup (name1); | |
50 | ||
51 | add_temp_file (mktemp (name1)); | |
52 | add_temp_file (mktemp (name2)); | |
53 | } | |
54 | ||
55 | ||
56 | /* Run the test. */ | |
57 | int | |
58 | do_test (int argc, char *argv[]) | |
59 | { | |
60 | char *canon; | |
61 | ||
62 | printf ("create symlinks from %s to %s and vice versa\n", name1, name2); | |
63 | if (symlink (name1, name2) == -1 | |
64 | || symlink (name2, name1) == -1) | |
65 | /* We cannot test this. */ | |
66 | return 0; | |
67 | ||
68 | /* Call the function. This is equivalent the using `realpath' but the | |
69 | function allocates the room for the result. */ | |
70 | errno = 0; | |
71 | canon = canonicalize_file_name (name1); | |
72 | ||
73 | return canon != NULL || errno != ELOOP; | |
74 | } |