It looks reasonable to define a getrusage() replacement for native Windows in gnulib. libgfortran (in GCC) has such a replacement already.
First comes a <sys/resource.h> substitute. Reference: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_resource.h.html 2012-04-12 Bruno Haible <br...@clisp.org> New module 'sys_resource'. * lib/sys_resource.in.h: New file. * m4/sys_resource_h.m4: New file. * modules/sys_resource: New file. * doc/posix-headers/sys_resource.texi: Mention the new module. ============================ lib/sys_resource.in.h ============================ /* Substitute for <sys/resource.h>. Copyright (C) 2012 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. */ # if __GNUC__ >= 3 @PRAGMA_SYSTEM_HEADER@ # endif @PRAGMA_COLUMNS@ #ifndef _@GUARD_PREFIX@_SYS_RESOURCE_H #if @HAVE_SYS_RESOURCE_H@ /* On FreeBSD 5.0, <sys/resource.h> assumes prior inclusion of <sys/types.h> and <sys/time.h>. */ # include <sys/types.h> # include <sys/time.h> /* The include_next requires a split double-inclusion guard. */ # @INCLUDE_NEXT@ @NEXT_SYS_RESOURCE_H@ #endif #ifndef _@GUARD_PREFIX@_SYS_RESOURCE_H #define _@GUARD_PREFIX@_SYS_RESOURCE_H #if !@HAVE_SYS_RESOURCE_H@ /* A platform that lacks <sys/resource.h>. */ /* Get 'struct timeval'. */ # include <sys/time.h> /* Define the RUSAGE_* constants. */ # define RUSAGE_SELF 0 # define RUSAGE_CHILDREN -1 # ifdef __cplusplus extern "C" { # endif # if !GNULIB_defined_struct_rusage /* All known platforms that lack <sys/resource.h> also lack any declaration of struct rusage in any other header. */ struct rusage { struct timeval ru_utime; /* CPU time used in user mode */ struct timeval ru_stime; /* CPU time used in system mode (kernel) */ long ru_maxrss; long ru_ixrss; long ru_idrss; long ru_isrss; long ru_minflt; long ru_majflt; long ru_nswap; long ru_inblock; long ru_oublock; long ru_msgsnd; long ru_msgrcv; long ru_nsignals; long ru_nvcsw; long ru_nivcsw; }; # define GNULIB_defined_struct_rusage 1 # endif # ifdef __cplusplus } # endif #endif #endif /* _@GUARD_PREFIX@_SYS_RESOURCE_H */ #endif /* _@GUARD_PREFIX@_SYS_RESOURCE_H */ ============================ m4/sys_resource_h.m4 ============================= # sys_resource_h.m4 serial 1 dnl Copyright (C) 2012 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_HEADER_SYS_RESOURCE], [ AC_REQUIRE([gl_SYS_RESOURCE_H_DEFAULTS]) dnl <sys/resource.h> is always overridden, because of GNULIB_POSIXCHECK. gl_CHECK_NEXT_HEADERS([sys/resource.h]) if test $ac_cv_header_sys_resource_h = yes; then HAVE_SYS_RESOURCE_H=1 else HAVE_SYS_RESOURCE_H=0 fi AC_SUBST([HAVE_SYS_RESOURCE_H]) ]) AC_DEFUN([gl_SYS_RESOURCE_MODULE_INDICATOR], [ dnl Use AC_REQUIRE here, so that the default settings are expanded once only. AC_REQUIRE([gl_SYS_RESOURCE_H_DEFAULTS]) gl_MODULE_INDICATOR_SET_VARIABLE([$1]) dnl Define it also as a C macro, for the benefit of the unit tests. gl_MODULE_INDICATOR_FOR_TESTS([$1]) ]) AC_DEFUN([gl_SYS_RESOURCE_H_DEFAULTS], [ ]) ============================ modules/sys_resource ============================= Description: A POSIX-like <sys/resource.h>. Files: lib/sys_resource.in.h m4/sys_resource_h.m4 Depends-on: include_next sys_time configure.ac: gl_HEADER_SYS_RESOURCE AC_PROG_MKDIR_P Makefile.am: BUILT_SOURCES += sys/resource.h # We need the following in order to create <sys/resource.h> when the system # doesn't have one. sys/resource.h: sys_resource.in.h $(top_builddir)/config.status $(AM_V_at)$(MKDIR_P) sys $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_SYS_RESOURCE_H''@|$(NEXT_SYS_RESOURCE_H)|g' \ -e 's|@''HAVE_SYS_RESOURCE_H''@|$(HAVE_SYS_RESOURCE_H)|g' \ < $(srcdir)/sys_resource.in.h; \ } > $@-t && \ mv -f $@-t $@ MOSTLYCLEANFILES += sys/resource.h sys/resource.h-t MOSTLYCLEANDIRS += sys Include: <sys/resource.h> License: LGPL Maintainer: Bruno Haible =============================================================================== --- doc/posix-headers/sys_resource.texi.orig Thu Apr 12 20:57:01 2012 +++ doc/posix-headers/sys_resource.texi Thu Apr 12 20:15:29 2012 @@ -3,20 +3,19 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/basedefs/sys_resource.h.html} -Gnulib module: --- +Gnulib module: sys_resource Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item This header file is missing on some platforms: mingw, MSVC 9. - @item On some platforms, this header file requires that <sys/types.h> and <sys/time.h> already be included: FreeBSD 5.0. @end itemize + +Portability problems not fixed by Gnulib: +@itemize +@end itemize