bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

declare getloadavg in stdlib.h


From: Bruno Haible
Subject: declare getloadavg in stdlib.h
Date: Sun, 19 Oct 2008 00:19:16 +0200
User-agent: KMail/1.5.4

Hi Jim,

We have been adopting the approach to declare functions provided by glibc
(but not specified by POSIX) in the same header file as glibc does. This
makes sense because most development takes place on glibc systems today.

The ones that not yet follow this idiom:
  - getloadavg, getusershell - not declared by any gnulib header file,
  - euidaccess.h, dirfd.h, isnanl.h, lchmod.h, getdomainname.h: declared
    by gnulib but not in the same header file as in glibc.

Here's first a proposed patch for getloadavg. glibc declares it in <stdlib.h>.


2008-10-18  Bruno Haible  <address@hidden>

        * lib/stdlib.in.h; Include <sys/loadavg.h> when needed for the
        getloadavg declaration.
        (getloadavg): New declaration.
        * lib/getloadavg.c: Include <stdlib.h> first.
        * m4/getloadavg.m4 (gl_GETLOADAVG): Require gl_STDLIB_H_DEFAULTS.
        Test whether sys/loadavg.h exists. Set HAVE_SYS_LOADAVG_H and
        HAVE_DECL_GETLOADAVG.
        * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_GETLOADAVG,
        HAVE_SYS_LOADAVG_H, HAVE_DECL_GETLOADAVG.
        * modules/getloadavg (Depends-on): Add stdlib.
        (configure.ac): Invoke gl_STDLIB_MODULE_INDICATOR.
        (Include): Specify <stdlib.h>.
        * modules/stdlib (Makefile.am): Substitute GNULIB_GETLOADAVG,
        HAVE_SYS_LOADAVG_H, HAVE_DECL_GETLOADAVG.

--- lib/stdlib.in.h.orig        2008-10-19 00:14:24.000000000 +0200
+++ lib/stdlib.in.h     2008-10-19 00:14:21.000000000 +0200
@@ -36,6 +36,11 @@
 #define _GL_STDLIB_H
 
 
+/* Solaris declares getloadavg() in <sys/loadavg.h>.  */
+#if @GNULIB_GETLOADAVG@ && @HAVE_SYS_LOADAVG_H@
+# include <sys/loadavg.h>
+#endif
+
 /* The definition of GL_LINK_WARNING is copied here.  */
 
 
@@ -103,6 +108,23 @@
 #endif
 
 
+#if @GNULIB_GETLOADAVG@
+# if address@hidden@
+/* Store max(NELEM,3) load average numbers in LOADAVG[].
+   The three numbers are the load average of the last 1 minute, the last 5
+   minutes, and the last 15 minutes, respectively.
+   LOADAVG is an array of NELEM numbers.  */
+extern int getloadavg (double loadavg[], int nelem);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getloadavg
+# define getloadavg(l,n) \
+    (GL_LINK_WARNING ("getloadavg is not portable - " \
+                      "use gnulib module getloadavg for portability"), \
+     getloadavg (l, n))
+#endif
+
+
 #if @GNULIB_GETSUBOPT@
 /* Assuming *OPTIONP is a comma separated list of elements of the form
    "token" or "token=value", getsubopt parses the first of these elements.
--- lib/getloadavg.c.orig       2008-10-19 00:14:23.000000000 +0200
+++ lib/getloadavg.c    2008-10-18 20:58:33.000000000 +0200
@@ -1,7 +1,7 @@
 /* Get the system load averages.
 
    Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994,
-   1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007 Free Software
+   1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008 Free Software
    Foundation, Inc.
 
    NOTE: The canonical source of this file is maintained with gnulib.
@@ -89,9 +89,11 @@
 # include <stdbool.h>
 #endif
 
+/* Specification.  */
+#include <stdlib.h>
+
 #include <errno.h>
 #include <stdio.h>
-#include <stdlib.h>
 
 /* Exclude all the code except the test program at the end
    if the system has its own `getloadavg' function.  */
--- m4/getloadavg.m4.orig       2008-10-19 00:14:24.000000000 +0200
+++ m4/getloadavg.m4    2008-10-18 21:14:46.000000000 +0200
@@ -1,7 +1,7 @@
 # Check for getloadavg.
 
 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2002, 2003,
