test-canon2.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* 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. 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. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <errno.h>
  18. #include <string.h>
  19. /* Prototype for our test function. */
  20. extern void do_prepare (int argc, char *argv[]);
  21. extern int do_test (int argc, char *argv[]);
  22. /* We have a preparation function. */
  23. #define PREPARE do_prepare
  24. #include <test-skeleton.c>
  25. /* Name of the temporary files we create. */
  26. char *name1;
  27. char *name2;
  28. /* Preparation. */
  29. void
  30. do_prepare (int argc, char *argv[])
  31. {
  32. size_t test_dir_len;
  33. test_dir_len = strlen (test_dir);
  34. /* Generate the circular symlinks. */
  35. name1 = malloc (test_dir_len + sizeof ("/canonXXXXXX"));
  36. mempcpy (mempcpy (name1, test_dir, test_dir_len),
  37. "/canonXXXXXX", sizeof ("/canonXXXXXX"));
  38. name2 = strdup (name1);
  39. add_temp_file (mktemp (name1));
  40. add_temp_file (mktemp (name2));
  41. }
  42. /* Run the test. */
  43. int
  44. do_test (int argc, char *argv[])
  45. {
  46. char *canon;
  47. printf ("create symlinks from %s to %s and vice versa\n", name1, name2);
  48. if (symlink (name1, name2) == -1
  49. || symlink (name2, name1) == -1)
  50. /* We cannot test this. */
  51. return 0;
  52. /* Call the function. This is equivalent the using `realpath' but the
  53. function allocates the room for the result. */
  54. errno = 0;
  55. canon = canonicalize_file_name (name1);
  56. return canon != NULL || errno != ELOOP;
  57. }