enum xlat_style, const struct xlat *, ...)
ATTRIBUTE_SENTINEL;
extern const char *sprintflags_ex(const char *prefix, const struct xlat *,
- uint64_t flags, enum xlat_style);
+ uint64_t flags, char sep, enum xlat_style);
static inline const char *
sprintflags(const char *prefix, const struct xlat *xlat, uint64_t flags)
{
- return sprintflags_ex(prefix, xlat, flags, XLAT_STYLE_DEFAULT);
+ return sprintflags_ex(prefix, xlat, flags, '\0', XLAT_STYLE_DEFAULT);
}
extern const char *sprinttime(long long sec);
const char *
sprint_open_modes(unsigned int flags)
{
- static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
+ static char outstr[sizeof("flags O_ACCMODE")];
char *p;
char sep;
const char *str;
- const struct xlat *x;
sep = ' ';
p = stpcpy(outstr, "flags");
return outstr;
sep = '|';
}
+ *p = '\0';
- for (x = open_mode_flags; x->str; x++) {
- if ((flags & x->val) == x->val) {
- *p++ = sep;
- p = stpcpy(p, x->str);
- flags &= ~x->val;
- if (!flags)
- return outstr;
- sep = '|';
- }
- }
- /* flags is still nonzero */
- *p++ = sep;
- p = xappendstr(outstr, p, "%#x", flags);
- return outstr;
+ return sprintflags_ex(outstr, open_mode_flags, flags, sep,
+ XLAT_STYLE_ABBREV) ?: outstr;
}
void
*/
const char *
sprintflags_ex(const char *prefix, const struct xlat *xlat, uint64_t flags,
- enum xlat_style style)
+ char sep, enum xlat_style style)
{
static char outstr[1024];
char *outptr;
if (!flags)
return NULL;
+ if (sep)
+ *outptr++ = sep;
outptr = xappendstr(outstr, outptr, "%s",
sprint_xlat_val(flags, style));
}
if (flags == 0 && xlat->val == 0 && xlat->str) {
+ if (sep)
+ *outptr++ = sep;
if (xlat_verbose(style) == XLAT_STYLE_VERBOSE) {
outptr = xappendstr(outstr, outptr, "0 /* %s */",
xlat->str);
return outstr;
}
- if (xlat_verbose(style) == XLAT_STYLE_VERBOSE && flags)
+ if (xlat_verbose(style) == XLAT_STYLE_VERBOSE && flags) {
+ if (sep) {
+ *outptr++ = sep;
+ sep = '\0';
+ }
outptr = xappendstr(outstr, outptr, "%s",
sprint_xlat_val(flags, style));
+ }
for (; flags && xlat->str; xlat++) {
if (xlat->val && (flags & xlat->val) == xlat->val) {
- if (found)
- *outptr++ = '|';
- else if (xlat_verbose(style) == XLAT_STYLE_VERBOSE)
+ if (sep) {
+ *outptr++ = sep;
+ } else if (xlat_verbose(style) == XLAT_STYLE_VERBOSE) {
outptr = stpcpy(outptr, " /* ");
+ }
outptr = stpcpy(outptr, xlat->str);
found = 1;
+ sep = '|';
flags &= ~xlat->val;
}
}
if (flags) {
- if (found)
- *outptr++ = '|';
+ if (sep)
+ *outptr++ = sep;
if (found || xlat_verbose(style) != XLAT_STYLE_VERBOSE)
outptr = xappendstr(outstr, outptr, "%s",
sprint_xlat_val(flags, style));