Consolidate repeated macro definitions into one header

The MIN, MAX, CLAMP, MINIMUM, and MAXIMUM macros appear
throughout the codebase with many re-definitions.  Make
a single copy of each in a common header file, and use
the BSD variants of MINIMUM/MAXIMUM due to conflicts in
the system <sys/param.h> headers.
This commit is contained in:
Nathan Scott
2020-09-09 16:56:04 +10:00
parent 8ec5d4a3a0
commit c5808c56db
29 changed files with 35 additions and 156 deletions

View File

@ -42,10 +42,6 @@ in the source distribution for its full text.
#include <linux/taskstats.h>
#endif
#ifndef CLAMP
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
#endif
static ssize_t xread(int fd, void *buf, size_t count) {
// Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested.
size_t alreadyRead = 0;
@ -194,7 +190,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
fclose(file);
pl->cpuCount = MAX(cpus - 1, 1);
pl->cpuCount = MAXIMUM(cpus - 1, 1);
this->cpus = xCalloc(cpus, sizeof(CPUData));
for (int i = 0; i < cpus; i++) {

View File

@ -92,10 +92,6 @@ typedef struct LinuxProcessList_ {
#define PROC_LINE_LENGTH 4096
#endif
#ifndef CLAMP
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
#endif
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
void ProcessList_delete(ProcessList* pl);

View File

@ -33,10 +33,6 @@ in the source distribution for its full text.
#include <stdlib.h>
#ifndef CLAMP
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
#endif
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, (int)M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
//static ProcessField defaultIoFields[] = { PID, IO_PRIORITY, USER, IO_READ_RATE, IO_WRITE_RATE, IO_RATE, COMM, 0 };

View File

@ -13,10 +13,6 @@ in the source distribution for its full text.
#include "LinuxProcess.h"
#include "SignalsPanel.h"
#ifndef CLAMP
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
#endif
extern ProcessField Platform_defaultFields[];
extern int Platform_numberOfFields;