-# 2006 Free Software Foundation, Inc.
+# 2006, 2008 Free Software Foundation, Inc.
 
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -13,7 +13,9 @@
 # gl_GETLOADAVG(LIBOBJDIR)
 # ------------------------
 AC_DEFUN([gl_GETLOADAVG],
-[gl_have_func=no # yes means we've found a way to get the load average.
+[AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+
+gl_have_func=no # yes means we've found a way to get the load average.
 
 # Make sure getloadavg.c is where it belongs, at configure-time.
 test -f "$srcdir/$1/getloadavg.c" ||
@@ -106,6 +108,20 @@
 LIBS=$gl_save_LIBS
 
 AC_SUBST(GETLOADAVG_LIBS)dnl
+
+# Test whether the system declares getloadavg. Solaris has the function
+# but declares it in <sys/loadavg.h>, not <stdlib.h>.
+AC_CHECK_HEADERS([sys/loadavg.h])
+if test $ac_cv_header_sys_loadavg_h = yes; then
+  HAVE_SYS_LOADAVG_H=1
+else
+  HAVE_SYS_LOADAVG_H=0
+fi
+AC_CHECK_DECL([getloadavg], [], [HAVE_DECL_GETLOADAVG=0],
+  [#if HAVE_SYS_LOADAVG_H
+   # include <sys/loadavg.h>
+   #endif
+   #include <stdlib.h>])
 ])# gl_GETLOADAVG
 
 
--- m4/stdlib_h.m4.orig 2008-10-19 00:14:24.000000000 +0200
+++ m4/stdlib_h.m4      2008-10-18 21:15:00.000000000 +0200
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 7
+# stdlib_h.m4 serial 8
 dnl Copyright (C) 2007, 2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -22,6 +22,7 @@
   GNULIB_MALLOC_POSIX=0;  AC_SUBST([GNULIB_MALLOC_POSIX])
   GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX])
   GNULIB_CALLOC_POSIX=0;  AC_SUBST([GNULIB_CALLOC_POSIX])
+  GNULIB_GETLOADAVG=0;    AC_SUBST([GNULIB_GETLOADAVG])
   GNULIB_GETSUBOPT=0;     AC_SUBST([GNULIB_GETSUBOPT])
   GNULIB_MKDTEMP=0;       AC_SUBST([GNULIB_MKDTEMP])
   GNULIB_MKSTEMP=0;       AC_SUBST([GNULIB_MKSTEMP])
@@ -39,7 +40,9 @@
   HAVE_RPMATCH=1;         AC_SUBST([HAVE_RPMATCH])
   HAVE_SETENV=1;          AC_SUBST([HAVE_SETENV])
   HAVE_STRTOD=1;          AC_SUBST([HAVE_STRTOD])
+  HAVE_SYS_LOADAVG_H=0;   AC_SUBST([HAVE_SYS_LOADAVG_H])
   HAVE_UNSETENV=1;        AC_SUBST([HAVE_UNSETENV])
+  HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG])
   REPLACE_MKSTEMP=0;      AC_SUBST([REPLACE_MKSTEMP])
   REPLACE_PUTENV=0;       AC_SUBST([REPLACE_PUTENV])
   REPLACE_STRTOD=0;       AC_SUBST([REPLACE_STRTOD])
--- modules/getloadavg.orig     2008-10-19 00:14:24.000000000 +0200
+++ modules/getloadavg  2008-10-18 20:57:38.000000000 +0200
@@ -6,6 +6,7 @@
 m4/getloadavg.m4
 
 Depends-on:
+stdlib
 cloexec
 xalloc
 c-strtod
@@ -15,10 +16,12 @@
 
 configure.ac:
 gl_GETLOADAVG([$gl_source_base])
+gl_STDLIB_MODULE_INDICATOR([getloadavg])
 
 Makefile.am:
 
 Include:
+<stdlib.h>
 
 License:
 GPL
--- modules/stdlib.orig 2008-10-19 00:14:24.000000000 +0200
+++ modules/stdlib      2008-10-18 21:15:26.000000000 +0200
@@ -28,6 +28,7 @@
              -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \
              -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \
              -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
+             -e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \
              -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
              -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
              -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
@@ -43,7 +44,9 @@
              -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
              -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \
              -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \
+             -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
              -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \
+             -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
              -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
              -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
              -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \





reply via email to

[Prev in Thread] Current Thread [Next in Thread]