[PATCH 1/3] strace: Export sprintflags function
Dmitry V. Levin
ldv at altlinux.org
Sat Sep 22 23:44:30 UTC 2007
2007-09-22 Dmitry V. Levin <ldv at altlinux.org>
* defs.h (sprintflags): New function.
* desc.c (sprintflags): Remove static qualifier, add "prefix"
argument, move function to ...
* util.c (sprintflags): ... here.
--- a/strace/defs.h
+++ b/strace/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 *));
--- a/strace/desc.c
+++ b/strace/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);
--- a/strace/util.c
+++ b/strace/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;
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20070923/87e0d497/attachment.bin>
More information about the Strace-devel
mailing list