From: Alan Cox Date: Sun, 24 May 2015 21:46:04 +0000 (+0100) Subject: libc: add the getloadavg() interface from 2BSD X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=8551f7fd486f84938f65e00c87a053360603760a;p=FUZIX.git libc: add the getloadavg() interface from 2BSD --- diff --git a/Library/include/stdlib.h b/Library/include/stdlib.h index 210099ec..c474b4ae 100644 --- a/Library/include/stdlib.h +++ b/Library/include/stdlib.h @@ -92,4 +92,6 @@ extern char *getpass(char *prompt); extern int _argc; extern char **_argv; +extern int getloadavg __P((unsigned int loadavg[], int nelem)); + #endif /* __STDLIB_H */ diff --git a/Library/libs/Makefile b/Library/libs/Makefile index ce3f4680..2fe30f4c 100644 --- a/Library/libs/Makefile +++ b/Library/libs/Makefile @@ -26,7 +26,7 @@ SRC_C += execl.c execv.c execvp.c exit.c SRC_C += fclose.c fflush.c fgetc.c fgetgrent.c fgetpwent.c SRC_C += fgetpos.c fgets.c fopen.c fprintf.c fputc.c fputs.c fread.c free.c SRC_C += fsetpos.c ftell.c fwrite.c getcwd.c -SRC_C += getenv.c __getgrent.c getgrgid.c getgrnam.c getopt.c +SRC_C += getenv.c __getgrent.c getgrgid.c getgrnam.c getloadavg.c getopt.c SRC_C += getpw.c __getpwent.c getpwnam.c getpwuid.c gets.c gettimeofday.c SRC_C += gmtime.c gmtime_r.c grent.c index.c isatty.c killpg.c SRC_C += libintl.c diff --git a/Library/libs/Makefile.6502 b/Library/libs/Makefile.6502 index c9cba5f8..d7daa888 100644 --- a/Library/libs/Makefile.6502 +++ b/Library/libs/Makefile.6502 @@ -38,7 +38,7 @@ SRC_C += execl.c execv.c execvp.c exit.c SRC_C += fclose.c fflush.c fgetc.c fgetgrent.c fgetpwent.c SRC_C += fgetpos.c fgets.c fopen.c fprintf.c fputc.c fputs.c fread.c free.c SRC_C += fsetpos.c ftell.c fwrite.c getcwd.c -SRC_C += getenv.c __getgrent.c getgrgid.c getgrnam.c getopt.c +SRC_C += getenv.c __getgrent.c getgrgid.c getgrnam.c getloadavg.c getopt.c SRC_C += getpw.c __getpwent.c getpwnam.c getpwuid.c gets.c gettimeofday.c SRC_C += gmtime.c gmtime_r.c grent.c index.c isatty.c killpg.c SRC_C += libintl.c diff --git a/Library/libs/Makefile.6809 b/Library/libs/Makefile.6809 index a721a770..471e28b4 100644 --- a/Library/libs/Makefile.6809 +++ b/Library/libs/Makefile.6809 @@ -19,7 +19,7 @@ SRC_C += execl.c execv.c execvp.c exit.c SRC_C += fclose.c fflush.c fgetc.c fgetgrent.c fgetpwent.c SRC_C += fgetpos.c fgets.c fopen.c fprintf.c fputc.c fputs.c fread.c free.c SRC_C += fsetpos.c ftell.c fwrite.c getcwd.c -SRC_C += getenv.c __getgrent.c getgrgid.c getgrnam.c getopt.c +SRC_C += getenv.c __getgrent.c getgrgid.c getgrnam.c getloadavg.c getopt.c SRC_C += getpw.c __getpwent.c getpwnam.c getpwuid.c gets.c gettimeofday.c SRC_C += gmtime.c gmtime_r.c grent.c index.c isatty.c killpg.c SRC_C += libintl.c diff --git a/Library/libs/getloadavg.c b/Library/libs/getloadavg.c new file mode 100644 index 00000000..23306b5a --- /dev/null +++ b/Library/libs/getloadavg.c @@ -0,0 +1,23 @@ +/* + * BSD has an API for this so we might as well provide a libc API + * using the same interface. Pity the API varies between systems on + * the type used for loadavg! + */ + +#include +#include + +int getloadavg(unsigned int loadavg[], int nelem) +{ + static struct _uzisysinfoblk uts; + uint8_t i; + int bytes = _uname(&uts, sizeof(uts)); + + if (bytes < sizeof(uts)) + return -1; + if (nelem > 3) + nelem = 3; + for (i = 0; i < nelem; i++) + loadavg[i] = (uts.loadavg[i] * 100) >> 8; + return nelem; +}