diff options
author | Theodore Ts'o <tytso@mit.edu> | 2020-03-20 17:57:38 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2020-03-20 17:57:38 -0400 |
commit | 96d5cc74ec9fb1e5feb4bea0871c6dc2010abe8d (patch) | |
tree | a09b6cbc3122548e8202254310cefeb859df51fd | |
parent | 23c6ef3de362aa291a15cc21a8a82a534a785fde (diff) | |
download | e2fsprogs-96d5cc74ec9fb1e5feb4bea0871c6dc2010abe8d.tar.gz |
libe2p: add a thread-safe variant of e2p_feature2string
This commit adds the function e2p_feature_to_string() which allows the
caller to pass in a preallocated buffer.
Google-Bug-Id: 16978603
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r-- | lib/e2p/e2p.h | 2 | ||||
-rw-r--r-- | lib/e2p/feature.c | 18 |
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/e2p/e2p.h b/lib/e2p/e2p.h index c3a6b2587..ae7dd74dd 100644 --- a/lib/e2p/e2p.h +++ b/lib/e2p/e2p.h @@ -50,6 +50,8 @@ int setversion (int fd, unsigned long version); void e2p_list_journal_super(FILE *f, char *journal_sb_buf, int exp_block_size, int flags); +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 ae7f7f0aa..515a0f881 100644 --- a/lib/e2p/feature.c +++ b/lib/e2p/feature.c @@ -135,17 +135,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: @@ -163,6 +166,13 @@ const char *e2p_feature2string(int compat, unsigned int mask) } for (fnum = 0; mask >>= 1; fnum++); sprintf(buf, "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; } |