tst-basic6.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Copyright (C) 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <pthread.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <unistd.h>
  20. static char *p;
  21. static pthread_barrier_t b;
  22. #define BT \
  23. e = pthread_barrier_wait (&b); \
  24. if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) \
  25. { \
  26. puts ("barrier_wait failed"); \
  27. exit (1); \
  28. }
  29. static void *
  30. tf (void *a)
  31. {
  32. int e;
  33. BT;
  34. char *p2 = getcwd (NULL, 0);
  35. if (p2 == NULL)
  36. {
  37. puts ("2nd getcwd failed");
  38. exit (1);
  39. }
  40. if (strcmp (p, p2) != 0)
  41. {
  42. printf ("initial cwd mismatch: \"%s\" vs \"%s\"\n", p, p2);
  43. exit (1);
  44. }
  45. free (p);
  46. free (p2);
  47. if (chdir ("..") != 0)
  48. {
  49. puts ("chdir failed");
  50. exit (1);
  51. }
  52. p = getcwd (NULL, 0);
  53. if (p == NULL)
  54. {
  55. puts ("getcwd failed");
  56. exit (1);
  57. }
  58. return a;
  59. }
  60. int
  61. do_test (void)
  62. {
  63. if (pthread_barrier_init (&b, NULL, 2) != 0)
  64. {
  65. puts ("barrier_init failed");
  66. exit (1);
  67. }
  68. pthread_t th;
  69. if (pthread_create (&th, NULL, tf, NULL) != 0)
  70. {
  71. puts ("create failed");
  72. exit (1);
  73. }
  74. p = getcwd (NULL, 0);
  75. if (p == NULL)
  76. {
  77. puts ("getcwd failed");
  78. exit (1);
  79. }
  80. int e;
  81. BT;
  82. if (pthread_join (th, NULL) != 0)
  83. {
  84. puts ("join failed");
  85. exit (1);
  86. }
  87. char *p2 = getcwd (NULL, 0);
  88. if (p2 == NULL)
  89. {
  90. puts ("2nd getcwd failed");
  91. exit (1);
  92. }
  93. if (strcmp (p, p2) != 0)
  94. {
  95. printf ("cwd after chdir mismatch: \"%s\" vs \"%s\"\n", p, p2);
  96. exit (1);
  97. }
  98. free (p);
  99. free (p2);
  100. return 0;
  101. }
  102. #define TEST_FUNCTION do_test ()
  103. #include "../test-skeleton.c"