library: rework namespace calls

Functions related to namespaces were half-in half-out of the
procps library and didn't fit the standard naming scheme.

While struct { long ns[x]} is a bit clunky, its the only way
to "lock in" x. The alternative is to use ns_* variables.

This work was needed before pgrep could be converted.
This commit is contained in:
Craig Small
2015-09-03 22:32:19 +10:00
parent d9caf0980e
commit a61f78d6e0
16 changed files with 297 additions and 134 deletions

View File

@ -171,8 +171,8 @@ static int sr_ ## NAME (const proc_t* P, const proc_t* Q) { \
#define CMP_NS(NAME, ID) \
static int sr_ ## NAME (const proc_t* P, const proc_t* Q) { \
if (P->ns[ID] < Q->ns[ID]) return -1; \
if (P->ns[ID] > Q->ns[ID]) return 1; \
if (P->ns.ns[ID] < Q->ns.ns[ID]) return -1; \
if (P->ns.ns[ID] > Q->ns.ns[ID]) return 1; \
return 0; \
}
@ -1253,8 +1253,8 @@ static int pr_sd_slice(char *restrict const outbuf, const proc_t *restrict const
#define _pr_ns(NAME, ID)\
static int pr_##NAME(char *restrict const outbuf, const proc_t *restrict const pp) {\
if (pp->ns[ID])\
return snprintf(outbuf, COLWID, "%li", pp->ns[ID]);\
if (pp->ns.ns[ID])\
return snprintf(outbuf, COLWID, "%li", pp->ns.ns[ID]);\
else\
return snprintf(outbuf, COLWID, "-");\
}