summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/common.c9
-rw-r--r--common/common.h8
2 files changed, 17 insertions, 0 deletions
diff --git a/common/common.c b/common/common.c
index eead096d5a..a07af8c461 100644
--- a/common/common.c
+++ b/common/common.c
@@ -287,3 +287,12 @@ char *mp_tag_str_buf(char *buf, size_t buf_size, uint32_t tag)
}
return buf;
}
+
+char *mp_tprintf_buf(char *buf, size_t buf_size, const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ vsnprintf(buf, buf_size, format, ap);
+ va_end(ap);
+ return buf;
+}
diff --git a/common/common.h b/common/common.h
index 4f944c99ba..fb40d251f1 100644
--- a/common/common.h
+++ b/common/common.h
@@ -101,4 +101,12 @@ char *mp_strerror_buf(char *buf, size_t buf_size, int errnum);
char *mp_tag_str_buf(char *buf, size_t buf_size, uint32_t tag);
#define mp_tag_str(t) mp_tag_str_buf((char[22]){0}, 22, t)
+// Return a printf(format, ...) formatted string of the given SIZE. SIZE must
+// be a compile time constant. The result is allocated on the stack and valid
+// only within the current block scope.
+#define mp_tprintf(SIZE, format, ...) \
+ mp_tprintf_buf((char[SIZE]){0}, (SIZE), (format), __VA_ARGS__)
+char *mp_tprintf_buf(char *buf, size_t buf_size, const char *format, ...)
+ PRINTF_ATTRIBUTE(3, 4);
+
#endif /* MPLAYER_MPCOMMON_H */