wait4.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * wait4() for uClibc
  3. *
  4. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <sys/syscall.h>
  9. #include <sys/wait.h>
  10. #include <sys/resource.h>
  11. # define __NR___syscall_wait4 __NR_wait4
  12. static __always_inline _syscall4(int, __syscall_wait4, __kernel_pid_t, pid,
  13. int *, status, int, opts, struct rusage *, rusage)
  14. pid_t __wait4_nocancel(pid_t pid, int *status, int opts, struct rusage *rusage)
  15. {
  16. #if defined(__UCLIBC_USE_TIME64__)
  17. char *arg_rusage = rusage ? (char *)&rusage->ru_maxrss - 4 * sizeof(__S32_TYPE) : 0;
  18. int __ret = __syscall_wait4(pid, status, opts, (struct rusage *)arg_rusage);
  19. if (__ret > 0 && rusage) {
  20. __S32_TYPE __rusage[4];
  21. memcpy(__rusage, arg_rusage, 4 * sizeof(__S32_TYPE));
  22. struct timeval tv_utime = {.tv_sec = __rusage[0], .tv_usec = __rusage[1]};
  23. struct timeval tv_stime = {.tv_sec = __rusage[2], .tv_usec = __rusage[2]};
  24. rusage->ru_utime = tv_utime;
  25. rusage->ru_stime = tv_stime;
  26. }
  27. return __ret;
  28. #else
  29. return __syscall_wait4(pid, status, opts, rusage);
  30. #endif
  31. }
  32. #ifdef __USE_BSD
  33. strong_alias(__wait4_nocancel,wait4)
  34. #endif