2 dnl Copyright (C) 1993-2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
9 dnl From Bruno Haible, Marcus Daniels, Sam Steingold, Peter Burwood, Sam Steingold.
14 [AC_CHECK_HEADERS(sys/resource.h sys/times.h)dnl
15 if test $ac_cv_header_sys_resource_h = yes; then
16 dnl HAVE_SYS_RESOURCE_H defined
17 CL_LINK_CHECK([getrusage], cl_cv_func_getrusage,
18 [#include <sys/types.h> /* NetBSD 1.0 needs this */
20 #include <sys/resource.h>],
21 [struct rusage x; int y = RUSAGE_SELF; getrusage(y,&x); x.ru_utime.tv_sec;])dnl
22 if test $cl_cv_func_getrusage = yes; then
23 CL_PROTO([getrusage], [
29 #include <sys/types.h> /* NetBSD 1.0 needs this */
31 #include <sys/resource.h>
33 [int getrusage (int who, struct rusage * rusage);],
35 [cl_cv_proto_getrusage_arg1="int"],
36 [cl_cv_proto_getrusage_arg1="enum __rusage_who"])
37 ], [extern int getrusage ($cl_cv_proto_getrusage_arg1, struct rusage *);])dnl
38 AC_CACHE_CHECK(whether getrusage works, cl_cv_func_getrusage_works, [
41 #include <sys/types.h> /* NetBSD 1.0 needs this */
43 #include <time.h> /* for time(2) */
44 #include <sys/resource.h>
47 struct rusage used, prev;
48 time_t end = time(NULL)+2;
51 if ((count = getrusage(RUSAGE_SELF, &prev))) {
52 /* getrusage is defined but does not do anything. */
53 /*fprintf(stderr,"getrusage failed: return=%d\n",count);*/
56 while (time(NULL) < end) {
58 getrusage(RUSAGE_SELF, &used);
59 if ((used.ru_utime.tv_usec != prev.ru_utime.tv_usec)
60 || (used.ru_utime.tv_sec != prev.ru_utime.tv_sec)
61 || (used.ru_stime.tv_usec != prev.ru_stime.tv_usec)
62 || (used.ru_stime.tv_sec != prev.ru_stime.tv_sec)) {
63 /*fprintf(stderr,"success after %d runs\n",count);*/
67 /* getrusage is defined but does not work. */
68 /*fprintf(stderr,"failure after %d runs\n",count);*/
71 cl_cv_func_getrusage_works=yes,
72 cl_cv_func_getrusage_works=no,
73 dnl When cross-compiling, don't assume anything.
74 cl_cv_func_getrusage_works="guessing no")])
76 if test "$cl_cv_func_getrusage_works" = yes; then
77 AC_DEFINE(HAVE_GETRUSAGE,,[have <sys/time.h>, the getrusage() function, the struct rusage type, and <sys/resource.h> defines RUSAGE_SELF])
78 AC_DEFINE_UNQUOTED(RUSAGE_WHO_T,$cl_cv_proto_getrusage_arg1,[type of `who' in getrusage() declaration])