tst-basic6.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <pthread.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <unistd.h>
  21. static char *p;
  22. static pthread_barrier_t b;
  23. #define BT \
  24. e = pthread_barrier_wait (&b); \
  25. if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) \
  26. { \
  27. puts ("barrier_wait failed"); \
  28. exit (1); \
  29. }
  30. static void *
  31. tf (void *a)
  32. {
  33. int e;
  34. BT;
  35. char *p2 = getcwd (NULL, 0);
  36. if (p2 == NULL)
  37. {
  38. puts ("2nd getcwd failed");
  39. exit (1);
  40. }
  41. if (strcmp (p, p2) != 0)
  42. {
  43. printf ("initial cwd mismatch: \"%s\" vs \"%s\"\n", p, p2);
  44. exit (1);
  45. }
  46. free (p);
  47. free (p2);
  48. if (chdir ("..") != 0)
  49. {
  50. puts ("chdir failed");
  51. exit (1);
  52. }
  53. p = getcwd (NULL, 0);
  54. if (p == NULL)
  55. {
  56. puts ("getcwd failed");
  57. exit (1);
  58. }
  59. return a;
  60. }
  61. int
  62. do_test (void)
  63. {
  64. if (pthread_barrier_init (&b, NULL, 2) != 0)
  65. {
  66. puts ("barrier_init failed");
  67. exit (1);
  68. }
  69. pthread_t th;
  70. if (pthread_create (&th, NULL, tf, NULL) != 0)
  71. {
  72. puts ("create failed");
  73. exit (1);
  74. }
  75. p = getcwd (NULL, 0);
  76. if (p == NULL)
  77. {
  78. puts ("getcwd failed");
  79. exit (1);
  80. }
  81. int e;
  82. BT;
  83. if (pthread_join (th, NULL) != 0)
  84. {
  85. puts ("join failed");
  86. exit (1);
  87. }
  88. char *p2 = getcwd (NULL, 0);
  89. if (p2 == NULL)
  90. {
  91. puts ("2nd getcwd failed");
  92. exit (1);
  93. }
  94. if (strcmp (p, p2) != 0)
  95. {
  96. printf ("cwd after chdir mismatch: \"%s\" vs \"%s\"\n", p, p2);
  97. exit (1);
  98. }
  99. free (p);
  100. free (p2);
  101. return 0;
  102. }
  103. #define TEST_FUNCTION do_test ()
  104. #include "../test-skeleton.c"