diff options
Diffstat (limited to 'libgfortran/intrinsics/time_1.h')
-rw-r--r-- | libgfortran/intrinsics/time_1.h | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/libgfortran/intrinsics/time_1.h b/libgfortran/intrinsics/time_1.h index 12d79ebc12f..73977cbef61 100644 --- a/libgfortran/intrinsics/time_1.h +++ b/libgfortran/intrinsics/time_1.h @@ -40,19 +40,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see As usual with UNIX systems, unfortunately no single way is available for all systems. */ -#ifdef TIME_WITH_SYS_TIME -# include <sys/time.h> -# include <time.h> -#else -# if HAVE_SYS_TIME_H -# include <sys/time.h> -# else -# ifdef HAVE_TIME_H -# include <time.h> -# endif -# endif +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> #endif +#include <time.h> + #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif @@ -174,20 +167,21 @@ gf_cputime (long *user_sec, long *user_usec, long *system_sec, long *system_usec clock_t err; err = times (&buf); *user_sec = buf.tms_utime / HZ; - *user_usec = buf.tms_utime % HZ * (1000000 / HZ); + *user_usec = buf.tms_utime % HZ * (1000000. / HZ); *system_sec = buf.tms_stime / HZ; - *system_usec = buf.tms_stime % HZ * (1000000 / HZ); + *system_usec = buf.tms_stime % HZ * (1000000. / HZ); if ((err == (clock_t) -1) && errno != 0) return -1; return 0; #else - - /* We have nothing to go on. Return -1. */ - *user_sec = *system_sec = 0; - *user_usec = *system_usec = 0; - errno = ENOSYS; - return -1; + clock_t c = clock (); + *user_sec = c / CLOCKS_PER_SEC; + *user_usec = c % CLOCKS_PER_SEC * (1000000. / CLOCKS_PER_SEC); + *system_sec = *system_usec = 0; + if (c == (clock_t) -1) + return -1; + return 0; #endif } @@ -218,7 +212,7 @@ gf_gettime (time_t * secs, long * usecs) *secs = tv.tv_sec; *usecs = tv.tv_usec; return err; -#elif HAVE_TIME +#else time_t t, t2; t = time (&t2); *secs = t2; @@ -226,11 +220,6 @@ gf_gettime (time_t * secs, long * usecs) if (t == ((time_t)-1)) return -1; return 0; -#else - *secs = 0; - *usecs = 0; - errno = ENOSYS; - return -1; #endif } |