linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Patch adding e2p_feature_to_string
@ 2014-12-17 19:27 👾 Wade
  2014-12-17 20:30 ` Andreas Dilger
  0 siblings, 1 reply; 7+ messages in thread
From: 👾 Wade @ 2014-12-17 19:27 UTC (permalink / raw)
  To: linux-ext4

This is needed to provide a version of e2p_feature2string that doesn't
use (and return a pointer to) an internal, static buffer.

diff --git a/lib/e2p/e2p.h b/lib/e2p/e2p.h
index 5fa41f4..53f0183 100644
--- a/lib/e2p/e2p.h
+++ b/lib/e2p/e2p.h
@@ -45,6 +45,8 @@ void print_fs_state (FILE * f, unsigned short state);
 int setflags (int fd, unsigned long flags);
 int setversion (int fd, unsigned long version);

+void e2p_feature_to_string(int compat, unsigned int mask, char *buf,
+                          size_t buf_len);
 const char *e2p_feature2string(int compat, unsigned int mask);
 const char *e2p_jrnl_feature2string(int compat, unsigned int mask);
 int e2p_string2feature(char *string, int *compat, unsigned int *mask);
diff --git a/lib/e2p/feature.c b/lib/e2p/feature.c
index 6e53cfe..6dca315 100644
--- a/lib/e2p/feature.c
+++ b/lib/e2p/feature.c
@@ -117,17 +117,20 @@ static struct feature jrnl_feature_list[] = {
        {       0, 0, 0 },
 };

-const char *e2p_feature2string(int compat, unsigned int mask)
+void e2p_feature_to_string(int compat, unsigned int mask, char *buf,
+                           size_t buf_len)
 {
        struct feature  *f;
-       static char buf[20];
        char    fchar;
        int     fnum;

        for (f = feature_list; f->string; f++) {
                if ((compat == f->compat) &&
-                   (mask == f->mask))
-                       return f->string;
+                   (mask == f->mask)) {
+                       strncpy(buf, f->string, buf_len);
+                       buf[buf_len - 1] = 0;
+                       return;
+                }
        }
        switch (compat) {
        case  E2P_FEATURE_COMPAT:
@@ -144,7 +147,13 @@ const char *e2p_feature2string(int compat,
unsigned int mask)
                break;
        }
        for (fnum = 0; mask >>= 1; fnum++);
-       sprintf(buf, "FEATURE_%c%d", fchar, fnum);
+       snprintf(buf, buf_len, "FEATURE_%c%d", fchar, fnum);
+}
+
+const char *e2p_feature2string(int compat, unsigned int mask)
+{
+       static char buf[20];
+       e2p_feature_to_string(compat, mask, buf, sizeof(buf) / sizeof(buf[0]));
        return buf;
 }

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-12-19  3:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-17 19:27 Patch adding e2p_feature_to_string 👾 Wade
2014-12-17 20:30 ` Andreas Dilger
2014-12-18  0:03   ` 👾 Wade
2014-12-18  5:24     ` Andreas Dilger
2014-12-18 18:23       ` 👾 Wade
2014-12-18 21:58         ` Andreas Dilger
2014-12-19  3:21           ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).