/* 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)
# 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
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_named_t *kn;
+ int saved_errno;
kc = kstat_open ();
if (kc == 0)
}
}
+ saved_errno = errno;
kstat_close (kc);
+ errno = saved_errno;
# endif /* HAVE_LIBKSTAT */
# if !defined (LDAV_DONE) && defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC)
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';
{
double numerator = 0;
double denominator = 1;
- bool have_digit = false;
while (*ptr == ' ')
ptr++;
if (! ('0' <= *ptr && *ptr <= '9'))
{
if (elem == 0)
- return -1;
+ {
+ errno = ENOTSUP;
+ return -1;
+ }
break;
}
&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;
}
if (!getloadavg_initialized)
- return -1;
+ {
+ errno = ENOTSUP;
+ return -1;
+ }
# endif /* NeXT */
# if !defined (LDAV_DONE) && defined (UMAX)
}
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
}
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. */
# 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;