home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / getrusag.c < prev    next >
C/C++ Source or Header  |  1993-02-17  |  1KB  |  69 lines

  1. /* getrusage emulation for MiNT */
  2.  
  3. #include <compiler.h>
  4. #include <osbind.h>
  5. #include <mintbind.h>
  6. #include <time.h>
  7. #include <resource.h>
  8. #include <errno.h>
  9.  
  10. extern int __mint;
  11. extern long _childtime;
  12.  
  13. void _ms2tval __PROTO((unsigned long, struct timeval *));
  14.  
  15. void
  16. _ms2tval(milliseconds, tval)
  17.     unsigned long milliseconds;
  18.     struct timeval *tval;
  19. {
  20.     tval->tv_sec = milliseconds/1000;
  21.     tval->tv_usec = (milliseconds % 1000) * 1000;
  22. }
  23.  
  24. void
  25. _add_tval(orig, new)
  26.     struct timeval *orig, *new;
  27. {
  28.     long t;
  29.  
  30.     t = orig->tv_usec + new->tv_usec;
  31.     if (t > 1000000L) {
  32.         orig->tv_sec += t/1000000L;
  33.         t = t % 1000000L;
  34.     }
  35.     orig->tv_usec = t;
  36.     orig->tv_sec += new->tv_sec;
  37. }
  38.  
  39. int
  40. getrusage(which, data)
  41.     int which;
  42.     struct rusage *data;
  43. {
  44.     long r;
  45.     long usage[8];
  46.  
  47.     if (__mint) {
  48.         r = Prusage(usage);
  49.         if (r < 0) {
  50.             errno = (int) -r;
  51.             return -1;
  52.         }
  53.     } else {
  54.         usage[0] = usage[2] = 0;
  55.         usage[1] = _clock() - _childtime;
  56.         usage[3] = _childtime;
  57.     }
  58.  
  59.     if (which == RUSAGE_SELF) {
  60.         _ms2tval(usage[0], &(data->ru_stime));
  61.         _ms2tval(usage[1], &(data->ru_utime));
  62.     }
  63.     else if (which == RUSAGE_CHILDREN) {
  64.         _ms2tval(usage[2], &(data->ru_stime));
  65.         _ms2tval(usage[3], &(data->ru_utime));
  66.     }
  67.     return 0;
  68. }
  69.