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 4, 2025
1 parent 53c9698 commit ebd677d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,42 @@ pid_t get_pid_max(void)
#error "Platform not supported"
#endif
}

#if defined(__linux__) && defined(__UCLIBC__)
int getloadavg(double *a, int n)
{
FILE *fp;
int i;

if (n <= 0)
{
return n ? -1 : 0;
}
if (n > 3)
{
n = 3;
}

fp = fopen("/proc/loadavg", "r");
if (fp == NULL)
{
perror("Failed to open /proc/loadavg");
return -1;
}

for (i = 0; i < n; i++)
{
if (fscanf(fp, "%lf", &a[i]) != 1)
{
break;
}
}

if (fclose(fp) != 0)
{
perror("Failed to close /proc/loadavg");
}

return i;
}
#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);

#if defined(__linux__) && defined(__UCLIBC__)
int getloadavg(double *a, int n);
#endif

#endif

0 comments on commit ebd677d

Please sign in to comment.