From 80b57167c9149aeb60922530b79f7bd40d7130a1 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Sat, 9 Jul 2022 22:01:26 +1200 Subject: [PATCH 2/6] Remove dead getrusage replacement code. getrusage is in POSIX-1:2001. Note that POSIX only covers ru_utime and ru_stime and we rely on many more fields unconditionally, but that doesn't seem to cause a problem on any current system. If a system were to appear that has minimal POSIX getrusage, we'd be better off doing a configure test for the extended fields rather than carrying the ancient replacement code. The only supported system we need a replacement for now is Windows. --- src/include/rusagestub.h | 3 --- src/port/getrusage.c | 46 ++-------------------------------------- 2 files changed, 2 insertions(+), 47 deletions(-) diff --git a/src/include/rusagestub.h b/src/include/rusagestub.h index b887effa3e..be26f849a5 100644 --- a/src/include/rusagestub.h +++ b/src/include/rusagestub.h @@ -15,9 +15,6 @@ #define RUSAGESTUB_H #include /* for struct timeval */ -#ifndef WIN32 -#include /* for struct tms */ -#endif #include /* for CLK_TCK */ #define RUSAGE_SELF 0 diff --git a/src/port/getrusage.c b/src/port/getrusage.c index 02665f4032..41b3373953 100644 --- a/src/port/getrusage.c +++ b/src/port/getrusage.c @@ -17,11 +17,8 @@ #include "rusagestub.h" -/* This code works on: - * solaris_i386 - * solaris_sparc - * win32 - * which currently is all the supported platforms that don't have a +/* + * This code works on Windows, which is the only supported platform without a * native version of getrusage(). So, if configure decides to compile * this file at all, we just use this version unconditionally. */ @@ -29,7 +26,6 @@ int getrusage(int who, struct rusage *rusage) { -#ifdef WIN32 FILETIME starttime; FILETIME exittime; FILETIME kerneltime; @@ -66,44 +62,6 @@ getrusage(int who, struct rusage *rusage) li.QuadPart /= 10L; /* Convert to microseconds */ rusage->ru_utime.tv_sec = li.QuadPart / 1000000L; rusage->ru_utime.tv_usec = li.QuadPart % 1000000L; -#else /* all but WIN32 */ - - struct tms tms; - int tick_rate = CLK_TCK; /* ticks per second */ - clock_t u, - s; - - if (rusage == (struct rusage *) NULL) - { - errno = EFAULT; - return -1; - } - if (times(&tms) < 0) - { - /* errno set by times */ - return -1; - } - switch (who) - { - case RUSAGE_SELF: - u = tms.tms_utime; - s = tms.tms_stime; - break; - case RUSAGE_CHILDREN: - u = tms.tms_cutime; - s = tms.tms_cstime; - break; - default: - errno = EINVAL; - return -1; - } -#define TICK_TO_SEC(T, RATE) ((T)/(RATE)) -#define TICK_TO_USEC(T,RATE) (((T)%(RATE)*1000000)/RATE) - rusage->ru_utime.tv_sec = TICK_TO_SEC(u, tick_rate); - rusage->ru_utime.tv_usec = TICK_TO_USEC(u, tick_rate); - rusage->ru_stime.tv_sec = TICK_TO_SEC(s, tick_rate); - rusage->ru_stime.tv_usec = TICK_TO_USEC(u, tick_rate); -#endif /* WIN32 */ return 0; } -- 2.36.1