home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / libg++-2.6-fsf.lha / libg++-2.6 / libiberty / clock.c < prev    next >
C/C++ Source or Header  |  1994-01-24  |  2KB  |  67 lines

  1. /* ANSI-compatible clock function.
  2.    Copyright (C) 1994 Free Software Foundation, Inc.
  3.  
  4. This file is part of the libiberty library.
  5. Libiberty is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9.  
  10. Libiberty is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with libiberty; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  18. Cambridge, MA 02139, USA.  */
  19.  
  20. #ifdef HAVE_GETRUSAGE
  21. #include <sys/time.h>
  22. #include <sys/resource.h>
  23. #endif
  24.  
  25. #ifdef HAVE_TIMES
  26. #include <sys/param.h>
  27. #include <sys/times.h>
  28. #endif
  29.  
  30. /* FIXME: should be able to declare as clock_t. */
  31.  
  32. long
  33. clock ()
  34. {
  35. #ifdef HAVE_GETRUSAGE
  36.   struct rusage rusage;
  37.  
  38.   getrusage (0, &rusage);
  39.   return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
  40.       + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
  41. #else
  42. #ifdef HAVE_TIMES
  43.   struct tms tms;
  44.  
  45.   times (&tms);
  46.   return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ);
  47. #else
  48. #ifdef VMS
  49.   struct
  50.     {
  51.       int proc_user_time;
  52.       int proc_system_time;
  53.       int child_user_time;
  54.       int child_system_time;
  55.     } vms_times;
  56.  
  57.   times (&vms_times);
  58.   return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
  59. #else
  60.   /* A fallback, if nothing else available. */
  61.   return 0;
  62. #endif /* VMS */
  63. #endif /* HAVE_TIMES */
  64. #endif /* HAVE_GETRUSAGE */
  65. }
  66.  
  67.