Skip to content

Commit

Permalink
Fix a compilation error with uClibc
Browse files Browse the repository at this point in the history
  • Loading branch information
HiGarfield committed Jan 3, 2025
1 parent 53c9698 commit d1d9969
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#if defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/sysctl.h>
#endif
#ifdef __UCLIBC__
#include <sys/sysinfo.h>
#endif
#include "util.h"

#ifdef __IMPL_BASENAME
Expand Down Expand Up @@ -96,3 +99,19 @@ pid_t get_pid_max(void)
#error "Platform not supported"
#endif
}

#ifdef __UCLIBC__
int getloadavg(double *a, int n)
{
struct sysinfo si;
int i;
if (n <= 0)
return n ? -1 : 0;
sysinfo(&si);
if (n > 3)
n = 3;
for (i = 0; i < n; i++)
a[i] = 1.0 / (1 << SI_LOAD_SHIFT) * si.loads[i];
return n;
}
#endif
4 changes: 4 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,8 @@ int get_ncpu(void);
*/
pid_t get_pid_max(void);

#ifdef __UCLIBC__
int getloadavg(double *a, int n);
#endif

#endif

0 comments on commit d1d9969

Please sign in to comment.