Skip to content

Commit

Permalink
Fix build with newer uClibc-ng
Browse files Browse the repository at this point in the history
  • Loading branch information
HiGarfield committed Jan 24, 2025
1 parent 99a8523 commit 6c5aa1a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
21 changes: 12 additions & 9 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@
#define _GNU_SOURCE
#endif

#include "util.h" /* Must be included at first!!! */
#include <stdio.h>
#include <string.h>
#include <sys/resource.h>
#include <unistd.h>
#if defined(__linux__) && defined(__UCLIBC__)
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#endif

#if defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/types.h>
#include <sys/sysctl.h>
#endif

#ifdef __IMPL_GET_TIME
#include <sys/time.h>
#endif

#ifdef __IMPL_GETLOADAVG
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#endif

#if defined(__linux__) && !defined(_SC_NPROCESSORS_ONLN)
#include <sys/sysinfo.h>
#endif

#include "util.h"

#ifdef __IMPL_BASENAME
const char *__basename(const char *path)
{
Expand Down Expand Up @@ -143,8 +146,8 @@ pid_t get_pid_max(void)
#endif
}

#if defined(__linux__) && defined(__UCLIBC__)
int getloadavg(double *loadavg, int nelem)
#ifdef __IMPL_GETLOADAVG
int __getloadavg(double *loadavg, int nelem)
{
int fd, i;
char buffer[65], *ptr;
Expand Down
19 changes: 17 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,19 @@ int get_ncpu(void);
*/
pid_t get_pid_max(void);

#if defined(__linux__) && defined(__UCLIBC__)
/**
* If uClibc/uClibc-ng is below 1.0.42,
* implement a custom getloadavg function
*/
#if defined(__linux__) && \
defined(__UCLIBC__) && \
defined(__UCLIBC_MAJOR__) && \
defined(__UCLIBC_MINOR__) && \
defined(__UCLIBC_SUBLEVEL__) && \
((__UCLIBC_MAJOR__ < 1) || \
(__UCLIBC_MAJOR__ == 1 && \
__UCLIBC_MINOR__ == 0 && \
__UCLIBC_SUBLEVEL__ < 42))
/**
* Retrieves up to nelem load averages for system processes over the
* last 1, 5, and 15 minutes.
Expand All @@ -187,7 +199,10 @@ pid_t get_pid_max(void);
* @return The number of samples retrieved, or -1 if the load
* average could not be obtained.
*/
int getloadavg(double *loadavg, int nelem);
int __getloadavg(double *loadavg, int nelem);
#define getloadavg(loadavg, nelem) \
(__getloadavg((loadavg), (nelem)))
#define __IMPL_GETLOADAVG
#endif

#endif

0 comments on commit 6c5aa1a

Please sign in to comment.