On date Sunday 2012-01-15 16:36:35 +0100, Nicolas George encoded:
Le sextidi 26 nivôse, an CCXX, Stefano Sabatini a écrit :
return ts == (AV_NOPTS_VALUE) ? snprintf(buf, buf_size, "NOPTS") : snprintf(buf, buf_size, "%"PRId64"", ts);
Note that the return value is not the room taken in the buffer but the size that the text would have used if there was enough room.
Do you think this would be a good idea? If yes, where should I put them (libavutil/printutils.h may be an option)?
As Reimer points out, I fear it would lack flexibility for some purposes. But for quick debugging it may be useful.
As a side note, I would like to share the following trick that I have used in some programs of mine:
char *foo2str_buf(char *buf, size_t buf_size, foo_t foo) { <convert> return buf; }
#define foo2str(foo) foo2str_buf((char[42]){ 0 }, 42, foo)
with 42 a constant chosen to be large enough: that way, I can write:
printf("a = %s\n", foo2str(a));
and the buffer to convert is allocated with automatic storage.
Updated based on this, with example code. -- FFmpeg = Frenzy Freak MultiPurpose Extravagant Guide