/gnu/lib/libf2c/libU77/sys_clock_.c

https://github.com/avsm/src · C · 79 lines · 60 code · 2 blank · 17 comment · 4 complexity · a953378722e4063cea601a4c70837893 MD5 · raw file

  1. /* Copyright (C) 1996, 1998, 2001 Free Software Foundation, Inc.
  2. This file is part of GNU Fortran libU77 library.
  3. This library is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU Library General Public License as published
  5. by the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. GNU Fortran is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with GNU Fortran; see the file COPYING.LIB. If
  13. not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. #ifdef HAVE_CONFIG_H
  16. #include "config.h"
  17. #endif
  18. #include <sys/types.h>
  19. #if HAVE_SYS_PARAM_H
  20. # include <sys/param.h>
  21. #endif
  22. #if TIME_WITH_SYS_TIME
  23. # include <sys/time.h>
  24. # include <time.h>
  25. #else
  26. # if HAVE_SYS_TIME_H
  27. # include <sys/time.h>
  28. # else
  29. # include <time.h>
  30. # endif
  31. #endif
  32. #if HAVE_SYS_TIMES_H
  33. # include <sys/times.h>
  34. #endif
  35. #include <limits.h>
  36. #if HAVE_UNISTD_H
  37. # include <unistd.h>
  38. #endif
  39. #include <errno.h> /* for ENOSYS */
  40. #include "f2c.h"
  41. int
  42. G77_system_clock_0 (integer * count, integer * count_rate,
  43. integer * count_max)
  44. {
  45. #if defined (HAVE_TIMES)
  46. struct tms buffer;
  47. unsigned long cnt;
  48. if (count_rate)
  49. {
  50. #ifdef _SC_CLK_TCK
  51. *count_rate = sysconf (_SC_CLK_TCK);
  52. #elif defined CLOCKS_PER_SECOND
  53. *count_rate = CLOCKS_PER_SECOND;
  54. #elif defined CLK_TCK
  55. *count_rate = CLK_TCK;
  56. #elif defined HZ
  57. *count_rate = HZ;
  58. #else
  59. #error Dont know clock tick length
  60. #endif
  61. }
  62. if (count_max) /* optional arg present? */
  63. *count_max = INT_MAX; /* dubious */
  64. cnt = times (&buffer);
  65. if (cnt > (unsigned long) (INT_MAX))
  66. *count = INT_MAX; /* also dubious */
  67. else
  68. *count = cnt;
  69. return 0;
  70. #else /* ! HAVE_TIMES */
  71. errno = ENOSYS;
  72. return -1;
  73. #endif /* ! HAVE_TIMES */
  74. }