Back to index

glibc  2.9
test-canon2.c
Go to the documentation of this file.
00001 /* Test for realpath/canonicalize function.
00002    Copyright (C) 1998 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <errno.h>
00022 #include <string.h>
00023 
00024 
00025 /* Prototype for our test function.  */
00026 extern void do_prepare (int argc, char *argv[]);
00027 extern int do_test (int argc, char *argv[]);
00028 
00029 /* We have a preparation function.  */
00030 #define PREPARE do_prepare
00031 
00032 #include <test-skeleton.c>
00033 
00034 /* Name of the temporary files we create.  */
00035 char *name1;
00036 char *name2;
00037 
00038 /* Preparation.  */
00039 void
00040 do_prepare (int argc, char *argv[])
00041 {
00042   size_t test_dir_len;
00043 
00044   test_dir_len = strlen (test_dir);
00045 
00046   /* Generate the circular symlinks.  */
00047   name1 = malloc (test_dir_len + sizeof ("/canonXXXXXX"));
00048   mempcpy (mempcpy (name1, test_dir, test_dir_len),
00049           "/canonXXXXXX", sizeof ("/canonXXXXXX"));
00050   name2 = strdup (name1);
00051 
00052   add_temp_file (mktemp (name1));
00053   add_temp_file (mktemp (name2));
00054 }
00055 
00056 
00057 /* Run the test.  */
00058 int
00059 do_test (int argc, char *argv[])
00060 {
00061   char *canon;
00062 
00063   printf ("create symlinks from %s to %s and vice versa\n", name1, name2);
00064   if (symlink (name1, name2) == -1
00065       || symlink (name2, name1) == -1)
00066     /* We cannot test this.  */
00067     return 0;
00068 
00069   /* Call the function.  This is equivalent the using `realpath' but the
00070      function allocates the room for the result.  */
00071   errno = 0;
00072   canon = canonicalize_file_name (name1);
00073 
00074   return canon != NULL || errno != ELOOP;
00075 }