]> granicus.if.org Git - strace/commitdiff
2007-09-22 Dmitry V. Levin <ldv@altlinux.org>
authorRoland McGrath <roland@redhat.com>
Thu, 1 Nov 2007 21:46:22 +0000 (21:46 +0000)
committerRoland McGrath <roland@redhat.com>
Thu, 1 Nov 2007 21:46:22 +0000 (21:46 +0000)
* desc.c (sprintflags): Remove static qualifier, add "prefix"
argument, move function to ...
* util.c (sprintflags): ... here.
* defs.h (sprintflags): Declare it.

defs.h
desc.c
util.c

diff --git a/defs.h b/defs.h
index a3ce867285e451b956beb051c9a875cea49d29f7..2905a33ca70689cffe34dbd9eba5bd5b3dcc01b0 100644 (file)
--- 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 4d82fa8e104e72f443a901a891e791e963332256..47aa92c8709581e4dd86768efc070f1bd9f9fe2d 100644 (file)
--- 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 7b52df4a9a76e9efee6674a14a2cae73356e1ce7..461b9dac80ffc25f9cb33d6053cda63fdcb3be6c 100644 (file)
--- 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;