From 994459e4cedf5cced518820f531b75feb521bea1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 11 Jan 2016 14:35:56 +0100 Subject: common: add mp_tag_str() utility function --- common/common.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'common/common.c') diff --git a/common/common.c b/common/common.c index c943235c2a..7a651e9781 100644 --- a/common/common.c +++ b/common/common.c @@ -23,6 +23,7 @@ #include "talloc.h" #include "misc/bstr.h" +#include "misc/ctype.h" #include "common/common.h" #define appendf(ptr, ...) \ @@ -258,3 +259,19 @@ char *mp_strerror_buf(char *buf, size_t buf_size, int errnum) av_strerror(AVERROR(errnum), buf, buf_size); return buf; } + +char *mp_tag_str_buf(char *buf, size_t buf_size, uint32_t tag) +{ + if (buf_size < 1) + return buf; + buf[0] = '\0'; + for (int n = 0; n < 4; n++) { + uint8_t val = (tag >> (n * 8)) & 0xFF; + if (mp_isalnum(val) || val == '_' || val == ' ') { + mp_snprintf_cat(buf, buf_size, "%c", val); + } else { + mp_snprintf_cat(buf, buf_size, "[%d]", val); + } + } + return buf; +} -- cgit v1.2.3