aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Love2003-06-05 16:24:51 +0000
committerDave Love2003-06-05 16:24:51 +0000
commit87c359749caa9203fa3eac4370bb088397f11e1d (patch)
treebef3a3b1c0fc280a5716bc37b7c8cd1f08d73c44
parent984257db1789c93908ffd49224e8b2a59968b735 (diff)
downloademacs-87c359749caa9203fa3eac4370bb088397f11e1d.tar.gz
emacs-87c359749caa9203fa3eac4370bb088397f11e1d.zip
Set NLIST_STRUCT from HAVE_NLIST_H. Use
HAVE_STRUCT_NLIST_N_UN_N_NAME, not NLIST_NAME_UNION. [HAVE_LOCALE_H]: Include locale.h. (getloadavg) [HAVE_SETLOCALE]: Run sscanf in C locale.
-rw-r--r--src/getloadavg.c48
1 files changed, 34 insertions, 14 deletions
diff --git a/src/getloadavg.c b/src/getloadavg.c
index 6700d81395a..462ee16fa54 100644
--- a/src/getloadavg.c
+++ b/src/getloadavg.c
@@ -1,7 +1,10 @@
1/* Get the system load averages. 1/* Get the system load averages.
2 Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994, 1995, 1997 2 Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994, 1995, 1997, 2003
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5 NOTE: The canonical source of this file is maintained with gnulib.
6 Bugs can be reported to bug-gnulib@gnu.org.
7
5 This program is free software; you can redistribute it and/or modify 8 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 9 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option) 10 the Free Software Foundation; either version 2, or (at your option)
@@ -37,11 +40,15 @@
37 apollo, DGUX, NeXT, or UMAX is defined; 40 apollo, DGUX, NeXT, or UMAX is defined;
38 or we have libkstat; 41 or we have libkstat;
39 otherwise, no load average is available. 42 otherwise, no load average is available.
43 HAVE_NLIST_H nlist.h is available. NLIST_STRUCT defaults
44 to this.
40 NLIST_STRUCT Include nlist.h, not a.out.h, and 45 NLIST_STRUCT Include nlist.h, not a.out.h, and
41 the nlist n_name element is a pointer, 46 the nlist n_name element is a pointer,
42 not an array. 47 not an array.
43 NLIST_NAME_UNION struct nlist has an n_un member, not n_name. 48 HAVE_STRUCT_NLIST_N_UN_N_NAME `n_un.n_name' is member of `struct nlist'.
44 LINUX_LDAV_FILE [__linux__]: File containing load averages. 49 LINUX_LDAV_FILE [__linux__]: File containing load averages.
50 HAVE_LOCALE_H locale.h is available.
51 HAVE_SETLOCALE The `setlocale' function is available.
45 52
46 Specific system predefines this file uses, aside from setting 53 Specific system predefines this file uses, aside from setting
47 default values if not emacs: 54 default values if not emacs:
@@ -99,8 +106,14 @@
99extern int errno; 106extern int errno;
100#endif 107#endif
101 108
102#ifndef HAVE_GETLOADAVG 109#ifdef HAVE_LOCALE_H
110# include <locale.h>
111#endif
112#ifndef HAVE_SETLOCALE
113# define setlocale(Category, Locale) /* empty */
114#endif
103 115
116#ifndef HAVE_GETLOADAVG
104 117
105/* The existing Emacs configuration files define a macro called 118/* The existing Emacs configuration files define a macro called
106 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and 119 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and
@@ -288,7 +301,7 @@ extern int errno;
288/* Sometimes both MIPS and sgi are defined, so FSCALE was just defined 301/* Sometimes both MIPS and sgi are defined, so FSCALE was just defined
289 above under #ifdef MIPS. But we want the sgi value. */ 302 above under #ifdef MIPS. But we want the sgi value. */
290# undef FSCALE 303# undef FSCALE
291# define FSCALE 1000.0 304# define FSCALE 1000.0
292# endif 305# endif
293 306
294# if defined (ardent) && defined (titan) 307# if defined (ardent) && defined (titan)
@@ -306,9 +319,14 @@ extern int errno;
306# endif /* Not FSCALE. */ 319# endif /* Not FSCALE. */
307 320
308# if !defined (LDAV_CVT) && defined (FSCALE) 321# if !defined (LDAV_CVT) && defined (FSCALE)
309# define LDAV_CVT(n) (((double) (n)) / FSCALE) 322# define LDAV_CVT(n) (((double) (n)) / FSCALE)
310# endif 323# endif
311 324
325# ifndef NLIST_STRUCT
326# if HAVE_NLIST_H
327# define NLIST_STRUCT
328# endif
329# endif
312 330
313# if defined(sgi) || (defined(mips) && !defined(BSD)) 331# if defined(sgi) || (defined(mips) && !defined(BSD))
314# define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31)) 332# define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31))
@@ -446,7 +464,6 @@ extern int errno;
446# include <sys/file.h> 464# include <sys/file.h>
447# endif 465# endif
448 466
449
450/* Avoid static vars inside a function since in HPUX they dump as pure. */ 467/* Avoid static vars inside a function since in HPUX they dump as pure. */
451 468
452# ifdef NeXT 469# ifdef NeXT
@@ -471,13 +488,13 @@ static int getloadavg_initialized;
471/* Offset in kmem to seek to read load average, or 0 means invalid. */ 488/* Offset in kmem to seek to read load average, or 0 means invalid. */
472static long offset; 489static long offset;
473 490
474#if !defined(VMS) && !defined(sgi) && !defined(__linux__) 491# if !defined(VMS) && !defined(sgi) && !defined(__linux__)
475static struct nlist nl[2]; 492static struct nlist nl[2];
476#endif /* Not VMS or sgi */ 493# endif /* Not VMS or sgi */
477 494
478#ifdef SUNOS_5 495# ifdef SUNOS_5
479static kvm_t *kd; 496static kvm_t *kd;
480#endif /* SUNOS_5 */ 497# endif /* SUNOS_5 */
481 498
482#endif /* LOAD_AVE_TYPE && !HAVE_LIBKSTAT */ 499#endif /* LOAD_AVE_TYPE && !HAVE_LIBKSTAT */
483 500
@@ -585,8 +602,11 @@ getloadavg (loadavg, nelem)
585 if (count <= 0) 602 if (count <= 0)
586 return -1; 603 return -1;
587 604
605 /* The following sscanf must use the C locale. */
606 setlocale (LC_NUMERIC, "C");
588 count = sscanf (ldavgbuf, "%lf %lf %lf", 607 count = sscanf (ldavgbuf, "%lf %lf %lf",
589 &load_ave[0], &load_ave[1], &load_ave[2]); 608 &load_ave[0], &load_ave[1], &load_ave[2]);
609 setlocale (LC_NUMERIC, "");
590 if (count < 1) 610 if (count < 1)
591 return -1; 611 return -1;
592 612
@@ -862,13 +882,13 @@ getloadavg (loadavg, nelem)
862 strcpy (nl[0].n_name, LDAV_SYMBOL); 882 strcpy (nl[0].n_name, LDAV_SYMBOL);
863 strcpy (nl[1].n_name, ""); 883 strcpy (nl[1].n_name, "");
864# else /* NLIST_STRUCT */ 884# else /* NLIST_STRUCT */
865# ifdef NLIST_NAME_UNION 885# ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME
866 nl[0].n_un.n_name = LDAV_SYMBOL; 886 nl[0].n_un.n_name = LDAV_SYMBOL;
867 nl[1].n_un.n_name = 0; 887 nl[1].n_un.n_name = 0;
868# else /* not NLIST_NAME_UNION */ 888# else /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */
869 nl[0].n_name = LDAV_SYMBOL; 889 nl[0].n_name = LDAV_SYMBOL;
870 nl[1].n_name = 0; 890 nl[1].n_name = 0;
871# endif /* not NLIST_NAME_UNION */ 891# endif /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */
872# endif /* NLIST_STRUCT */ 892# endif /* NLIST_STRUCT */
873 893
874# ifndef SUNOS_5 894# ifndef SUNOS_5
@@ -977,7 +997,7 @@ getloadavg (loadavg, nelem)
977#endif /* ! HAVE_GETLOADAVG */ 997#endif /* ! HAVE_GETLOADAVG */
978 998
979#ifdef TEST 999#ifdef TEST
980int 1000void
981main (argc, argv) 1001main (argc, argv)
982 int argc; 1002 int argc;
983 char **argv; 1003 char **argv;