test-canon2.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Test for realpath/canonicalize function.
  2. Copyright (C) 1998-2019 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, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <errno.h>
  17. #include <string.h>
  18. /* Prototype for our test function. */
  19. extern void do_prepare (int argc, char *argv[]);
  20. extern int do_test (int argc, char *argv[]);
  21. /* We have a preparation function. */
  22. #define PREPARE do_prepare
  23. #include <test-skeleton.c>
  24. /* Name of the temporary files we create. */
  25. char *name1;
  26. char *name2;
  27. /* Preparation. */
  28. void
  29. do_prepare (int argc, char *argv[])
  30. {
  31. size_t test_dir_len;
  32. test_dir_len = strlen (test_dir);
  33. /* Generate the circular symlinks. */
  34. name1 = malloc (test_dir_len + sizeof ("/canonXXXXXX"));
  35. mempcpy (mempcpy (name1, test_dir, test_dir_len),
  36. "/canonXXXXXX", sizeof ("/canonXXXXXX"));
  37. name2 = strdup (name1);
  38. add_temp_file (mktemp (name1));
  39. add_temp_file (mktemp (name2));
  40. }
  41. /* Run the test. */
  42. int
  43. do_test (int argc, char *argv[])
  44. {
  45. char *canon;
  46. printf ("create symlinks from %s to %s and vice versa\n", name1, name2);
  47. if (symlink (name1, name2) == -1
  48. || symlink (name2, name1) == -1)
  49. /* We cannot test this. */
  50. return 0;
  51. /* Call the function. This is equivalent the using `realpath' but the
  52. function allocates the room for the result. */
  53. errno = 0;
  54. canon = canonicalize_file_name (name1);
  55. return canon != NULL || errno != ELOOP;
  56. }