tst-clone.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Test for proper error/errno handling in clone.
  2. Copyright (C) 2006-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. /* BZ #2386 */
  16. #include <errno.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <unistd.h>
  20. #include <sched.h>
  21. #ifdef __ia64__
  22. extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
  23. size_t __child_stack_size, int __flags, void *__arg, ...);
  24. #endif
  25. int child_fn(void *arg)
  26. {
  27. puts ("FAIL: in child_fn(); should not be here");
  28. exit(1);
  29. }
  30. static int
  31. do_test (void)
  32. {
  33. int result;
  34. #ifdef __ia64__
  35. result = __clone2 (child_fn, NULL, 0, 0, NULL, NULL, NULL);
  36. #else
  37. result = clone (child_fn, NULL, 0, NULL);
  38. #endif
  39. if (errno != EINVAL || result != -1)
  40. {
  41. printf ("FAIL: clone()=%d (wanted -1) errno=%d (wanted %d)\n",
  42. result, errno, EINVAL);
  43. return 1;
  44. }
  45. puts ("All OK");
  46. return 0;
  47. }
  48. #define TEST_FUNCTION do_test ()
  49. #include "../test-skeleton.c"