From 24dc91907a039b7a86bf6d5b2a0a914bf1f44c3d Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 24 Jul 2017 08:07:32 +0200 Subject: common, vo_opengl: add/use helper for formatted strings on the stack Seems like I really like this C99 idiom. No reason not to generalize it do snprintf(). Introduce mp_tprintf(), which basically this idiom to snprintf(). This macro looks like it returns a string that was allocated with alloca() on the caller site, except it's portable C99/C11. (And unlike alloca(), the result is valid only within block scope.) Use it in 2 places in the vo_opengl code. But it has the potential to make a whole bunch of weird looking code look slightly nicer. --- common/common.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'common/common.c') 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; +} -- cgit v1.2.3