Merge from gnulib.

This commit is contained in:
Paul Eggert 2011-02-15 16:23:58 -08:00
parent 5740d4abab
commit 976e1fab21

View file

@ -495,7 +495,7 @@ static kvm_t *kd;
/* Put the 1 minute, 5 minute and 15 minute load averages
into the first NELEM elements of LOADAVG.
Return the number written (never more than 3, but may be less than NELEM),
or -1 if an error occurred. */
or -1 (setting errno) if an error occurred. */
int
getloadavg (double loadavg[], int nelem)
@ -504,9 +504,7 @@ getloadavg (double loadavg[], int nelem)
# ifdef NO_GET_LOAD_AVG
# define LDAV_DONE
/* Set errno to zero to indicate that there was no particular error;
this function just can't work at all on this system. */
errno = 0;
errno = ENOSYS;
elem = -1;
# endif
@ -516,6 +514,7 @@ getloadavg (double loadavg[], int nelem)
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_named_t *kn;
int saved_errno;
kc = kstat_open ();
if (kc == 0)
@ -554,7 +553,9 @@ getloadavg (double loadavg[], int nelem)
}
}
saved_errno = errno;
kstat_close (kc);
errno = saved_errno;
# endif /* HAVE_LIBKSTAT */
# if !defined (LDAV_DONE) && defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC)
@ -600,13 +601,15 @@ getloadavg (double loadavg[], int nelem)
char ldavgbuf[3 * (INT_STRLEN_BOUND (int) + sizeof ".00 ")];
char const *ptr = ldavgbuf;
int fd, count;
int fd, count, saved_errno;
fd = open (LINUX_LDAV_FILE, O_RDONLY);
if (fd == -1)
return -1;
count = read (fd, ldavgbuf, sizeof ldavgbuf - 1);
saved_errno = errno;
(void) close (fd);
errno = saved_errno;
if (count <= 0)
return -1;
ldavgbuf[count] = '\0';
@ -615,7 +618,6 @@ getloadavg (double loadavg[], int nelem)
{
double numerator = 0;
double denominator = 1;
bool have_digit = false;
while (*ptr == ' ')
ptr++;
@ -625,7 +627,10 @@ getloadavg (double loadavg[], int nelem)
if (! ('0' <= *ptr && *ptr <= '9'))
{
if (elem == 0)
return -1;
{
errno = ENOTSUP;
return -1;
}
break;
}
@ -663,7 +668,10 @@ getloadavg (double loadavg[], int nelem)
&scale);
(void) fclose (fp);
if (count != 4)
return -1;
{
errno = ENOTSUP;
return -1;
}
for (elem = 0; elem < nelem; elem++)
loadavg[elem] = (double) load_ave[elem] / (double) scale;
@ -704,7 +712,10 @@ getloadavg (double loadavg[], int nelem)
}
if (!getloadavg_initialized)
return -1;
{
errno = ENOTSUP;
return -1;
}
# endif /* NeXT */
# if !defined (LDAV_DONE) && defined (UMAX)
@ -889,7 +900,10 @@ getloadavg (double loadavg[], int nelem)
}
if (!getloadavg_initialized)
return -1;
{
errno = ENOTSUP;
return -1;
}
# endif /* ! defined LDAV_DONE && defined __VMS */
# if ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS
@ -1005,7 +1019,10 @@ getloadavg (double loadavg[], int nelem)
}
if (offset == 0 || !getloadavg_initialized)
return -1;
{
errno = ENOTSUP;
return -1;
}
# endif /* ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS */
# if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) /* Including VMS. */
@ -1020,9 +1037,7 @@ getloadavg (double loadavg[], int nelem)
# endif /* !LDAV_DONE && LOAD_AVE_TYPE */
# if !defined LDAV_DONE
/* Set errno to zero to indicate that there was no particular error;
this function just can't work at all on this system. */
errno = 0;
errno = ENOSYS;
elem = -1;
# endif
return elem;