From a6c0d8c90a1cc3117f70281968d9efe6de755d83 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 1 Nov 2007 21:46:22 +0000 Subject: [PATCH] 2007-09-22 Dmitry V. Levin * desc.c (sprintflags): Remove static qualifier, add "prefix" argument, move function to ... * util.c (sprintflags): ... here. * defs.h (sprintflags): Declare it. --- defs.h | 1 + desc.c | 25 ++----------------------- util.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/defs.h b/defs.h index a3ce8672..2905a33c 100644 --- a/defs.h +++ b/defs.h @@ -444,6 +444,7 @@ extern void printxval P((const struct xlat *, int, const char *)); extern int printargs P((struct tcb *)); extern int addflags P((const struct xlat *, int)); extern int printflags P((const struct xlat *, int, const char *)); +extern const char *sprintflags P((const char *, const struct xlat *, int)); extern int umoven P((struct tcb *, long, int, char *)); extern int umovestr P((struct tcb *, long, int, char *)); extern int upeek P((int, long, long *)); diff --git a/desc.c b/desc.c index 4d82fa8e..47aa92c8 100644 --- a/desc.c +++ b/desc.c @@ -242,28 +242,6 @@ int getlk; } #endif -static const char * -sprintflags(const struct xlat *xlat, int flags) -{ - static char outstr[1024]; - const char *sep; - - strcpy(outstr, "flags "); - sep = ""; - for (; xlat->str; xlat++) { - if ((flags & xlat->val) == xlat->val) { - sprintf(outstr + strlen(outstr), - "%s%s", sep, xlat->str); - sep = "|"; - flags &= ~xlat->val; - } - } - if (flags) - sprintf(outstr + strlen(outstr), - "%s%#x", sep, flags); - return outstr; -} - /* * low bits of the open(2) flags define access mode, * other bits are real flags. @@ -356,7 +334,8 @@ sys_fcntl(struct tcb *tcp) case F_GETFD: if (tcp->u_rval == 0) return 0; - tcp->auxstr = sprintflags(fdflags, tcp->u_rval); + tcp->auxstr = + sprintflags("flags ", fdflags, tcp->u_rval); return RVAL_HEX|RVAL_STR; case F_GETFL: tcp->auxstr = sprint_open_modes(tcp->u_rval); diff --git a/util.c b/util.c index 7b52df4a..461b9dac 100644 --- a/util.c +++ b/util.c @@ -280,6 +280,37 @@ int flags; return n; } +/* + * Interpret `xlat' as an array of flags/ + * Print to static string the entries whose bits are on in `flags' + * Return static string. + */ +const char * +sprintflags(const char *prefix, const struct xlat *xlat, int flags) +{ + static char outstr[1024]; + int found = 0; + + strcpy(outstr, prefix); + + for (; xlat->str; xlat++) { + if ((flags & xlat->val) == xlat->val) { + if (found) + strcat(outstr, "|"); + strcat(outstr, xlat->str); + flags &= ~xlat->val; + found = 1; + } + } + if (flags) { + if (found) + strcat(outstr, "|"); + sprintf(outstr + strlen(outstr), "%#x", flags); + } + + return outstr; +} + int printflags(xlat, flags, dflt) const struct xlat *xlat; -- 2.40.0