tst-pthread-mutexattr.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Make sure that pthread_mutexattr_gettype returns a valid kind.
  2. Copyright (C) 2015-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  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 <stdio.h>
  16. #include <string.h>
  17. #include <pthread.h>
  18. static int
  19. do_test (void)
  20. {
  21. pthread_mutexattr_t attr;
  22. int kind;
  23. int error;
  24. error = pthread_mutexattr_init (&attr);
  25. if (error)
  26. {
  27. printf ("pthread_mutexattr_init: %s\n", strerror (error));
  28. return 1;
  29. }
  30. error = pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_DEFAULT);
  31. if (error)
  32. {
  33. printf ("pthread_mutexattr_settype (1): %s\n", strerror (error));
  34. return 1;
  35. }
  36. error = pthread_mutexattr_gettype (&attr, &kind);
  37. if (error)
  38. {
  39. printf ("pthread_mutexattr_gettype: %s\n", strerror (error));
  40. return 1;
  41. }
  42. error = pthread_mutexattr_settype (&attr, kind);
  43. if (error)
  44. {
  45. printf ("pthread_mutexattr_settype (2): %s\n", strerror (error));
  46. return 1;
  47. }
  48. return 0;
  49. }
  50. #define TEST_FUNCTION do_test ()
  51. #include "../test-skeleton.c"