aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert2011-02-07 23:05:03 -0800
committerPaul Eggert2011-02-07 23:05:03 -0800
commit79ab4b7f0e69ac1d76186346c33187b1fb02ff02 (patch)
tree38948150fa2119df0765c9004a27011caa9f3f50 /lib
parent226590f8d1247314abf913cc1bc77621f8a5bca9 (diff)
downloademacs-79ab4b7f0e69ac1d76186346c33187b1fb02ff02.tar.gz
emacs-79ab4b7f0e69ac1d76186346c33187b1fb02ff02.zip
Import getloadavg module from gnulib.
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.in173
-rw-r--r--lib/getloadavg.c1075
-rw-r--r--lib/gnulib.mk96
-rw-r--r--lib/stdlib.in.h725
4 files changed, 2052 insertions, 17 deletions
diff --git a/lib/Makefile.in b/lib/Makefile.in
index e50f9b31ef3..5e170d155e8 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -24,7 +24,7 @@
24# the same distribution terms as the rest of that program. 24# the same distribution terms as the rest of that program.
25# 25#
26# Generated by gnulib-tool. 26# Generated by gnulib-tool.
27# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files dtoastr getopt-gnu ignore-value mktime strftime 27# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files dtoastr getloadavg getopt-gnu ignore-value mktime strftime
28 28
29VPATH = @srcdir@ 29VPATH = @srcdir@
30pkgdatadir = $(datadir)/@PACKAGE@ 30pkgdatadir = $(datadir)/@PACKAGE@
@@ -51,14 +51,15 @@ subdir = lib
51ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 51ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
52am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \ 52am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \
53 $(top_srcdir)/m4/c-strtod.m4 $(top_srcdir)/m4/extensions.m4 \ 53 $(top_srcdir)/m4/c-strtod.m4 $(top_srcdir)/m4/extensions.m4 \
54 $(top_srcdir)/m4/getopt.m4 $(top_srcdir)/m4/gl-comp.m4 \ 54 $(top_srcdir)/m4/getloadavg.m4 $(top_srcdir)/m4/getopt.m4 \
55 $(top_srcdir)/m4/gnulib-common.m4 \ 55 $(top_srcdir)/m4/gl-comp.m4 $(top_srcdir)/m4/gnulib-common.m4 \
56 $(top_srcdir)/m4/include_next.m4 $(top_srcdir)/m4/mktime.m4 \ 56 $(top_srcdir)/m4/include_next.m4 $(top_srcdir)/m4/mktime.m4 \
57 $(top_srcdir)/m4/multiarch.m4 $(top_srcdir)/m4/stdbool.m4 \ 57 $(top_srcdir)/m4/multiarch.m4 $(top_srcdir)/m4/stdbool.m4 \
58 $(top_srcdir)/m4/stddef_h.m4 $(top_srcdir)/m4/strftime.m4 \ 58 $(top_srcdir)/m4/stddef_h.m4 $(top_srcdir)/m4/stdlib_h.m4 \
59 $(top_srcdir)/m4/time_h.m4 $(top_srcdir)/m4/time_r.m4 \ 59 $(top_srcdir)/m4/strftime.m4 $(top_srcdir)/m4/time_h.m4 \
60 $(top_srcdir)/m4/tm_gmtoff.m4 $(top_srcdir)/m4/unistd_h.m4 \ 60 $(top_srcdir)/m4/time_r.m4 $(top_srcdir)/m4/tm_gmtoff.m4 \
61 $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/configure.in 61 $(top_srcdir)/m4/unistd_h.m4 $(top_srcdir)/m4/wchar_t.m4 \
62 $(top_srcdir)/configure.in
62am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ 63am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
63 $(ACLOCAL_M4) 64 $(ACLOCAL_M4)
64mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs 65mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
@@ -134,6 +135,9 @@ GCONF_LIBS = @GCONF_LIBS@
134GETLOADAVG_LIBS = @GETLOADAVG_LIBS@ 135GETLOADAVG_LIBS = @GETLOADAVG_LIBS@
135GETOPT_H = @GETOPT_H@ 136GETOPT_H = @GETOPT_H@
136GMALLOC_OBJ = @GMALLOC_OBJ@ 137GMALLOC_OBJ = @GMALLOC_OBJ@
138GNULIB_ATOLL = @GNULIB_ATOLL@
139GNULIB_CALLOC_POSIX = @GNULIB_CALLOC_POSIX@
140GNULIB_CANONICALIZE_FILE_NAME = @GNULIB_CANONICALIZE_FILE_NAME@
137GNULIB_CHOWN = @GNULIB_CHOWN@ 141GNULIB_CHOWN = @GNULIB_CHOWN@
138GNULIB_CLOSE = @GNULIB_CLOSE@ 142GNULIB_CLOSE = @GNULIB_CLOSE@
139GNULIB_DUP2 = @GNULIB_DUP2@ 143GNULIB_DUP2 = @GNULIB_DUP2@
@@ -150,27 +154,47 @@ GNULIB_GETDOMAINNAME = @GNULIB_GETDOMAINNAME@
150GNULIB_GETDTABLESIZE = @GNULIB_GETDTABLESIZE@ 154GNULIB_GETDTABLESIZE = @GNULIB_GETDTABLESIZE@
151GNULIB_GETGROUPS = @GNULIB_GETGROUPS@ 155GNULIB_GETGROUPS = @GNULIB_GETGROUPS@
152GNULIB_GETHOSTNAME = @GNULIB_GETHOSTNAME@ 156GNULIB_GETHOSTNAME = @GNULIB_GETHOSTNAME@
157GNULIB_GETLOADAVG = @GNULIB_GETLOADAVG@
153GNULIB_GETLOGIN = @GNULIB_GETLOGIN@ 158GNULIB_GETLOGIN = @GNULIB_GETLOGIN@
154GNULIB_GETLOGIN_R = @GNULIB_GETLOGIN_R@ 159GNULIB_GETLOGIN_R = @GNULIB_GETLOGIN_R@
155GNULIB_GETPAGESIZE = @GNULIB_GETPAGESIZE@ 160GNULIB_GETPAGESIZE = @GNULIB_GETPAGESIZE@
161GNULIB_GETSUBOPT = @GNULIB_GETSUBOPT@
156GNULIB_GETUSERSHELL = @GNULIB_GETUSERSHELL@ 162GNULIB_GETUSERSHELL = @GNULIB_GETUSERSHELL@
163GNULIB_GRANTPT = @GNULIB_GRANTPT@
157GNULIB_LCHOWN = @GNULIB_LCHOWN@ 164GNULIB_LCHOWN = @GNULIB_LCHOWN@
158GNULIB_LINK = @GNULIB_LINK@ 165GNULIB_LINK = @GNULIB_LINK@
159GNULIB_LINKAT = @GNULIB_LINKAT@ 166GNULIB_LINKAT = @GNULIB_LINKAT@
160GNULIB_LSEEK = @GNULIB_LSEEK@ 167GNULIB_LSEEK = @GNULIB_LSEEK@
168GNULIB_MALLOC_POSIX = @GNULIB_MALLOC_POSIX@
169GNULIB_MKDTEMP = @GNULIB_MKDTEMP@
170GNULIB_MKOSTEMP = @GNULIB_MKOSTEMP@
171GNULIB_MKOSTEMPS = @GNULIB_MKOSTEMPS@
172GNULIB_MKSTEMP = @GNULIB_MKSTEMP@
173GNULIB_MKSTEMPS = @GNULIB_MKSTEMPS@
161GNULIB_MKTIME = @GNULIB_MKTIME@ 174GNULIB_MKTIME = @GNULIB_MKTIME@
162GNULIB_NANOSLEEP = @GNULIB_NANOSLEEP@ 175GNULIB_NANOSLEEP = @GNULIB_NANOSLEEP@
163GNULIB_PIPE = @GNULIB_PIPE@ 176GNULIB_PIPE = @GNULIB_PIPE@
164GNULIB_PIPE2 = @GNULIB_PIPE2@ 177GNULIB_PIPE2 = @GNULIB_PIPE2@
165GNULIB_PREAD = @GNULIB_PREAD@ 178GNULIB_PREAD = @GNULIB_PREAD@
179GNULIB_PTSNAME = @GNULIB_PTSNAME@
180GNULIB_PUTENV = @GNULIB_PUTENV@
166GNULIB_PWRITE = @GNULIB_PWRITE@ 181GNULIB_PWRITE = @GNULIB_PWRITE@
182GNULIB_RANDOM_R = @GNULIB_RANDOM_R@
167GNULIB_READLINK = @GNULIB_READLINK@ 183GNULIB_READLINK = @GNULIB_READLINK@
168GNULIB_READLINKAT = @GNULIB_READLINKAT@ 184GNULIB_READLINKAT = @GNULIB_READLINKAT@
185GNULIB_REALLOC_POSIX = @GNULIB_REALLOC_POSIX@
186GNULIB_REALPATH = @GNULIB_REALPATH@
169GNULIB_RMDIR = @GNULIB_RMDIR@ 187GNULIB_RMDIR = @GNULIB_RMDIR@
188GNULIB_RPMATCH = @GNULIB_RPMATCH@
189GNULIB_SETENV = @GNULIB_SETENV@
170GNULIB_SLEEP = @GNULIB_SLEEP@ 190GNULIB_SLEEP = @GNULIB_SLEEP@
171GNULIB_STRPTIME = @GNULIB_STRPTIME@ 191GNULIB_STRPTIME = @GNULIB_STRPTIME@
192GNULIB_STRTOD = @GNULIB_STRTOD@
193GNULIB_STRTOLL = @GNULIB_STRTOLL@
194GNULIB_STRTOULL = @GNULIB_STRTOULL@
172GNULIB_SYMLINK = @GNULIB_SYMLINK@ 195GNULIB_SYMLINK = @GNULIB_SYMLINK@
173GNULIB_SYMLINKAT = @GNULIB_SYMLINKAT@ 196GNULIB_SYMLINKAT = @GNULIB_SYMLINKAT@
197GNULIB_SYSTEM_POSIX = @GNULIB_SYSTEM_POSIX@
174GNULIB_TIMEGM = @GNULIB_TIMEGM@ 198GNULIB_TIMEGM = @GNULIB_TIMEGM@
175GNULIB_TIME_R = @GNULIB_TIME_R@ 199GNULIB_TIME_R = @GNULIB_TIME_R@
176GNULIB_TTYNAME_R = @GNULIB_TTYNAME_R@ 200GNULIB_TTYNAME_R = @GNULIB_TTYNAME_R@
@@ -178,8 +202,11 @@ GNULIB_UNISTD_H_GETOPT = @GNULIB_UNISTD_H_GETOPT@
178GNULIB_UNISTD_H_SIGPIPE = @GNULIB_UNISTD_H_SIGPIPE@ 202GNULIB_UNISTD_H_SIGPIPE = @GNULIB_UNISTD_H_SIGPIPE@
179GNULIB_UNLINK = @GNULIB_UNLINK@ 203GNULIB_UNLINK = @GNULIB_UNLINK@
180GNULIB_UNLINKAT = @GNULIB_UNLINKAT@ 204GNULIB_UNLINKAT = @GNULIB_UNLINKAT@
205GNULIB_UNLOCKPT = @GNULIB_UNLOCKPT@
206GNULIB_UNSETENV = @GNULIB_UNSETENV@
181GNULIB_USLEEP = @GNULIB_USLEEP@ 207GNULIB_USLEEP = @GNULIB_USLEEP@
182GNULIB_WRITE = @GNULIB_WRITE@ 208GNULIB_WRITE = @GNULIB_WRITE@
209GNULIB__EXIT = @GNULIB__EXIT@
183GNU_OBJC_CFLAGS = @GNU_OBJC_CFLAGS@ 210GNU_OBJC_CFLAGS = @GNU_OBJC_CFLAGS@
184GREP = @GREP@ 211GREP = @GREP@
185GTK_CFLAGS = @GTK_CFLAGS@ 212GTK_CFLAGS = @GTK_CFLAGS@
@@ -187,15 +214,20 @@ GTK_LIBS = @GTK_LIBS@
187GTK_OBJ = @GTK_OBJ@ 214GTK_OBJ = @GTK_OBJ@
188GZIP_INFO = @GZIP_INFO@ 215GZIP_INFO = @GZIP_INFO@
189GZIP_PROG = @GZIP_PROG@ 216GZIP_PROG = @GZIP_PROG@
217HAVE_ATOLL = @HAVE_ATOLL@
218HAVE_CANONICALIZE_FILE_NAME = @HAVE_CANONICALIZE_FILE_NAME@
190HAVE_CHOWN = @HAVE_CHOWN@ 219HAVE_CHOWN = @HAVE_CHOWN@
191HAVE_DECL_ENVIRON = @HAVE_DECL_ENVIRON@ 220HAVE_DECL_ENVIRON = @HAVE_DECL_ENVIRON@
192HAVE_DECL_FCHDIR = @HAVE_DECL_FCHDIR@ 221HAVE_DECL_FCHDIR = @HAVE_DECL_FCHDIR@
193HAVE_DECL_GETDOMAINNAME = @HAVE_DECL_GETDOMAINNAME@ 222HAVE_DECL_GETDOMAINNAME = @HAVE_DECL_GETDOMAINNAME@
223HAVE_DECL_GETLOADAVG = @HAVE_DECL_GETLOADAVG@
194HAVE_DECL_GETLOGIN_R = @HAVE_DECL_GETLOGIN_R@ 224HAVE_DECL_GETLOGIN_R = @HAVE_DECL_GETLOGIN_R@
195HAVE_DECL_GETPAGESIZE = @HAVE_DECL_GETPAGESIZE@ 225HAVE_DECL_GETPAGESIZE = @HAVE_DECL_GETPAGESIZE@
196HAVE_DECL_GETUSERSHELL = @HAVE_DECL_GETUSERSHELL@ 226HAVE_DECL_GETUSERSHELL = @HAVE_DECL_GETUSERSHELL@
197HAVE_DECL_LOCALTIME_R = @HAVE_DECL_LOCALTIME_R@ 227HAVE_DECL_LOCALTIME_R = @HAVE_DECL_LOCALTIME_R@
228HAVE_DECL_SETENV = @HAVE_DECL_SETENV@
198HAVE_DECL_TTYNAME_R = @HAVE_DECL_TTYNAME_R@ 229HAVE_DECL_TTYNAME_R = @HAVE_DECL_TTYNAME_R@
230HAVE_DECL_UNSETENV = @HAVE_DECL_UNSETENV@
199HAVE_DUP2 = @HAVE_DUP2@ 231HAVE_DUP2 = @HAVE_DUP2@
200HAVE_DUP3 = @HAVE_DUP3@ 232HAVE_DUP3 = @HAVE_DUP3@
201HAVE_EUIDACCESS = @HAVE_EUIDACCESS@ 233HAVE_EUIDACCESS = @HAVE_EUIDACCESS@
@@ -210,30 +242,50 @@ HAVE_GETHOSTNAME = @HAVE_GETHOSTNAME@
210HAVE_GETLOGIN = @HAVE_GETLOGIN@ 242HAVE_GETLOGIN = @HAVE_GETLOGIN@
211HAVE_GETOPT_H = @HAVE_GETOPT_H@ 243HAVE_GETOPT_H = @HAVE_GETOPT_H@
212HAVE_GETPAGESIZE = @HAVE_GETPAGESIZE@ 244HAVE_GETPAGESIZE = @HAVE_GETPAGESIZE@
245HAVE_GETSUBOPT = @HAVE_GETSUBOPT@
246HAVE_GRANTPT = @HAVE_GRANTPT@
213HAVE_LCHOWN = @HAVE_LCHOWN@ 247HAVE_LCHOWN = @HAVE_LCHOWN@
214HAVE_LINK = @HAVE_LINK@ 248HAVE_LINK = @HAVE_LINK@
215HAVE_LINKAT = @HAVE_LINKAT@ 249HAVE_LINKAT = @HAVE_LINKAT@
216HAVE_MAKEINFO = @HAVE_MAKEINFO@ 250HAVE_MAKEINFO = @HAVE_MAKEINFO@
251HAVE_MKDTEMP = @HAVE_MKDTEMP@
252HAVE_MKOSTEMP = @HAVE_MKOSTEMP@
253HAVE_MKOSTEMPS = @HAVE_MKOSTEMPS@
254HAVE_MKSTEMP = @HAVE_MKSTEMP@
255HAVE_MKSTEMPS = @HAVE_MKSTEMPS@
217HAVE_NANOSLEEP = @HAVE_NANOSLEEP@ 256HAVE_NANOSLEEP = @HAVE_NANOSLEEP@
218HAVE_OS_H = @HAVE_OS_H@ 257HAVE_OS_H = @HAVE_OS_H@
219HAVE_PIPE = @HAVE_PIPE@ 258HAVE_PIPE = @HAVE_PIPE@
220HAVE_PIPE2 = @HAVE_PIPE2@ 259HAVE_PIPE2 = @HAVE_PIPE2@
221HAVE_PREAD = @HAVE_PREAD@ 260HAVE_PREAD = @HAVE_PREAD@
261HAVE_PTSNAME = @HAVE_PTSNAME@
222HAVE_PWRITE = @HAVE_PWRITE@ 262HAVE_PWRITE = @HAVE_PWRITE@
263HAVE_RANDOM_H = @HAVE_RANDOM_H@
264HAVE_RANDOM_R = @HAVE_RANDOM_R@
223HAVE_READLINK = @HAVE_READLINK@ 265HAVE_READLINK = @HAVE_READLINK@
224HAVE_READLINKAT = @HAVE_READLINKAT@ 266HAVE_READLINKAT = @HAVE_READLINKAT@
267HAVE_REALPATH = @HAVE_REALPATH@
268HAVE_RPMATCH = @HAVE_RPMATCH@
269HAVE_SETENV = @HAVE_SETENV@
225HAVE_SLEEP = @HAVE_SLEEP@ 270HAVE_SLEEP = @HAVE_SLEEP@
226HAVE_STRPTIME = @HAVE_STRPTIME@ 271HAVE_STRPTIME = @HAVE_STRPTIME@
272HAVE_STRTOD = @HAVE_STRTOD@
273HAVE_STRTOLL = @HAVE_STRTOLL@
274HAVE_STRTOULL = @HAVE_STRTOULL@
275HAVE_STRUCT_RANDOM_DATA = @HAVE_STRUCT_RANDOM_DATA@
227HAVE_SYMLINK = @HAVE_SYMLINK@ 276HAVE_SYMLINK = @HAVE_SYMLINK@
228HAVE_SYMLINKAT = @HAVE_SYMLINKAT@ 277HAVE_SYMLINKAT = @HAVE_SYMLINKAT@
278HAVE_SYS_LOADAVG_H = @HAVE_SYS_LOADAVG_H@
229HAVE_SYS_PARAM_H = @HAVE_SYS_PARAM_H@ 279HAVE_SYS_PARAM_H = @HAVE_SYS_PARAM_H@
230HAVE_TIMEGM = @HAVE_TIMEGM@ 280HAVE_TIMEGM = @HAVE_TIMEGM@
231HAVE_UNISTD_H = @HAVE_UNISTD_H@ 281HAVE_UNISTD_H = @HAVE_UNISTD_H@
232HAVE_UNLINKAT = @HAVE_UNLINKAT@ 282HAVE_UNLINKAT = @HAVE_UNLINKAT@
283HAVE_UNLOCKPT = @HAVE_UNLOCKPT@
233HAVE_USLEEP = @HAVE_USLEEP@ 284HAVE_USLEEP = @HAVE_USLEEP@
234HAVE_WCHAR_T = @HAVE_WCHAR_T@ 285HAVE_WCHAR_T = @HAVE_WCHAR_T@
235HAVE_XSERVER = @HAVE_XSERVER@ 286HAVE_XSERVER = @HAVE_XSERVER@
236HAVE__BOOL = @HAVE__BOOL@ 287HAVE__BOOL = @HAVE__BOOL@
288HAVE__EXIT = @HAVE__EXIT@
237IMAGEMAGICK_CFLAGS = @IMAGEMAGICK_CFLAGS@ 289IMAGEMAGICK_CFLAGS = @IMAGEMAGICK_CFLAGS@
238IMAGEMAGICK_LIBS = @IMAGEMAGICK_LIBS@ 290IMAGEMAGICK_LIBS = @IMAGEMAGICK_LIBS@
239INCLUDE_NEXT = @INCLUDE_NEXT@ 291INCLUDE_NEXT = @INCLUDE_NEXT@
@@ -300,10 +352,12 @@ M_FILE = @M_FILE@
300NEED_SETGID = @NEED_SETGID@ 352NEED_SETGID = @NEED_SETGID@
301NEXT_AS_FIRST_DIRECTIVE_GETOPT_H = @NEXT_AS_FIRST_DIRECTIVE_GETOPT_H@ 353NEXT_AS_FIRST_DIRECTIVE_GETOPT_H = @NEXT_AS_FIRST_DIRECTIVE_GETOPT_H@
302NEXT_AS_FIRST_DIRECTIVE_STDDEF_H = @NEXT_AS_FIRST_DIRECTIVE_STDDEF_H@ 354NEXT_AS_FIRST_DIRECTIVE_STDDEF_H = @NEXT_AS_FIRST_DIRECTIVE_STDDEF_H@
355NEXT_AS_FIRST_DIRECTIVE_STDLIB_H = @NEXT_AS_FIRST_DIRECTIVE_STDLIB_H@
303NEXT_AS_FIRST_DIRECTIVE_TIME_H = @NEXT_AS_FIRST_DIRECTIVE_TIME_H@ 356NEXT_AS_FIRST_DIRECTIVE_TIME_H = @NEXT_AS_FIRST_DIRECTIVE_TIME_H@
304NEXT_AS_FIRST_DIRECTIVE_UNISTD_H = @NEXT_AS_FIRST_DIRECTIVE_UNISTD_H@ 357NEXT_AS_FIRST_DIRECTIVE_UNISTD_H = @NEXT_AS_FIRST_DIRECTIVE_UNISTD_H@
305NEXT_GETOPT_H = @NEXT_GETOPT_H@ 358NEXT_GETOPT_H = @NEXT_GETOPT_H@
306NEXT_STDDEF_H = @NEXT_STDDEF_H@ 359NEXT_STDDEF_H = @NEXT_STDDEF_H@
360NEXT_STDLIB_H = @NEXT_STDLIB_H@
307NEXT_TIME_H = @NEXT_TIME_H@ 361NEXT_TIME_H = @NEXT_TIME_H@
308NEXT_UNISTD_H = @NEXT_UNISTD_H@ 362NEXT_UNISTD_H = @NEXT_UNISTD_H@
309NS_OBJ = @NS_OBJ@ 363NS_OBJ = @NS_OBJ@
@@ -330,6 +384,8 @@ PROFILING_CFLAGS = @PROFILING_CFLAGS@
330PTHREAD_H_DEFINES_STRUCT_TIMESPEC = @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ 384PTHREAD_H_DEFINES_STRUCT_TIMESPEC = @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
331RALLOC_OBJ = @RALLOC_OBJ@ 385RALLOC_OBJ = @RALLOC_OBJ@
332RANLIB = @RANLIB@ 386RANLIB = @RANLIB@
387REPLACE_CALLOC = @REPLACE_CALLOC@
388REPLACE_CANONICALIZE_FILE_NAME = @REPLACE_CANONICALIZE_FILE_NAME@
333REPLACE_CHOWN = @REPLACE_CHOWN@ 389REPLACE_CHOWN = @REPLACE_CHOWN@
334REPLACE_CLOSE = @REPLACE_CLOSE@ 390REPLACE_CLOSE = @REPLACE_CLOSE@
335REPLACE_DUP = @REPLACE_DUP@ 391REPLACE_DUP = @REPLACE_DUP@
@@ -345,19 +401,27 @@ REPLACE_LINK = @REPLACE_LINK@
345REPLACE_LINKAT = @REPLACE_LINKAT@ 401REPLACE_LINKAT = @REPLACE_LINKAT@
346REPLACE_LOCALTIME_R = @REPLACE_LOCALTIME_R@ 402REPLACE_LOCALTIME_R = @REPLACE_LOCALTIME_R@
347REPLACE_LSEEK = @REPLACE_LSEEK@ 403REPLACE_LSEEK = @REPLACE_LSEEK@
404REPLACE_MALLOC = @REPLACE_MALLOC@
405REPLACE_MKSTEMP = @REPLACE_MKSTEMP@
348REPLACE_MKTIME = @REPLACE_MKTIME@ 406REPLACE_MKTIME = @REPLACE_MKTIME@
349REPLACE_NANOSLEEP = @REPLACE_NANOSLEEP@ 407REPLACE_NANOSLEEP = @REPLACE_NANOSLEEP@
350REPLACE_NULL = @REPLACE_NULL@ 408REPLACE_NULL = @REPLACE_NULL@
351REPLACE_PREAD = @REPLACE_PREAD@ 409REPLACE_PREAD = @REPLACE_PREAD@
410REPLACE_PUTENV = @REPLACE_PUTENV@
352REPLACE_PWRITE = @REPLACE_PWRITE@ 411REPLACE_PWRITE = @REPLACE_PWRITE@
353REPLACE_READLINK = @REPLACE_READLINK@ 412REPLACE_READLINK = @REPLACE_READLINK@
413REPLACE_REALLOC = @REPLACE_REALLOC@
414REPLACE_REALPATH = @REPLACE_REALPATH@
354REPLACE_RMDIR = @REPLACE_RMDIR@ 415REPLACE_RMDIR = @REPLACE_RMDIR@
416REPLACE_SETENV = @REPLACE_SETENV@
355REPLACE_SLEEP = @REPLACE_SLEEP@ 417REPLACE_SLEEP = @REPLACE_SLEEP@
418REPLACE_STRTOD = @REPLACE_STRTOD@
356REPLACE_SYMLINK = @REPLACE_SYMLINK@ 419REPLACE_SYMLINK = @REPLACE_SYMLINK@
357REPLACE_TIMEGM = @REPLACE_TIMEGM@ 420REPLACE_TIMEGM = @REPLACE_TIMEGM@
358REPLACE_TTYNAME_R = @REPLACE_TTYNAME_R@ 421REPLACE_TTYNAME_R = @REPLACE_TTYNAME_R@
359REPLACE_UNLINK = @REPLACE_UNLINK@ 422REPLACE_UNLINK = @REPLACE_UNLINK@
360REPLACE_UNLINKAT = @REPLACE_UNLINKAT@ 423REPLACE_UNLINKAT = @REPLACE_UNLINKAT@
424REPLACE_UNSETENV = @REPLACE_UNSETENV@
361REPLACE_USLEEP = @REPLACE_USLEEP@ 425REPLACE_USLEEP = @REPLACE_USLEEP@
362REPLACE_WRITE = @REPLACE_WRITE@ 426REPLACE_WRITE = @REPLACE_WRITE@
363RSVG_CFLAGS = @RSVG_CFLAGS@ 427RSVG_CFLAGS = @RSVG_CFLAGS@
@@ -471,23 +535,23 @@ x_default_search_path = @x_default_search_path@
471# present in all Makefile.am that need it. This is ensured by the applicability 535# present in all Makefile.am that need it. This is ensured by the applicability
472# 'all' defined above. 536# 'all' defined above.
473BUILT_SOURCES = arg-nonnull.h c++defs.h $(GETOPT_H) $(STDBOOL_H) \ 537BUILT_SOURCES = arg-nonnull.h c++defs.h $(GETOPT_H) $(STDBOOL_H) \
474 $(STDDEF_H) time.h unistd.h warn-on-use.h 538 $(STDDEF_H) stdlib.h time.h unistd.h warn-on-use.h
475EXTRA_DIST = $(top_srcdir)/./arg-nonnull.h $(top_srcdir)/./c++defs.h \ 539EXTRA_DIST = $(top_srcdir)/./arg-nonnull.h $(top_srcdir)/./c++defs.h \
476 ftoastr.c ftoastr.h getopt.c getopt.in.h getopt1.c \ 540 ftoastr.c ftoastr.h getloadavg.c getopt.c getopt.in.h \
477 getopt_int.h intprops.h mktime-internal.h mktime.c \ 541 getopt1.c getopt_int.h intprops.h mktime-internal.h mktime.c \
478 stdbool.in.h stddef.in.h strftime.c strftime.h time.in.h \ 542 stdbool.in.h stddef.in.h stdlib.in.h strftime.c strftime.h \
479 time_r.c unistd.in.h $(top_srcdir)/./warn-on-use.h 543 time.in.h time_r.c unistd.in.h $(top_srcdir)/./warn-on-use.h
480MOSTLYCLEANFILES = core *.stackdump arg-nonnull.h arg-nonnull.h-t \ 544MOSTLYCLEANFILES = core *.stackdump arg-nonnull.h arg-nonnull.h-t \
481 c++defs.h c++defs.h-t getopt.h getopt.h-t stdbool.h \ 545 c++defs.h c++defs.h-t getopt.h getopt.h-t stdbool.h \
482 stdbool.h-t stddef.h stddef.h-t time.h time.h-t unistd.h \ 546 stdbool.h-t stddef.h stddef.h-t stdlib.h stdlib.h-t time.h \
483 unistd.h-t warn-on-use.h warn-on-use.h-t 547 time.h-t unistd.h unistd.h-t warn-on-use.h warn-on-use.h-t
484noinst_LIBRARIES = libgnu.a 548noinst_LIBRARIES = libgnu.a
485DEFAULT_INCLUDES = -I. -I../src -I$(top_srcdir)/src 549DEFAULT_INCLUDES = -I. -I../src -I$(top_srcdir)/src
486libgnu_a_SOURCES = dtoastr.c gettext.h ignore-value.h 550libgnu_a_SOURCES = dtoastr.c gettext.h ignore-value.h
487libgnu_a_LIBADD = $(gl_LIBOBJS) 551libgnu_a_LIBADD = $(gl_LIBOBJS)
488libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) 552libgnu_a_DEPENDENCIES = $(gl_LIBOBJS)
489EXTRA_libgnu_a_SOURCES = ftoastr.c getopt.c getopt1.c mktime.c \ 553EXTRA_libgnu_a_SOURCES = ftoastr.c getloadavg.c getopt.c getopt1.c \
490 strftime.c time_r.c 554 mktime.c strftime.c time_r.c
491ARG_NONNULL_H = arg-nonnull.h 555ARG_NONNULL_H = arg-nonnull.h
492CXXDEFS_H = c++defs.h 556CXXDEFS_H = c++defs.h
493WARN_ON_USE_H = warn-on-use.h 557WARN_ON_USE_H = warn-on-use.h
@@ -542,6 +606,7 @@ distclean-compile:
542 606
543@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dtoastr.Po@am__quote@ 607@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dtoastr.Po@am__quote@
544@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftoastr.Po@am__quote@ 608@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftoastr.Po@am__quote@
609@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getloadavg.Po@am__quote@
545@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@ 610@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@
546@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt1.Po@am__quote@ 611@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt1.Po@am__quote@
547@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mktime.Po@am__quote@ 612@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mktime.Po@am__quote@
@@ -818,6 +883,82 @@ stddef.h: stddef.in.h
818 } > $@-t && \ 883 } > $@-t && \
819 mv $@-t $@ 884 mv $@-t $@
820 885
886# We need the following in order to create <stdlib.h> when the system
887# doesn't have one that works with the given compiler.
888stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
889 $(AM_V_GEN)rm -f $@-t $@ && \
890 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
891 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
892 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
893 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
894 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
895 -e 's|@''GNULIB__EXIT''@|$(GNULIB__EXIT)|g' \
896 -e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \
897 -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \
898 -e 's|@''GNULIB_CANONICALIZE_FILE_NAME''@|$(GNULIB_CANONICALIZE_FILE_NAME)|g' \
899 -e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \
900 -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
901 -e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \
902 -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
903 -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
904 -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \
905 -e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \
906 -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
907 -e 's|@''GNULIB_MKSTEMPS''@|$(GNULIB_MKSTEMPS)|g' \
908 -e 's|@''GNULIB_PTSNAME''@|$(GNULIB_PTSNAME)|g' \
909 -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
910 -e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|g' \
911 -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \
912 -e 's|@''GNULIB_REALPATH''@|$(GNULIB_REALPATH)|g' \
913 -e 's|@''GNULIB_RPMATCH''@|$(GNULIB_RPMATCH)|g' \
914 -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \
915 -e 's|@''GNULIB_STRTOD''@|$(GNULIB_STRTOD)|g' \
916 -e 's|@''GNULIB_STRTOLL''@|$(GNULIB_STRTOLL)|g' \
917 -e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \
918 -e 's|@''GNULIB_SYSTEM_POSIX''@|$(GNULIB_SYSTEM_POSIX)|g' \
919 -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \
920 -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
921 -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
922 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
923 -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \
924 -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
925 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
926 -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \
927 -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
928 -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \
929 -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \
930 -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \
931 -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \
932 -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \
933 -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \
934 -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
935 -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \
936 -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
937 -e 's|@''HAVE_DECL_SETENV''@|$(HAVE_DECL_SETENV)|g' \
938 -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \
939 -e 's|@''HAVE_STRTOLL''@|$(HAVE_STRTOLL)|g' \
940 -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \
941 -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \
942 -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
943 -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \
944 -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \
945 -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
946 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
947 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
948 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
949 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
950 -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
951 -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \
952 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
953 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
954 -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \
955 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
956 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
957 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
958 < $(srcdir)/stdlib.in.h; \
959 } > $@-t && \
960 mv $@-t $@
961
821# We need the following in order to create <time.h> when the system 962# We need the following in order to create <time.h> when the system
822# doesn't have one that works with the given compiler. 963# doesn't have one that works with the given compiler.
823time.h: time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) 964time.h: time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
diff --git a/lib/getloadavg.c b/lib/getloadavg.c
new file mode 100644
index 00000000000..96a6aa4d49c
--- /dev/null
+++ b/lib/getloadavg.c
@@ -0,0 +1,1075 @@
1/* Get the system load averages.
2
3 Copyright (C) 1985-1989, 1991-1995, 1997, 1999-2000, 2003-2011 Free Software
4 Foundation, Inc.
5
6 NOTE: The canonical source of this file is maintained with gnulib.
7 Bugs can be reported to bug-gnulib@gnu.org.
8
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22/* Compile-time symbols that this file uses:
23
24 HAVE_PSTAT_GETDYNAMIC Define this if your system has the
25 pstat_getdynamic function. I think it
26 is unique to HPUX9. The best way to get the
27 definition is through the AC_FUNC_GETLOADAVG
28 macro that comes with autoconf 2.13 or newer.
29 If that isn't an option, then just put
30 AC_CHECK_FUNCS(pstat_getdynamic) in your
31 configure.in file.
32 HAVE_LIBPERFSTAT Define this if your system has the
33 perfstat_cpu_total function in libperfstat (AIX).
34 FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist.
35 KERNEL_FILE Name of the kernel file to nlist.
36 LDAV_CVT() Scale the load average from the kernel.
37 Returns a double.
38 LDAV_SYMBOL Name of kernel symbol giving load average.
39 LOAD_AVE_TYPE Type of the load average array in the kernel.
40 Must be defined unless one of
41 apollo, DGUX, NeXT, or UMAX is defined;
42 or we have libkstat;
43 otherwise, no load average is available.
44 HAVE_NLIST_H nlist.h is available. NLIST_STRUCT defaults
45 to this.
46 NLIST_STRUCT Include nlist.h, not a.out.h.
47 N_NAME_POINTER The nlist n_name element is a pointer,
48 not an array.
49 HAVE_STRUCT_NLIST_N_UN_N_NAME `n_un.n_name' is member of `struct nlist'.
50 LINUX_LDAV_FILE [__linux__, __CYGWIN__]: File containing
51 load averages.
52
53 Specific system predefines this file uses, aside from setting
54 default values if not emacs:
55
56 apollo
57 BSD Real BSD, not just BSD-like.
58 convex
59 DGUX
60 eunice UNIX emulator under VMS.
61 hpux
62 __MSDOS__ No-op for MSDOS.
63 NeXT
64 sgi
65 sequent Sequent Dynix 3.x.x (BSD)
66 _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV)
67 sony_news NEWS-OS (works at least for 4.1C)
68 UMAX
69 UMAX4_3
70 VMS
71 WINDOWS32 No-op for Windows95/NT.
72 __linux__ Linux: assumes /proc file system mounted.
73 Support from Michael K. Johnson.
74 __CYGWIN__ Cygwin emulates linux /proc/loadavg.
75 __NetBSD__ NetBSD: assumes /kern file system mounted.
76
77 In addition, to avoid nesting many #ifdefs, we internally set
78 LDAV_DONE to indicate that the load average has been computed.
79
80 We also #define LDAV_PRIVILEGED if a program will require
81 special installation to be able to call getloadavg. */
82
83/* "configure" defines CONFIGURING_GETLOADAVG to sidestep problems
84 with partially-configured source directories. */
85
86#ifndef CONFIGURING_GETLOADAVG
87# include <config.h>
88# include <stdbool.h>
89#endif
90
91/* Specification. */
92#include <stdlib.h>
93
94#include <errno.h>
95#include <stdio.h>
96
97/* Exclude all the code except the test program at the end
98 if the system has its own `getloadavg' function. */
99
100#ifndef HAVE_GETLOADAVG
101
102# include <sys/types.h>
103
104/* Both the Emacs and non-Emacs sections want this. Some
105 configuration files' definitions for the LOAD_AVE_CVT macro (like
106 sparc.h's) use macros like FSCALE, defined here. */
107# if defined (unix) || defined (__unix)
108# include <sys/param.h>
109# endif
110
111# include "intprops.h"
112
113/* The existing Emacs configuration files define a macro called
114 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and
115 returns the load average multiplied by 100. What we actually want
116 is a macro called LDAV_CVT, which returns the load average as an
117 unmultiplied double.
118
119 For backwards compatibility, we'll define LDAV_CVT in terms of
120 LOAD_AVE_CVT, but future machine config files should just define
121 LDAV_CVT directly. */
122
123# if !defined (LDAV_CVT) && defined (LOAD_AVE_CVT)
124# define LDAV_CVT(n) (LOAD_AVE_CVT (n) / 100.0)
125# endif
126
127# if !defined (BSD) && defined (ultrix)
128/* Ultrix behaves like BSD on Vaxen. */
129# define BSD
130# endif
131
132# ifdef NeXT
133/* NeXT in the 2.{0,1,2} releases defines BSD in <sys/param.h>, which
134 conflicts with the definition understood in this file, that this
135 really is BSD. */
136# undef BSD
137
138/* NeXT defines FSCALE in <sys/param.h>. However, we take FSCALE being
139 defined to mean that the nlist method should be used, which is not true. */
140# undef FSCALE
141# endif
142
143/* Same issues as for NeXT apply to the HURD-based GNU system. */
144# ifdef __GNU__
145# undef BSD
146# undef FSCALE
147# endif /* __GNU__ */
148
149/* Set values that are different from the defaults, which are
150 set a little farther down with #ifndef. */
151
152
153/* Some shorthands. */
154
155# if defined (HPUX) && !defined (hpux)
156# define hpux
157# endif
158
159# if defined (__hpux) && !defined (hpux)
160# define hpux
161# endif
162
163# if defined (__sun) && !defined (sun)
164# define sun
165# endif
166
167# if defined (hp300) && !defined (hpux)
168# define MORE_BSD
169# endif
170
171# if defined (ultrix) && defined (mips)
172# define decstation
173# endif
174
175# if defined (__SVR4) && !defined (SVR4)
176# define SVR4
177# endif
178
179# if (defined (sun) && defined (SVR4)) || defined (SOLARIS2)
180# define SUNOS_5
181# endif
182
183# if defined (__osf__) && (defined (__alpha) || defined (__alpha__))
184# define OSF_ALPHA
185# include <sys/mbuf.h>
186# include <sys/socket.h>
187# include <net/route.h>
188# include <sys/table.h>
189/* Tru64 4.0D's table.h redefines sys */
190# undef sys
191# endif
192
193# if defined (__osf__) && (defined (mips) || defined (__mips__))
194# define OSF_MIPS
195# include <sys/table.h>
196# endif
197
198/* UTek's /bin/cc on the 4300 has no architecture specific cpp define by
199 default, but _MACH_IND_SYS_TYPES is defined in <sys/types.h>. Combine
200 that with a couple of other things and we'll have a unique match. */
201# if !defined (tek4300) && defined (unix) && defined (m68k) && defined (mc68000) && defined (mc68020) && defined (_MACH_IND_SYS_TYPES)
202# define tek4300 /* Define by emacs, but not by other users. */
203# endif
204
205
206/* VAX C can't handle multi-line #ifs, or lines longer than 256 chars. */
207# ifndef LOAD_AVE_TYPE
208
209# ifdef MORE_BSD
210# define LOAD_AVE_TYPE long
211# endif
212
213# ifdef sun
214# define LOAD_AVE_TYPE long
215# endif
216
217# ifdef decstation
218# define LOAD_AVE_TYPE long
219# endif
220
221# ifdef _SEQUENT_
222# define LOAD_AVE_TYPE long
223# endif
224
225# ifdef sgi
226# define LOAD_AVE_TYPE long
227# endif
228
229# ifdef SVR4
230# define LOAD_AVE_TYPE long
231# endif
232
233# ifdef sony_news
234# define LOAD_AVE_TYPE long
235# endif
236
237# ifdef sequent
238# define LOAD_AVE_TYPE long
239# endif
240
241# ifdef OSF_ALPHA
242# define LOAD_AVE_TYPE long
243# endif
244
245# if defined (ardent) && defined (titan)
246# define LOAD_AVE_TYPE long
247# endif
248
249# ifdef tek4300
250# define LOAD_AVE_TYPE long
251# endif
252
253# if defined (alliant) && defined (i860) /* Alliant FX/2800 */
254# define LOAD_AVE_TYPE long
255# endif
256
257# if defined _AIX && ! defined HAVE_LIBPERFSTAT
258# define LOAD_AVE_TYPE long
259# endif
260
261# ifdef convex
262# define LOAD_AVE_TYPE double
263# ifndef LDAV_CVT
264# define LDAV_CVT(n) (n)
265# endif
266# endif
267
268# endif /* No LOAD_AVE_TYPE. */
269
270# ifdef OSF_ALPHA
271/* <sys/param.h> defines an incorrect value for FSCALE on Alpha OSF/1,
272 according to ghazi@noc.rutgers.edu. */
273# undef FSCALE
274# define FSCALE 1024.0
275# endif
276
277# if defined (alliant) && defined (i860) /* Alliant FX/2800 */
278/* <sys/param.h> defines an incorrect value for FSCALE on an
279 Alliant FX/2800 Concentrix 2.2, according to ghazi@noc.rutgers.edu. */
280# undef FSCALE
281# define FSCALE 100.0
282# endif
283
284
285# ifndef FSCALE
286
287/* SunOS and some others define FSCALE in sys/param.h. */
288
289# ifdef MORE_BSD
290# define FSCALE 2048.0
291# endif
292
293# if defined (MIPS) || defined (SVR4) || defined (decstation)
294# define FSCALE 256
295# endif
296
297# if defined (sgi) || defined (sequent)
298/* Sometimes both MIPS and sgi are defined, so FSCALE was just defined
299 above under #ifdef MIPS. But we want the sgi value. */
300# undef FSCALE
301# define FSCALE 1000.0
302# endif
303
304# if defined (ardent) && defined (titan)
305# define FSCALE 65536.0
306# endif
307
308# ifdef tek4300
309# define FSCALE 100.0
310# endif
311
312# if defined _AIX && !defined HAVE_LIBPERFSTAT
313# define FSCALE 65536.0
314# endif
315
316# endif /* Not FSCALE. */
317
318# if !defined (LDAV_CVT) && defined (FSCALE)
319# define LDAV_CVT(n) (((double) (n)) / FSCALE)
320# endif
321
322# ifndef NLIST_STRUCT
323# if HAVE_NLIST_H
324# define NLIST_STRUCT
325# endif
326# endif
327
328# if defined (sgi) || (defined (mips) && !defined (BSD))
329# define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31))
330# endif
331
332
333# if !defined (KERNEL_FILE) && defined (sequent)
334# define KERNEL_FILE "/dynix"
335# endif
336
337# if !defined (KERNEL_FILE) && defined (hpux)
338# define KERNEL_FILE "/hp-ux"
339# endif
340
341# if !defined (KERNEL_FILE) && (defined (_SEQUENT_) || defined (MIPS) || defined (SVR4) || defined (ISC) || defined (sgi) || (defined (ardent) && defined (titan)))
342# define KERNEL_FILE "/unix"
343# endif
344
345
346# if !defined (LDAV_SYMBOL) && defined (alliant)
347# define LDAV_SYMBOL "_Loadavg"
348# endif
349
350# if !defined (LDAV_SYMBOL) && ((defined (hpux) && !defined (hp9000s300)) || defined (_SEQUENT_) || defined (SVR4) || defined (ISC) || defined (sgi) || (defined (ardent) && defined (titan)) || (defined (_AIX) && !defined(HAVE_LIBPERFSTAT)))
351# define LDAV_SYMBOL "avenrun"
352# endif
353
354# include <unistd.h>
355
356/* LOAD_AVE_TYPE should only get defined if we're going to use the
357 nlist method. */
358# if !defined (LOAD_AVE_TYPE) && (defined (BSD) || defined (LDAV_CVT) || defined (KERNEL_FILE) || defined (LDAV_SYMBOL))
359# define LOAD_AVE_TYPE double
360# endif
361
362# ifdef LOAD_AVE_TYPE
363
364# ifndef __VMS
365# ifndef __linux__
366# ifndef NLIST_STRUCT
367# include <a.out.h>
368# else /* NLIST_STRUCT */
369# include <nlist.h>
370# endif /* NLIST_STRUCT */
371
372# ifdef SUNOS_5
373# include <kvm.h>
374# include <kstat.h>
375# endif
376
377# if defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC)
378# include <sys/pstat.h>
379# endif
380
381# ifndef KERNEL_FILE
382# define KERNEL_FILE "/vmunix"
383# endif /* KERNEL_FILE */
384
385# ifndef LDAV_SYMBOL
386# define LDAV_SYMBOL "_avenrun"
387# endif /* LDAV_SYMBOL */
388# endif /* __linux__ */
389
390# else /* __VMS */
391
392# ifndef eunice
393# include <iodef.h>
394# include <descrip.h>
395# else /* eunice */
396# include <vms/iodef.h>
397# endif /* eunice */
398# endif /* __VMS */
399
400# ifndef LDAV_CVT
401# define LDAV_CVT(n) ((double) (n))
402# endif /* !LDAV_CVT */
403
404# endif /* LOAD_AVE_TYPE */
405
406# if defined HAVE_LIBPERFSTAT
407# include <sys/protosw.h>
408# include <libperfstat.h>
409# include <sys/proc.h>
410# ifndef SBITS
411# define SBITS 16
412# endif
413# endif
414
415# if defined (__GNU__) && !defined (NeXT)
416/* Note that NeXT Openstep defines __GNU__ even though it should not. */
417/* GNU system acts much like NeXT, for load average purposes,
418 but not exactly. */
419# define NeXT
420# define host_self mach_host_self
421# endif
422
423# ifdef NeXT
424# ifdef HAVE_MACH_MACH_H
425# include <mach/mach.h>
426# else
427# include <mach.h>
428# endif
429# endif /* NeXT */
430
431# ifdef sgi
432# include <sys/sysmp.h>
433# endif /* sgi */
434
435# ifdef UMAX
436# include <signal.h>
437# include <sys/time.h>
438# include <sys/wait.h>
439# include <sys/syscall.h>
440
441# ifdef UMAX_43
442# include <machine/cpu.h>
443# include <inq_stats/statistics.h>
444# include <inq_stats/sysstats.h>
445# include <inq_stats/cpustats.h>
446# include <inq_stats/procstats.h>
447# else /* Not UMAX_43. */
448# include <sys/sysdefs.h>
449# include <sys/statistics.h>
450# include <sys/sysstats.h>
451# include <sys/cpudefs.h>
452# include <sys/cpustats.h>
453# include <sys/procstats.h>
454# endif /* Not UMAX_43. */
455# endif /* UMAX */
456
457# ifdef DGUX
458# include <sys/dg_sys_info.h>
459# endif
460
461# if (defined __linux__ || defined __CYGWIN__ || defined SUNOS_5 \
462 || (defined LOAD_AVE_TYPE && ! defined __VMS))
463# include <fcntl.h>
464# endif
465
466/* Avoid static vars inside a function since in HPUX they dump as pure. */
467
468# ifdef NeXT
469static processor_set_t default_set;
470static bool getloadavg_initialized;
471# endif /* NeXT */
472
473# ifdef UMAX
474static unsigned int cpus = 0;
475static unsigned int samples;
476# endif /* UMAX */
477
478# ifdef DGUX
479static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */
480# endif /* DGUX */
481
482# if !defined (HAVE_LIBKSTAT) && defined (LOAD_AVE_TYPE)
483/* File descriptor open to /dev/kmem or VMS load ave driver. */
484static int channel;
485/* True if channel is valid. */
486static bool getloadavg_initialized;
487/* Offset in kmem to seek to read load average, or 0 means invalid. */
488static long offset;
489
490# if ! defined __VMS && ! defined sgi && ! defined __linux__
491static struct nlist name_list[2];
492# endif
493
494# ifdef SUNOS_5
495static kvm_t *kd;
496# endif /* SUNOS_5 */
497
498# endif /* LOAD_AVE_TYPE && !HAVE_LIBKSTAT */
499
500/* Put the 1 minute, 5 minute and 15 minute load averages
501 into the first NELEM elements of LOADAVG.
502 Return the number written (never more than 3, but may be less than NELEM),
503 or -1 if an error occurred. */
504
505int
506getloadavg (double loadavg[], int nelem)
507{
508 int elem = 0; /* Return value. */
509
510# ifdef NO_GET_LOAD_AVG
511# define LDAV_DONE
512 /* Set errno to zero to indicate that there was no particular error;
513 this function just can't work at all on this system. */
514 errno = 0;
515 elem = -1;
516# endif
517
518# if !defined (LDAV_DONE) && defined (HAVE_LIBKSTAT)
519/* Use libkstat because we don't have to be root. */
520# define LDAV_DONE
521 kstat_ctl_t *kc;
522 kstat_t *ksp;
523 kstat_named_t *kn;
524
525 kc = kstat_open ();
526 if (kc == 0)
527 return -1;
528 ksp = kstat_lookup (kc, "unix", 0, "system_misc");
529 if (ksp == 0)
530 return -1;
531 if (kstat_read (kc, ksp, 0) == -1)
532 return -1;
533
534
535 kn = kstat_data_lookup (ksp, "avenrun_1min");
536 if (kn == 0)
537 {
538 /* Return -1 if no load average information is available. */
539 nelem = 0;
540 elem = -1;
541 }
542
543 if (nelem >= 1)
544 loadavg[elem++] = (double) kn->value.ul / FSCALE;
545
546 if (nelem >= 2)
547 {
548 kn = kstat_data_lookup (ksp, "avenrun_5min");
549 if (kn != 0)
550 {
551 loadavg[elem++] = (double) kn->value.ul / FSCALE;
552
553 if (nelem >= 3)
554 {
555 kn = kstat_data_lookup (ksp, "avenrun_15min");
556 if (kn != 0)
557 loadavg[elem++] = (double) kn->value.ul / FSCALE;
558 }
559 }
560 }
561
562 kstat_close (kc);
563# endif /* HAVE_LIBKSTAT */
564
565# if !defined (LDAV_DONE) && defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC)
566/* Use pstat_getdynamic() because we don't have to be root. */
567# define LDAV_DONE
568# undef LOAD_AVE_TYPE
569
570 struct pst_dynamic dyn_info;
571 if (pstat_getdynamic (&dyn_info, sizeof (dyn_info), 0, 0) < 0)
572 return -1;
573 if (nelem > 0)
574 loadavg[elem++] = dyn_info.psd_avg_1_min;
575 if (nelem > 1)
576 loadavg[elem++] = dyn_info.psd_avg_5_min;
577 if (nelem > 2)
578 loadavg[elem++] = dyn_info.psd_avg_15_min;
579
580# endif /* hpux && HAVE_PSTAT_GETDYNAMIC */
581
582# if ! defined LDAV_DONE && defined HAVE_LIBPERFSTAT
583# define LDAV_DONE
584# undef LOAD_AVE_TYPE
585/* Use perfstat_cpu_total because we don't have to be root. */
586 {
587 perfstat_cpu_total_t cpu_stats;
588 int result = perfstat_cpu_total (NULL, &cpu_stats, sizeof cpu_stats, 1);
589 if (result == -1)
590 return result;
591 loadavg[0] = cpu_stats.loadavg[0] / (double)(1 << SBITS);
592 loadavg[1] = cpu_stats.loadavg[1] / (double)(1 << SBITS);
593 loadavg[2] = cpu_stats.loadavg[2] / (double)(1 << SBITS);
594 elem = 3;
595 }
596# endif
597
598# if !defined (LDAV_DONE) && (defined (__linux__) || defined (__CYGWIN__))
599# define LDAV_DONE
600# undef LOAD_AVE_TYPE
601
602# ifndef LINUX_LDAV_FILE
603# define LINUX_LDAV_FILE "/proc/loadavg"
604# endif
605
606 char ldavgbuf[3 * (INT_STRLEN_BOUND (int) + sizeof ".00 ")];
607 char const *ptr = ldavgbuf;
608 int fd, count;
609
610 fd = open (LINUX_LDAV_FILE, O_RDONLY);
611 if (fd == -1)
612 return -1;
613 count = read (fd, ldavgbuf, sizeof ldavgbuf - 1);
614 (void) close (fd);
615 if (count <= 0)
616 return -1;
617 ldavgbuf[count] = '\0';
618
619 for (elem = 0; elem < nelem; elem++)
620 {
621 double numerator = 0;
622 double denominator = 1;
623 bool have_digit = false;
624
625 while (*ptr == ' ')
626 ptr++;
627
628 /* Finish if this number is missing, and report an error if all
629 were missing. */
630 if (! ('0' <= *ptr && *ptr <= '9'))
631 {
632 if (elem == 0)
633 return -1;
634 break;
635 }
636
637 while ('0' <= *ptr && *ptr <= '9')
638 numerator = 10 * numerator + (*ptr++ - '0');
639
640 if (*ptr == '.')
641 for (ptr++; '0' <= *ptr && *ptr <= '9'; ptr++)
642 numerator = 10 * numerator + (*ptr - '0'), denominator *= 10;
643
644 loadavg[elem++] = numerator / denominator;
645 }
646
647 return elem;
648
649# endif /* __linux__ || __CYGWIN__ */
650
651# if !defined (LDAV_DONE) && defined (__NetBSD__)
652# define LDAV_DONE
653# undef LOAD_AVE_TYPE
654
655# ifndef NETBSD_LDAV_FILE
656# define NETBSD_LDAV_FILE "/kern/loadavg"
657# endif
658
659 unsigned long int load_ave[3], scale;
660 int count;
661 FILE *fp;
662
663 fp = fopen (NETBSD_LDAV_FILE, "r");
664 if (fp == NULL)
665 return -1;
666 count = fscanf (fp, "%lu %lu %lu %lu\n",
667 &load_ave[0], &load_ave[1], &load_ave[2],
668 &scale);
669 (void) fclose (fp);
670 if (count != 4)
671 return -1;
672
673 for (elem = 0; elem < nelem; elem++)
674 loadavg[elem] = (double) load_ave[elem] / (double) scale;
675
676 return elem;
677
678# endif /* __NetBSD__ */
679
680# if !defined (LDAV_DONE) && defined (NeXT)
681# define LDAV_DONE
682 /* The NeXT code was adapted from iscreen 3.2. */
683
684 host_t host;
685 struct processor_set_basic_info info;
686 unsigned int info_count;
687
688 /* We only know how to get the 1-minute average for this system,
689 so even if the caller asks for more than 1, we only return 1. */
690
691 if (!getloadavg_initialized)
692 {
693 if (processor_set_default (host_self (), &default_set) == KERN_SUCCESS)
694 getloadavg_initialized = true;
695 }
696
697 if (getloadavg_initialized)
698 {
699 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
700 if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host,
701 (processor_set_info_t) &info, &info_count)
702 != KERN_SUCCESS)
703 getloadavg_initialized = false;
704 else
705 {
706 if (nelem > 0)
707 loadavg[elem++] = (double) info.load_average / LOAD_SCALE;
708 }
709 }
710
711 if (!getloadavg_initialized)
712 return -1;
713# endif /* NeXT */
714
715# if !defined (LDAV_DONE) && defined (UMAX)
716# define LDAV_DONE
717/* UMAX 4.2, which runs on the Encore Multimax multiprocessor, does not
718 have a /dev/kmem. Information about the workings of the running kernel
719 can be gathered with inq_stats system calls.
720 We only know how to get the 1-minute average for this system. */
721
722 struct proc_summary proc_sum_data;
723 struct stat_descr proc_info;
724 double load;
725 register unsigned int i, j;
726
727 if (cpus == 0)
728 {
729 register unsigned int c, i;
730 struct cpu_config conf;
731 struct stat_descr desc;
732
733 desc.sd_next = 0;
734 desc.sd_subsys = SUBSYS_CPU;
735 desc.sd_type = CPUTYPE_CONFIG;
736 desc.sd_addr = (char *) &conf;
737 desc.sd_size = sizeof conf;
738
739 if (inq_stats (1, &desc))
740 return -1;
741
742 c = 0;
743 for (i = 0; i < conf.config_maxclass; ++i)
744 {
745 struct class_stats stats;
746 memset (&stats, 0, sizeof stats);
747
748 desc.sd_type = CPUTYPE_CLASS;
749 desc.sd_objid = i;
750 desc.sd_addr = (char *) &stats;
751 desc.sd_size = sizeof stats;
752
753 if (inq_stats (1, &desc))
754 return -1;
755
756 c += stats.class_numcpus;
757 }
758 cpus = c;
759 samples = cpus < 2 ? 3 : (2 * cpus / 3);
760 }
761
762 proc_info.sd_next = 0;
763 proc_info.sd_subsys = SUBSYS_PROC;
764 proc_info.sd_type = PROCTYPE_SUMMARY;
765 proc_info.sd_addr = (char *) &proc_sum_data;
766 proc_info.sd_size = sizeof (struct proc_summary);
767 proc_info.sd_sizeused = 0;
768
769 if (inq_stats (1, &proc_info) != 0)
770 return -1;
771
772 load = proc_sum_data.ps_nrunnable;
773 j = 0;
774 for (i = samples - 1; i > 0; --i)
775 {
776 load += proc_sum_data.ps_nrun[j];
777 if (j++ == PS_NRUNSIZE)
778 j = 0;
779 }
780
781 if (nelem > 0)
782 loadavg[elem++] = load / samples / cpus;
783# endif /* UMAX */
784
785# if !defined (LDAV_DONE) && defined (DGUX)
786# define LDAV_DONE
787 /* This call can return -1 for an error, but with good args
788 it's not supposed to fail. The first argument is for no
789 apparent reason of type `long int *'. */
790 dg_sys_info ((long int *) &load_info,
791 DG_SYS_INFO_LOAD_INFO_TYPE,
792 DG_SYS_INFO_LOAD_VERSION_0);
793
794 if (nelem > 0)
795 loadavg[elem++] = load_info.one_minute;
796 if (nelem > 1)
797 loadavg[elem++] = load_info.five_minute;
798 if (nelem > 2)
799 loadavg[elem++] = load_info.fifteen_minute;
800# endif /* DGUX */
801
802# if !defined (LDAV_DONE) && defined (apollo)
803# define LDAV_DONE
804/* Apollo code from lisch@mentorg.com (Ray Lischner).
805
806 This system call is not documented. The load average is obtained as
807 three long integers, for the load average over the past minute,
808 five minutes, and fifteen minutes. Each value is a scaled integer,
809 with 16 bits of integer part and 16 bits of fraction part.
810
811 I'm not sure which operating system first supported this system call,
812 but I know that SR10.2 supports it. */
813
814 extern void proc1_$get_loadav ();
815 unsigned long load_ave[3];
816
817 proc1_$get_loadav (load_ave);
818
819 if (nelem > 0)
820 loadavg[elem++] = load_ave[0] / 65536.0;
821 if (nelem > 1)
822 loadavg[elem++] = load_ave[1] / 65536.0;
823 if (nelem > 2)
824 loadavg[elem++] = load_ave[2] / 65536.0;
825# endif /* apollo */
826
827# if !defined (LDAV_DONE) && defined (OSF_MIPS)
828# define LDAV_DONE
829
830 struct tbl_loadavg load_ave;
831 table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave));
832 loadavg[elem++]
833 = (load_ave.tl_lscale == 0
834 ? load_ave.tl_avenrun.d[0]
835 : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale));
836# endif /* OSF_MIPS */
837
838# if !defined (LDAV_DONE) && (defined (__MSDOS__) || defined (WINDOWS32))
839# define LDAV_DONE
840
841 /* A faithful emulation is going to have to be saved for a rainy day. */
842 for ( ; elem < nelem; elem++)
843 {
844 loadavg[elem] = 0.0;
845 }
846# endif /* __MSDOS__ || WINDOWS32 */
847
848# if !defined (LDAV_DONE) && defined (OSF_ALPHA)
849# define LDAV_DONE
850
851 struct tbl_loadavg load_ave;
852 table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave));
853 for (elem = 0; elem < nelem; elem++)
854 loadavg[elem]
855 = (load_ave.tl_lscale == 0
856 ? load_ave.tl_avenrun.d[elem]
857 : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale));
858# endif /* OSF_ALPHA */
859
860# if ! defined LDAV_DONE && defined __VMS
861 /* VMS specific code -- read from the Load Ave driver. */
862
863 LOAD_AVE_TYPE load_ave[3];
864 static bool getloadavg_initialized;
865# ifdef eunice
866 struct
867 {
868 int dsc$w_length;
869 char *dsc$a_pointer;
870 } descriptor;
871# endif
872
873 /* Ensure that there is a channel open to the load ave device. */
874 if (!getloadavg_initialized)
875 {
876 /* Attempt to open the channel. */
877# ifdef eunice
878 descriptor.dsc$w_length = 18;
879 descriptor.dsc$a_pointer = "$$VMS_LOAD_AVERAGE";
880# else
881 $DESCRIPTOR (descriptor, "LAV0:");
882# endif
883 if (sys$assign (&descriptor, &channel, 0, 0) & 1)
884 getloadavg_initialized = true;
885 }
886
887 /* Read the load average vector. */
888 if (getloadavg_initialized
889 && !(sys$qiow (0, channel, IO$_READVBLK, 0, 0, 0,
890 load_ave, 12, 0, 0, 0, 0) & 1))
891 {
892 sys$dassgn (channel);
893 getloadavg_initialized = false;
894 }
895
896 if (!getloadavg_initialized)
897 return -1;
898# endif /* ! defined LDAV_DONE && defined __VMS */
899
900# if ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS
901
902 /* UNIX-specific code -- read the average from /dev/kmem. */
903
904# define LDAV_PRIVILEGED /* This code requires special installation. */
905
906 LOAD_AVE_TYPE load_ave[3];
907
908 /* Get the address of LDAV_SYMBOL. */
909 if (offset == 0)
910 {
911# ifndef sgi
912# if ! defined NLIST_STRUCT || ! defined N_NAME_POINTER
913 strcpy (name_list[0].n_name, LDAV_SYMBOL);
914 strcpy (name_list[1].n_name, "");
915# else /* NLIST_STRUCT */
916# ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME
917 name_list[0].n_un.n_name = LDAV_SYMBOL;
918 name_list[1].n_un.n_name = 0;
919# else /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */
920 name_list[0].n_name = LDAV_SYMBOL;
921 name_list[1].n_name = 0;
922# endif /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */
923# endif /* NLIST_STRUCT */
924
925# ifndef SUNOS_5
926 if (
927# if !(defined (_AIX) && !defined (ps2))
928 nlist (KERNEL_FILE, name_list)
929# else /* _AIX */
930 knlist (name_list, 1, sizeof (name_list[0]))
931# endif
932 >= 0)
933 /* Omit "&& name_list[0].n_type != 0 " -- it breaks on Sun386i. */
934 {
935# ifdef FIXUP_KERNEL_SYMBOL_ADDR
936 FIXUP_KERNEL_SYMBOL_ADDR (name_list);
937# endif
938 offset = name_list[0].n_value;
939 }
940# endif /* !SUNOS_5 */
941# else /* sgi */
942 int ldav_off;
943
944 ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN);
945 if (ldav_off != -1)
946 offset = (long int) ldav_off & 0x7fffffff;
947# endif /* sgi */
948 }
949
950 /* Make sure we have /dev/kmem open. */
951 if (!getloadavg_initialized)
952 {
953# ifndef SUNOS_5
954 /* Set the channel to close on exec, so it does not
955 litter any child's descriptor table. */
956# ifndef O_CLOEXEC
957# define O_CLOEXEC 0
958# endif
959 int fd = open ("/dev/kmem", O_RDONLY | O_CLOEXEC);
960 if (0 <= fd)
961 {
962# if F_DUPFD_CLOEXEC
963 if (fd <= STDERR_FILENO)
964 {
965 int fd1 = fcntl (fd, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
966 close (fd);
967 fd = fd1;
968 }
969# endif
970 if (0 <= fd)
971 {
972 channel = fd;
973 getloadavg_initialized = true;
974 }
975 }
976# else /* SUNOS_5 */
977 /* We pass 0 for the kernel, corefile, and swapfile names
978 to use the currently running kernel. */
979 kd = kvm_open (0, 0, 0, O_RDONLY, 0);
980 if (kd != 0)
981 {
982 /* nlist the currently running kernel. */
983 kvm_nlist (kd, name_list);
984 offset = name_list[0].n_value;
985 getloadavg_initialized = true;
986 }
987# endif /* SUNOS_5 */
988 }
989
990 /* If we can, get the load average values. */
991 if (offset && getloadavg_initialized)
992 {
993 /* Try to read the load. */
994# ifndef SUNOS_5
995 if (lseek (channel, offset, 0) == -1L
996 || read (channel, (char *) load_ave, sizeof (load_ave))
997 != sizeof (load_ave))
998 {
999 close (channel);
1000 getloadavg_initialized = false;
1001 }
1002# else /* SUNOS_5 */
1003 if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave))
1004 != sizeof (load_ave))
1005 {
1006 kvm_close (kd);
1007 getloadavg_initialized = false;
1008 }
1009# endif /* SUNOS_5 */
1010 }
1011
1012 if (offset == 0 || !getloadavg_initialized)
1013 return -1;
1014# endif /* ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS */
1015
1016# if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) /* Including VMS. */
1017 if (nelem > 0)
1018 loadavg[elem++] = LDAV_CVT (load_ave[0]);
1019 if (nelem > 1)
1020 loadavg[elem++] = LDAV_CVT (load_ave[1]);
1021 if (nelem > 2)
1022 loadavg[elem++] = LDAV_CVT (load_ave[2]);
1023
1024# define LDAV_DONE
1025# endif /* !LDAV_DONE && LOAD_AVE_TYPE */
1026
1027# if !defined LDAV_DONE
1028 /* Set errno to zero to indicate that there was no particular error;
1029 this function just can't work at all on this system. */
1030 errno = 0;
1031 elem = -1;
1032# endif
1033 return elem;
1034}
1035
1036#endif /* ! HAVE_GETLOADAVG */
1037
1038#ifdef TEST
1039int
1040main (int argc, char **argv)
1041{
1042 int naptime = 0;
1043
1044 if (argc > 1)
1045 naptime = atoi (argv[1]);
1046
1047 while (1)
1048 {
1049 double avg[3];
1050 int loads;
1051
1052 errno = 0; /* Don't be misled if it doesn't set errno. */
1053 loads = getloadavg (avg, 3);
1054 if (loads == -1)
1055 {
1056 perror ("Error getting load average");
1057 return EXIT_FAILURE;
1058 }
1059 if (loads > 0)
1060 printf ("1-minute: %f ", avg[0]);
1061 if (loads > 1)
1062 printf ("5-minute: %f ", avg[1]);
1063 if (loads > 2)
1064 printf ("15-minute: %f ", avg[2]);
1065 if (loads > 0)
1066 putchar ('\n');
1067
1068 if (naptime == 0)
1069 break;
1070 sleep (naptime);
1071 }
1072
1073 return EXIT_SUCCESS;
1074}
1075#endif /* TEST */
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index af628c8d300..ffd175d58c8 100644
--- a/lib/gnulib.mk
+++ b/lib/gnulib.mk
@@ -9,7 +9,7 @@
9# the same distribution terms as the rest of that program. 9# the same distribution terms as the rest of that program.
10# 10#
11# Generated by gnulib-tool. 11# Generated by gnulib-tool.
12# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files dtoastr getopt-gnu ignore-value mktime strftime 12# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files dtoastr getloadavg getopt-gnu ignore-value mktime strftime
13 13
14 14
15MOSTLYCLEANFILES += core *.stackdump 15MOSTLYCLEANFILES += core *.stackdump
@@ -79,6 +79,15 @@ EXTRA_libgnu_a_SOURCES += ftoastr.c
79 79
80## end gnulib module dtoastr 80## end gnulib module dtoastr
81 81
82## begin gnulib module getloadavg
83
84
85EXTRA_DIST += getloadavg.c
86
87EXTRA_libgnu_a_SOURCES += getloadavg.c
88
89## end gnulib module getloadavg
90
82## begin gnulib module getopt-posix 91## begin gnulib module getopt-posix
83 92
84BUILT_SOURCES += $(GETOPT_H) 93BUILT_SOURCES += $(GETOPT_H)
@@ -175,6 +184,91 @@ EXTRA_DIST += stddef.in.h
175 184
176## end gnulib module stddef 185## end gnulib module stddef
177 186
187## begin gnulib module stdlib
188
189BUILT_SOURCES += stdlib.h
190
191# We need the following in order to create <stdlib.h> when the system
192# doesn't have one that works with the given compiler.
193stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
194 $(AM_V_GEN)rm -f $@-t $@ && \
195 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
196 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
197 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
198 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
199 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
200 -e 's|@''GNULIB__EXIT''@|$(GNULIB__EXIT)|g' \
201 -e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \
202 -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \
203 -e 's|@''GNULIB_CANONICALIZE_FILE_NAME''@|$(GNULIB_CANONICALIZE_FILE_NAME)|g' \
204 -e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \
205 -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
206 -e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \
207 -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
208 -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
209 -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \
210 -e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \
211 -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
212 -e 's|@''GNULIB_MKSTEMPS''@|$(GNULIB_MKSTEMPS)|g' \
213 -e 's|@''GNULIB_PTSNAME''@|$(GNULIB_PTSNAME)|g' \
214 -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
215 -e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|g' \
216 -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \
217 -e 's|@''GNULIB_REALPATH''@|$(GNULIB_REALPATH)|g' \
218 -e 's|@''GNULIB_RPMATCH''@|$(GNULIB_RPMATCH)|g' \
219 -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \
220 -e 's|@''GNULIB_STRTOD''@|$(GNULIB_STRTOD)|g' \
221 -e 's|@''GNULIB_STRTOLL''@|$(GNULIB_STRTOLL)|g' \
222 -e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \
223 -e 's|@''GNULIB_SYSTEM_POSIX''@|$(GNULIB_SYSTEM_POSIX)|g' \
224 -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \
225 -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
226 -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
227 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
228 -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \
229 -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
230 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
231 -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \
232 -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
233 -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \
234 -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \
235 -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \
236 -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \
237 -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \
238 -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \
239 -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
240 -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \
241 -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
242 -e 's|@''HAVE_DECL_SETENV''@|$(HAVE_DECL_SETENV)|g' \
243 -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \
244 -e 's|@''HAVE_STRTOLL''@|$(HAVE_STRTOLL)|g' \
245 -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \
246 -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \
247 -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
248 -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \
249 -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \
250 -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
251 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
252 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
253 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
254 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
255 -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
256 -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \
257 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
258 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
259 -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \
260 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
261 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
262 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
263 < $(srcdir)/stdlib.in.h; \
264 } > $@-t && \
265 mv $@-t $@
266MOSTLYCLEANFILES += stdlib.h stdlib.h-t
267
268EXTRA_DIST += stdlib.in.h
269
270## end gnulib module stdlib
271
178## begin gnulib module strftime 272## begin gnulib module strftime
179 273
180 274
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
new file mode 100644
index 00000000000..b3bb9d4e5de
--- /dev/null
+++ b/lib/stdlib.in.h
@@ -0,0 +1,725 @@
1/* A GNU-like <stdlib.h>.
2
3 Copyright (C) 1995, 2001-2004, 2006-2011 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#if __GNUC__ >= 3
19@PRAGMA_SYSTEM_HEADER@
20#endif
21@PRAGMA_COLUMNS@
22
23#if defined __need_malloc_and_calloc
24/* Special invocation convention inside glibc header files. */
25
26#@INCLUDE_NEXT@ @NEXT_STDLIB_H@
27
28#else
29/* Normal invocation convention. */
30
31#ifndef _GL_STDLIB_H
32
33/* The include_next requires a split double-inclusion guard. */
34#@INCLUDE_NEXT@ @NEXT_STDLIB_H@
35
36#ifndef _GL_STDLIB_H
37#define _GL_STDLIB_H
38
39/* NetBSD 5.0 mis-defines NULL. */
40#include <stddef.h>
41
42/* MirBSD 10 defines WEXITSTATUS in <sys/wait.h>, not in <stdlib.h>. */
43#if @GNULIB_SYSTEM_POSIX@ && !defined WEXITSTATUS
44# include <sys/wait.h>
45#endif
46
47/* Solaris declares getloadavg() in <sys/loadavg.h>. */
48#if (@GNULIB_GETLOADAVG@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_LOADAVG_H@
49# include <sys/loadavg.h>
50#endif
51
52/* OSF/1 5.1 declares 'struct random_data' in <random.h>, which is included
53 from <stdlib.h> if _REENTRANT is defined. Include it always. */
54#if @HAVE_RANDOM_H@
55# include <random.h>
56#endif
57
58#if !@HAVE_STRUCT_RANDOM_DATA@ || (@GNULIB_RANDOM_R@ && !@HAVE_RANDOM_R@)
59# include <stdint.h>
60#endif
61
62#if !@HAVE_STRUCT_RANDOM_DATA@
63/* Define 'struct random_data'.
64 But allow multiple gnulib generated <stdlib.h> replacements to coexist. */
65# if !GNULIB_defined_struct_random_data
66struct random_data
67{
68 int32_t *fptr; /* Front pointer. */
69 int32_t *rptr; /* Rear pointer. */
70 int32_t *state; /* Array of state values. */
71 int rand_type; /* Type of random number generator. */
72 int rand_deg; /* Degree of random number generator. */
73 int rand_sep; /* Distance between front and rear. */
74 int32_t *end_ptr; /* Pointer behind state table. */
75};
76# define GNULIB_defined_struct_random_data 1
77# endif
78#endif
79
80#if (@GNULIB_MKSTEMP@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
81/* On MacOS X 10.3, only <unistd.h> declares mkstemp. */
82/* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */
83/* But avoid namespace pollution on glibc systems and native Windows. */
84# include <unistd.h>
85#endif
86
87#ifndef __attribute__
88# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
89# define __attribute__(Spec) /* empty */
90# endif
91#endif
92
93/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
94
95/* The definition of _GL_ARG_NONNULL is copied here. */
96
97/* The definition of _GL_WARN_ON_USE is copied here. */
98
99
100/* Some systems do not define EXIT_*, despite otherwise supporting C89. */
101#ifndef EXIT_SUCCESS
102# define EXIT_SUCCESS 0
103#endif
104/* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
105 with proper operation of xargs. */
106#ifndef EXIT_FAILURE
107# define EXIT_FAILURE 1
108#elif EXIT_FAILURE != 1
109# undef EXIT_FAILURE
110# define EXIT_FAILURE 1
111#endif
112
113
114#if @GNULIB__EXIT@
115/* Terminate the current process with the given return code, without running
116 the 'atexit' handlers. */
117# if !@HAVE__EXIT@
118_GL_FUNCDECL_SYS (_Exit, void, (int status) __attribute__ ((__noreturn__)));
119# endif
120_GL_CXXALIAS_SYS (_Exit, void, (int status));
121_GL_CXXALIASWARN (_Exit);
122#elif defined GNULIB_POSIXCHECK
123# undef _Exit
124# if HAVE_RAW_DECL__EXIT
125_GL_WARN_ON_USE (_Exit, "_Exit is unportable - "
126 "use gnulib module _Exit for portability");
127# endif
128#endif
129
130
131#if @GNULIB_ATOLL@
132/* Parse a signed decimal integer.
133 Returns the value of the integer. Errors are not detected. */
134# if !@HAVE_ATOLL@
135_GL_FUNCDECL_SYS (atoll, long long, (const char *string) _GL_ARG_NONNULL ((1)));
136# endif
137_GL_CXXALIAS_SYS (atoll, long long, (const char *string));
138_GL_CXXALIASWARN (atoll);
139#elif defined GNULIB_POSIXCHECK
140# undef atoll
141# if HAVE_RAW_DECL_ATOLL
142_GL_WARN_ON_USE (atoll, "atoll is unportable - "
143 "use gnulib module atoll for portability");
144# endif
145#endif
146
147#if @GNULIB_CALLOC_POSIX@
148# if @REPLACE_CALLOC@
149# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
150# undef calloc
151# define calloc rpl_calloc
152# endif
153_GL_FUNCDECL_RPL (calloc, void *, (size_t nmemb, size_t size));
154_GL_CXXALIAS_RPL (calloc, void *, (size_t nmemb, size_t size));
155# else
156_GL_CXXALIAS_SYS (calloc, void *, (size_t nmemb, size_t size));
157# endif
158_GL_CXXALIASWARN (calloc);
159#elif defined GNULIB_POSIXCHECK
160# undef calloc
161/* Assume calloc is always declared. */
162_GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - "
163 "use gnulib module calloc-posix for portability");
164#endif
165
166#if @GNULIB_CANONICALIZE_FILE_NAME@
167# if @REPLACE_CANONICALIZE_FILE_NAME@
168# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
169# define canonicalize_file_name rpl_canonicalize_file_name
170# endif
171_GL_FUNCDECL_RPL (canonicalize_file_name, char *, (const char *name)
172 _GL_ARG_NONNULL ((1)));
173_GL_CXXALIAS_RPL (canonicalize_file_name, char *, (const char *name));
174# else
175# if !@HAVE_CANONICALIZE_FILE_NAME@
176_GL_FUNCDECL_SYS (canonicalize_file_name, char *, (const char *name)
177 _GL_ARG_NONNULL ((1)));
178# endif
179_GL_CXXALIAS_SYS (canonicalize_file_name, char *, (const char *name));
180# endif
181_GL_CXXALIASWARN (canonicalize_file_name);
182#elif defined GNULIB_POSIXCHECK
183# undef canonicalize_file_name
184# if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME
185_GL_WARN_ON_USE (canonicalize_file_name,
186 "canonicalize_file_name is unportable - "
187 "use gnulib module canonicalize-lgpl for portability");
188# endif
189#endif
190
191#if @GNULIB_GETLOADAVG@
192/* Store max(NELEM,3) load average numbers in LOADAVG[].
193 The three numbers are the load average of the last 1 minute, the last 5
194 minutes, and the last 15 minutes, respectively.
195 LOADAVG is an array of NELEM numbers. */
196# if !@HAVE_DECL_GETLOADAVG@
197_GL_FUNCDECL_SYS (getloadavg, int, (double loadavg[], int nelem)
198 _GL_ARG_NONNULL ((1)));
199# endif
200_GL_CXXALIAS_SYS (getloadavg, int, (double loadavg[], int nelem));
201_GL_CXXALIASWARN (getloadavg);
202#elif defined GNULIB_POSIXCHECK
203# undef getloadavg
204# if HAVE_RAW_DECL_GETLOADAVG
205_GL_WARN_ON_USE (getloadavg, "getloadavg is not portable - "
206 "use gnulib module getloadavg for portability");
207# endif
208#endif
209
210#if @GNULIB_GETSUBOPT@
211/* Assuming *OPTIONP is a comma separated list of elements of the form
212 "token" or "token=value", getsubopt parses the first of these elements.
213 If the first element refers to a "token" that is member of the given
214 NULL-terminated array of tokens:
215 - It replaces the comma with a NUL byte, updates *OPTIONP to point past
216 the first option and the comma, sets *VALUEP to the value of the
217 element (or NULL if it doesn't contain an "=" sign),
218 - It returns the index of the "token" in the given array of tokens.
219 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
220 For more details see the POSIX:2001 specification.
221 http://www.opengroup.org/susv3xsh/getsubopt.html */
222# if !@HAVE_GETSUBOPT@
223_GL_FUNCDECL_SYS (getsubopt, int,
224 (char **optionp, char *const *tokens, char **valuep)
225 _GL_ARG_NONNULL ((1, 2, 3)));
226# endif
227_GL_CXXALIAS_SYS (getsubopt, int,
228 (char **optionp, char *const *tokens, char **valuep));
229_GL_CXXALIASWARN (getsubopt);
230#elif defined GNULIB_POSIXCHECK
231# undef getsubopt
232# if HAVE_RAW_DECL_GETSUBOPT
233_GL_WARN_ON_USE (getsubopt, "getsubopt is unportable - "
234 "use gnulib module getsubopt for portability");
235# endif
236#endif
237
238#if @GNULIB_GRANTPT@
239/* Change the ownership and access permission of the slave side of the
240 pseudo-terminal whose master side is specified by FD. */
241# if !@HAVE_GRANTPT@
242_GL_FUNCDECL_SYS (grantpt, int, (int fd));
243# endif
244_GL_CXXALIAS_SYS (grantpt, int, (int fd));
245_GL_CXXALIASWARN (grantpt);
246#elif defined GNULIB_POSIXCHECK
247# undef grantpt
248# if HAVE_RAW_DECL_GRANTPT
249_GL_WARN_ON_USE (ptsname, "grantpt is not portable - "
250 "use gnulib module grantpt for portability");
251# endif
252#endif
253
254#if @GNULIB_MALLOC_POSIX@
255# if @REPLACE_MALLOC@
256# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
257# undef malloc
258# define malloc rpl_malloc
259# endif
260_GL_FUNCDECL_RPL (malloc, void *, (size_t size));
261_GL_CXXALIAS_RPL (malloc, void *, (size_t size));
262# else
263_GL_CXXALIAS_SYS (malloc, void *, (size_t size));
264# endif
265_GL_CXXALIASWARN (malloc);
266#elif defined GNULIB_POSIXCHECK
267# undef malloc
268/* Assume malloc is always declared. */
269_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
270 "use gnulib module malloc-posix for portability");
271#endif
272
273#if @GNULIB_MKDTEMP@
274/* Create a unique temporary directory from TEMPLATE.
275 The last six characters of TEMPLATE must be "XXXXXX";
276 they are replaced with a string that makes the directory name unique.
277 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
278 The directory is created mode 700. */
279# if !@HAVE_MKDTEMP@
280_GL_FUNCDECL_SYS (mkdtemp, char *, (char * /*template*/) _GL_ARG_NONNULL ((1)));
281# endif
282_GL_CXXALIAS_SYS (mkdtemp, char *, (char * /*template*/));
283_GL_CXXALIASWARN (mkdtemp);
284#elif defined GNULIB_POSIXCHECK
285# undef mkdtemp
286# if HAVE_RAW_DECL_MKDTEMP
287_GL_WARN_ON_USE (mkdtemp, "mkdtemp is unportable - "
288 "use gnulib module mkdtemp for portability");
289# endif
290#endif
291
292#if @GNULIB_MKOSTEMP@
293/* Create a unique temporary file from TEMPLATE.
294 The last six characters of TEMPLATE must be "XXXXXX";
295 they are replaced with a string that makes the file name unique.
296 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
297 and O_TEXT, O_BINARY (defined in "binary-io.h").
298 The file is then created, with the specified flags, ensuring it didn't exist
299 before.
300 The file is created read-write (mask at least 0600 & ~umask), but it may be
301 world-readable and world-writable (mask 0666 & ~umask), depending on the
302 implementation.
303 Returns the open file descriptor if successful, otherwise -1 and errno
304 set. */
305# if !@HAVE_MKOSTEMP@
306_GL_FUNCDECL_SYS (mkostemp, int, (char * /*template*/, int /*flags*/)
307 _GL_ARG_NONNULL ((1)));
308# endif
309_GL_CXXALIAS_SYS (mkostemp, int, (char * /*template*/, int /*flags*/));
310_GL_CXXALIASWARN (mkostemp);
311#elif defined GNULIB_POSIXCHECK
312# undef mkostemp
313# if HAVE_RAW_DECL_MKOSTEMP
314_GL_WARN_ON_USE (mkostemp, "mkostemp is unportable - "
315 "use gnulib module mkostemp for portability");
316# endif
317#endif
318
319#if @GNULIB_MKOSTEMPS@
320/* Create a unique temporary file from TEMPLATE.
321 The last six characters of TEMPLATE before a suffix of length
322 SUFFIXLEN must be "XXXXXX";
323 they are replaced with a string that makes the file name unique.
324 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
325 and O_TEXT, O_BINARY (defined in "binary-io.h").
326 The file is then created, with the specified flags, ensuring it didn't exist
327 before.
328 The file is created read-write (mask at least 0600 & ~umask), but it may be
329 world-readable and world-writable (mask 0666 & ~umask), depending on the
330 implementation.
331 Returns the open file descriptor if successful, otherwise -1 and errno
332 set. */
333# if !@HAVE_MKOSTEMPS@
334_GL_FUNCDECL_SYS (mkostemps, int,
335 (char * /*template*/, int /*suffixlen*/, int /*flags*/)
336 _GL_ARG_NONNULL ((1)));
337# endif
338_GL_CXXALIAS_SYS (mkostemps, int,
339 (char * /*template*/, int /*suffixlen*/, int /*flags*/));
340_GL_CXXALIASWARN (mkostemps);
341#elif defined GNULIB_POSIXCHECK
342# undef mkostemps
343# if HAVE_RAW_DECL_MKOSTEMPS
344_GL_WARN_ON_USE (mkostemps, "mkostemps is unportable - "
345 "use gnulib module mkostemps for portability");
346# endif
347#endif
348
349#if @GNULIB_MKSTEMP@
350/* Create a unique temporary file from TEMPLATE.
351 The last six characters of TEMPLATE must be "XXXXXX";
352 they are replaced with a string that makes the file name unique.
353 The file is then created, ensuring it didn't exist before.
354 The file is created read-write (mask at least 0600 & ~umask), but it may be
355 world-readable and world-writable (mask 0666 & ~umask), depending on the
356 implementation.
357 Returns the open file descriptor if successful, otherwise -1 and errno
358 set. */
359# if @REPLACE_MKSTEMP@
360# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
361# define mkstemp rpl_mkstemp
362# endif
363_GL_FUNCDECL_RPL (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1)));
364_GL_CXXALIAS_RPL (mkstemp, int, (char * /*template*/));
365# else
366# if ! @HAVE_MKSTEMP@
367_GL_FUNCDECL_SYS (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1)));
368# endif
369_GL_CXXALIAS_SYS (mkstemp, int, (char * /*template*/));
370# endif
371_GL_CXXALIASWARN (mkstemp);
372#elif defined GNULIB_POSIXCHECK
373# undef mkstemp
374# if HAVE_RAW_DECL_MKSTEMP
375_GL_WARN_ON_USE (mkstemp, "mkstemp is unportable - "
376 "use gnulib module mkstemp for portability");
377# endif
378#endif
379
380#if @GNULIB_MKSTEMPS@
381/* Create a unique temporary file from TEMPLATE.
382 The last six characters of TEMPLATE prior to a suffix of length
383 SUFFIXLEN must be "XXXXXX";
384 they are replaced with a string that makes the file name unique.
385 The file is then created, ensuring it didn't exist before.
386 The file is created read-write (mask at least 0600 & ~umask), but it may be
387 world-readable and world-writable (mask 0666 & ~umask), depending on the
388 implementation.
389 Returns the open file descriptor if successful, otherwise -1 and errno
390 set. */
391# if !@HAVE_MKSTEMPS@
392_GL_FUNCDECL_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/)
393 _GL_ARG_NONNULL ((1)));
394# endif
395_GL_CXXALIAS_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/));
396_GL_CXXALIASWARN (mkstemps);
397#elif defined GNULIB_POSIXCHECK
398# undef mkstemps
399# if HAVE_RAW_DECL_MKSTEMPS
400_GL_WARN_ON_USE (mkstemps, "mkstemps is unportable - "
401 "use gnulib module mkstemps for portability");
402# endif
403#endif
404
405#if @GNULIB_PTSNAME@
406/* Return the pathname of the pseudo-terminal slave associated with
407 the master FD is open on, or NULL on errors. */
408# if !@HAVE_PTSNAME@
409_GL_FUNCDECL_SYS (ptsname, char *, (int fd));
410# endif
411_GL_CXXALIAS_SYS (ptsname, char *, (int fd));
412_GL_CXXALIASWARN (ptsname);
413#elif defined GNULIB_POSIXCHECK
414# undef ptsname
415# if HAVE_RAW_DECL_PTSNAME
416_GL_WARN_ON_USE (ptsname, "ptsname is not portable - "
417 "use gnulib module ptsname for portability");
418# endif
419#endif
420
421#if @GNULIB_PUTENV@
422# if @REPLACE_PUTENV@
423# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
424# undef putenv
425# define putenv rpl_putenv
426# endif
427_GL_FUNCDECL_RPL (putenv, int, (char *string) _GL_ARG_NONNULL ((1)));
428_GL_CXXALIAS_RPL (putenv, int, (char *string));
429# else
430_GL_CXXALIAS_SYS (putenv, int, (char *string));
431# endif
432_GL_CXXALIASWARN (putenv);
433#endif
434
435
436#if @GNULIB_RANDOM_R@
437# if !@HAVE_RANDOM_R@
438# ifndef RAND_MAX
439# define RAND_MAX 2147483647
440# endif
441# endif
442#endif
443
444#if @GNULIB_RANDOM_R@
445# if !@HAVE_RANDOM_R@
446_GL_FUNCDECL_SYS (random_r, int, (struct random_data *buf, int32_t *result)
447 _GL_ARG_NONNULL ((1, 2)));
448# endif
449_GL_CXXALIAS_SYS (random_r, int, (struct random_data *buf, int32_t *result));
450_GL_CXXALIASWARN (random_r);
451#elif defined GNULIB_POSIXCHECK
452# undef random_r
453# if HAVE_RAW_DECL_RANDOM_R
454_GL_WARN_ON_USE (random_r, "random_r is unportable - "
455 "use gnulib module random_r for portability");
456# endif
457#endif
458
459#if @GNULIB_RANDOM_R@
460# if !@HAVE_RANDOM_R@
461_GL_FUNCDECL_SYS (srandom_r, int,
462 (unsigned int seed, struct random_data *rand_state)
463 _GL_ARG_NONNULL ((2)));
464# endif
465_GL_CXXALIAS_SYS (srandom_r, int,
466 (unsigned int seed, struct random_data *rand_state));
467_GL_CXXALIASWARN (srandom_r);
468#elif defined GNULIB_POSIXCHECK
469# undef srandom_r
470# if HAVE_RAW_DECL_SRANDOM_R
471_GL_WARN_ON_USE (srandom_r, "srandom_r is unportable - "
472 "use gnulib module random_r for portability");
473# endif
474#endif
475
476#if @GNULIB_RANDOM_R@
477# if !@HAVE_RANDOM_R@
478_GL_FUNCDECL_SYS (initstate_r, int,
479 (unsigned int seed, char *buf, size_t buf_size,
480 struct random_data *rand_state)
481 _GL_ARG_NONNULL ((2, 4)));
482# endif
483_GL_CXXALIAS_SYS (initstate_r, int,
484 (unsigned int seed, char *buf, size_t buf_size,
485 struct random_data *rand_state));
486_GL_CXXALIASWARN (initstate_r);
487#elif defined GNULIB_POSIXCHECK
488# undef initstate_r
489# if HAVE_RAW_DECL_INITSTATE_R
490_GL_WARN_ON_USE (initstate_r, "initstate_r is unportable - "
491 "use gnulib module random_r for portability");
492# endif
493#endif
494
495#if @GNULIB_RANDOM_R@
496# if !@HAVE_RANDOM_R@
497_GL_FUNCDECL_SYS (setstate_r, int,
498 (char *arg_state, struct random_data *rand_state)
499 _GL_ARG_NONNULL ((1, 2)));
500# endif
501_GL_CXXALIAS_SYS (setstate_r, int,
502 (char *arg_state, struct random_data *rand_state));
503_GL_CXXALIASWARN (setstate_r);
504#elif defined GNULIB_POSIXCHECK
505# undef setstate_r
506# if HAVE_RAW_DECL_SETSTATE_R
507_GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - "
508 "use gnulib module random_r for portability");
509# endif
510#endif
511
512
513#if @GNULIB_REALLOC_POSIX@
514# if @REPLACE_REALLOC@
515# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
516# undef realloc
517# define realloc rpl_realloc
518# endif
519_GL_FUNCDECL_RPL (realloc, void *, (void *ptr, size_t size));
520_GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size));
521# else
522_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size));
523# endif
524_GL_CXXALIASWARN (realloc);
525#elif defined GNULIB_POSIXCHECK
526# undef realloc
527/* Assume realloc is always declared. */
528_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - "
529 "use gnulib module realloc-posix for portability");
530#endif
531
532#if @GNULIB_REALPATH@
533# if @REPLACE_REALPATH@
534# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
535# define realpath rpl_realpath
536# endif
537_GL_FUNCDECL_RPL (realpath, char *, (const char *name, char *resolved)
538 _GL_ARG_NONNULL ((1)));
539_GL_CXXALIAS_RPL (realpath, char *, (const char *name, char *resolved));
540# else
541# if !@HAVE_REALPATH@
542_GL_FUNCDECL_SYS (realpath, char *, (const char *name, char *resolved)
543 _GL_ARG_NONNULL ((1)));
544# endif
545_GL_CXXALIAS_SYS (realpath, char *, (const char *name, char *resolved));
546# endif
547_GL_CXXALIASWARN (realpath);
548#elif defined GNULIB_POSIXCHECK
549# undef realpath
550# if HAVE_RAW_DECL_REALPATH
551_GL_WARN_ON_USE (realpath, "realpath is unportable - use gnulib module "
552 "canonicalize or canonicalize-lgpl for portability");
553# endif
554#endif
555
556#if @GNULIB_RPMATCH@
557/* Test a user response to a question.
558 Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
559# if !@HAVE_RPMATCH@
560_GL_FUNCDECL_SYS (rpmatch, int, (const char *response) _GL_ARG_NONNULL ((1)));
561# endif
562_GL_CXXALIAS_SYS (rpmatch, int, (const char *response));
563_GL_CXXALIASWARN (rpmatch);
564#elif defined GNULIB_POSIXCHECK
565# undef rpmatch
566# if HAVE_RAW_DECL_RPMATCH
567_GL_WARN_ON_USE (rpmatch, "rpmatch is unportable - "
568 "use gnulib module rpmatch for portability");
569# endif
570#endif
571
572#if @GNULIB_SETENV@
573/* Set NAME to VALUE in the environment.
574 If REPLACE is nonzero, overwrite an existing value. */
575# if @REPLACE_SETENV@
576# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
577# undef setenv
578# define setenv rpl_setenv
579# endif
580_GL_FUNCDECL_RPL (setenv, int,
581 (const char *name, const char *value, int replace)
582 _GL_ARG_NONNULL ((1)));
583_GL_CXXALIAS_RPL (setenv, int,
584 (const char *name, const char *value, int replace));
585# else
586# if !@HAVE_DECL_SETENV@
587_GL_FUNCDECL_SYS (setenv, int,
588 (const char *name, const char *value, int replace)
589 _GL_ARG_NONNULL ((1)));
590# endif
591_GL_CXXALIAS_SYS (setenv, int,
592 (const char *name, const char *value, int replace));
593# endif
594# if !(@REPLACE_SETENV@ && !@HAVE_DECL_SETENV@)
595_GL_CXXALIASWARN (setenv);
596# endif
597#elif defined GNULIB_POSIXCHECK
598# undef setenv
599# if HAVE_RAW_DECL_SETENV
600_GL_WARN_ON_USE (setenv, "setenv is unportable - "
601 "use gnulib module setenv for portability");
602# endif
603#endif
604
605#if @GNULIB_STRTOD@
606 /* Parse a double from STRING, updating ENDP if appropriate. */
607# if @REPLACE_STRTOD@
608# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
609# define strtod rpl_strtod
610# endif
611_GL_FUNCDECL_RPL (strtod, double, (const char *str, char **endp)
612 _GL_ARG_NONNULL ((1)));
613_GL_CXXALIAS_RPL (strtod, double, (const char *str, char **endp));
614# else
615# if !@HAVE_STRTOD@
616_GL_FUNCDECL_SYS (strtod, double, (const char *str, char **endp)
617 _GL_ARG_NONNULL ((1)));
618# endif
619_GL_CXXALIAS_SYS (strtod, double, (const char *str, char **endp));
620# endif
621_GL_CXXALIASWARN (strtod);
622#elif defined GNULIB_POSIXCHECK
623# undef strtod
624# if HAVE_RAW_DECL_STRTOD
625_GL_WARN_ON_USE (strtod, "strtod is unportable - "
626 "use gnulib module strtod for portability");
627# endif
628#endif
629
630#if @GNULIB_STRTOLL@
631/* Parse a signed integer whose textual representation starts at STRING.
632 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
633 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
634 "0x").
635 If ENDPTR is not NULL, the address of the first byte after the integer is
636 stored in *ENDPTR.
637 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
638 to ERANGE. */
639# if !@HAVE_STRTOLL@
640_GL_FUNCDECL_SYS (strtoll, long long,
641 (const char *string, char **endptr, int base)
642 _GL_ARG_NONNULL ((1)));
643# endif
644_GL_CXXALIAS_SYS (strtoll, long long,
645 (const char *string, char **endptr, int base));
646_GL_CXXALIASWARN (strtoll);
647#elif defined GNULIB_POSIXCHECK
648# undef strtoll
649# if HAVE_RAW_DECL_STRTOLL
650_GL_WARN_ON_USE (strtoll, "strtoll is unportable - "
651 "use gnulib module strtoll for portability");
652# endif
653#endif
654
655#if @GNULIB_STRTOULL@
656/* Parse an unsigned integer whose textual representation starts at STRING.
657 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
658 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
659 "0x").
660 If ENDPTR is not NULL, the address of the first byte after the integer is
661 stored in *ENDPTR.
662 Upon overflow, the return value is ULLONG_MAX, and errno is set to
663 ERANGE. */
664# if !@HAVE_STRTOULL@
665_GL_FUNCDECL_SYS (strtoull, unsigned long long,
666 (const char *string, char **endptr, int base)
667 _GL_ARG_NONNULL ((1)));
668# endif
669_GL_CXXALIAS_SYS (strtoull, unsigned long long,
670 (const char *string, char **endptr, int base));
671_GL_CXXALIASWARN (strtoull);
672#elif defined GNULIB_POSIXCHECK
673# undef strtoull
674# if HAVE_RAW_DECL_STRTOULL
675_GL_WARN_ON_USE (strtoull, "strtoull is unportable - "
676 "use gnulib module strtoull for portability");
677# endif
678#endif
679
680#if @GNULIB_UNLOCKPT@
681/* Unlock the slave side of the pseudo-terminal whose master side is specified
682 by FD, so that it can be opened. */
683# if !@HAVE_UNLOCKPT@
684_GL_FUNCDECL_SYS (unlockpt, int, (int fd));
685# endif
686_GL_CXXALIAS_SYS (unlockpt, int, (int fd));
687_GL_CXXALIASWARN (unlockpt);
688#elif defined GNULIB_POSIXCHECK
689# undef unlockpt
690# if HAVE_RAW_DECL_UNLOCKPT
691_GL_WARN_ON_USE (unlockpt, "unlockpt is not portable - "
692 "use gnulib module unlockpt for portability");
693# endif
694#endif
695
696#if @GNULIB_UNSETENV@
697/* Remove the variable NAME from the environment. */
698# if @REPLACE_UNSETENV@
699# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
700# undef unsetenv
701# define unsetenv rpl_unsetenv
702# endif
703_GL_FUNCDECL_RPL (unsetenv, int, (const char *name) _GL_ARG_NONNULL ((1)));
704_GL_CXXALIAS_RPL (unsetenv, int, (const char *name));
705# else
706# if !@HAVE_DECL_UNSETENV@
707_GL_FUNCDECL_SYS (unsetenv, int, (const char *name) _GL_ARG_NONNULL ((1)));
708# endif
709_GL_CXXALIAS_SYS (unsetenv, int, (const char *name));
710# endif
711# if !(@REPLACE_UNSETENV@ && !@HAVE_DECL_UNSETENV@)
712_GL_CXXALIASWARN (unsetenv);
713# endif
714#elif defined GNULIB_POSIXCHECK
715# undef unsetenv
716# if HAVE_RAW_DECL_UNSETENV
717_GL_WARN_ON_USE (unsetenv, "unsetenv is unportable - "
718 "use gnulib module unsetenv for portability");
719# endif
720#endif
721
722
723#endif /* _GL_STDLIB_H */
724#endif /* _GL_STDLIB_H */
725#endif