blob: e7e02e55e6520fcd1c655fe15f55a1de5b9226f9 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* Test for realpath/canonicalize function.
2 Copyright (C) 1998 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21#include <errno.h>
22#include <string.h>
23
24
25/* Prototype for our test function. */
26extern void do_prepare (int argc, char *argv[]);
27extern int do_test (int argc, char *argv[]);
28
29/* We have a preparation function. */
30#define PREPARE do_prepare
31
32#include <test-skeleton.c>
33
34/* Name of the temporary files we create. */
35char *name1;
36char *name2;
37
38/* Preparation. */
39void
40do_prepare (int argc, char *argv[])
41{
42 size_t test_dir_len;
43 int tfd;
44
45 test_dir_len = strlen (test_dir);
46
47 /* Generate the circular symlinks. */
48 name1 = malloc (test_dir_len + sizeof ("/canonXXXXXX"));
49 mempcpy (mempcpy (name1, test_dir, test_dir_len),
50 "/canonXXXXXX", sizeof ("/canonXXXXXX"));
51 name2 = strdup (name1);
52 tfd = mkstemp(name1);
53 if (tfd < 0) {
54 printf("%s: cannot generate temp file name\n", __FUNCTION__);
55 exit(1);
56 }
57 close(tfd);
58 add_temp_file (name1);
59 tfd = mkstemp(name2);
60 if (tfd < 0) {
61 printf("%s: cannot generate temp file name\n", __FUNCTION__);
62 exit(1);
63 }
64 close(tfd);
65 add_temp_file (name2);
66}
67
68
69/* Run the test. */
70int
71do_test (int argc, char *argv[])
72{
73 char *canon;
74
75 printf ("create symlinks from %s to %s and vice versa\n", name1, name2);
76 if (symlink (name1, name2) == -1
77 || symlink (name2, name1) == -1)
78 /* We cannot test this. */
79 return 0;
80
81 /* Call the function. This is equivalent the using `realpath' but the
82 function allocates the room for the result. */
83 errno = 0;
84 canon = canonicalize_file_name (name1);
85
86 return canon != NULL || errno != ELOOP;
87}