mirror of
git://git.musl-libc.org/musl
synced 2024-11-23 18:14:19 +08:00
add legacy getloadavg api
This commit is contained in:
parent
ceb0ed9cf9
commit
a516077feb
@ -139,6 +139,7 @@ int mkstemps (char *, int);
|
||||
int mkostemps (char *, int, int);
|
||||
void *valloc (size_t);
|
||||
void *memalign(size_t, size_t);
|
||||
int getloadavg(double *, int);
|
||||
#define WCOREDUMP(s) ((s) & 0x80)
|
||||
#define WIFCONTINUED(s) ((s) == 0xffff)
|
||||
#endif
|
||||
|
18
src/legacy/getloadavg.c
Normal file
18
src/legacy/getloadavg.c
Normal file
@ -0,0 +1,18 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int getloadavg(double *a, int n)
|
||||
{
|
||||
int i;
|
||||
double b[3];
|
||||
FILE *f = fopen("/proc/loadavg", "rbe");
|
||||
if (!f) return -1;
|
||||
i = fscanf(f, "%lf %lf %lf", b, b+1, b+2);
|
||||
fclose(f);
|
||||
if (n > i) n = i;
|
||||
if (n < 0) return -1;
|
||||
memcpy(a, b, n * sizeof *a);
|
||||
return n;
|
||||
}
|
Loading…
Reference in New Issue
Block a user