#ifdef O_CLOEXEC
{ O_CLOEXEC, "O_CLOEXEC" },
#endif
-
#ifdef FNDELAY
{ FNDELAY, "FNDELAY" },
#endif
const char *
sprint_open_modes(mode_t flags)
{
- static char outstr[1024];
+ static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
char *p;
- char sep = 0;
+ char sep;
const char *str;
const struct xlat *x;
- p = stpcpy(outstr, "flags ");
+ sep = ' ';
+ p = stpcpy(outstr, "flags");
str = xlookup(open_access_modes, flags & 3);
if (str) {
+ *p++ = sep;
p = stpcpy(p, str);
flags &= ~3;
if (!flags)
for (x = open_mode_flags; x->str; x++) {
if ((flags & x->val) == x->val) {
- if (sep)
- *p++ = sep;
+ *p++ = sep;
p = stpcpy(p, x->str);
flags &= ~x->val;
if (!flags)
}
}
/* flags is still nonzero */
- if (sep)
- *p++ = sep;
+ *p++ = sep;
sprintf(p, "%#x", flags);
return outstr;
}
* and sig 0 doesn't exist either.
* Therefore max possible no of sigs is 255: 1..255
*/
- static char outstr[8 * 255];
+ static char outstr[8 * (255 * 2 / 3)];
int i, nsigs;
int maxsigs;
- const char *format;
+ int show_members;
+ char sep;
char *s;
- strcpy(outstr, str);
- s = outstr + strlen(outstr);
- nsigs = 0;
maxsigs = nsignals;
#ifdef __SIGRTMAX
if (rt)
maxsigs = __SIGRTMAX; /* instead */
#endif
+ s = stpcpy(outstr, str);
+ nsigs = 0;
for (i = 1; i < maxsigs; i++) {
if (sigismember(mask, i) == 1)
nsigs++;
}
- if (nsigs >= nsignals * 2 / 3) {
+
+ /* 1: show mask members, 0: show those which are NOT in mask */
+ show_members = (nsigs < nsignals * 2 / 3);
+ if (!show_members)
*s++ = '~';
- for (i = 1; i < maxsigs; i++) {
- switch (sigismember(mask, i)) {
- case 1:
- sigdelset(mask, i);
- break;
- case 0:
- sigaddset(mask, i);
- break;
- }
- }
- }
- format = "%s";
- *s++ = '[';
+
+ sep = '[';
for (i = 1; i < maxsigs; i++) {
- if (sigismember(mask, i) == 1) {
+ if (sigismember(mask, i) == show_members) {
/* real-time signals on solaris don't have
* signalent entries
*/
+ char tsig[40];
+ *s++ = sep;
if (i < nsignals) {
- sprintf(s, format, signalent[i] + 3);
+ s = stpcpy(s, signalent[i] + 3);
}
#ifdef SIGRTMIN
else if (i >= __SIGRTMIN && i <= __SIGRTMAX) {
- char tsig[40];
sprintf(tsig, "RT_%u", i - __SIGRTMIN);
- sprintf(s, format, tsig);
+ s = stpcpy(s, tsig);
}
#endif /* SIGRTMIN */
else {
- char tsig[32];
sprintf(tsig, "%u", i);
- sprintf(s, format, tsig);
+ s = stpcpy(s, tsig);
}
- s += strlen(s);
- format = " %s";
+ sep = ' ';
}
}
+ if (sep == '[')
+ *s++ = sep;
*s++ = ']';
*s = '\0';
return outstr;
int m, n, len;
for (path = getenv("PATH"); path && *path; path += m) {
- if (strchr(path, ':')) {
- n = strchr(path, ':') - path;
+ const char *colon = strchr(path, ':');
+ if (colon) {
+ n = colon - path;
m = n + 1;
}
else