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