Skip to content

Commit fb91871

Browse files
ComicSansMSmichaelni
authored andcommitted
avutil/log: added av_log_format_line2 which returns buffer length
The new function behaves the same as av_log_format_line, but also forwards the return value from the underlying snprintf call. This will allow callers to accurately determine the size requirements for the line buffer. Signed-off-by: Andreas Weis <[email protected]> Signed-off-by: Michael Niedermayer <[email protected]>
1 parent 6f784c1 commit fb91871

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

doc/APIchanges

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ libavutil: 2015-08-28
1515

1616
API changes, most recent first:
1717

18+
2016-04-27 - xxxxxxx - lavu 55.23.100 - log.h
19+
Add a new function av_log_format_line2() which returns number of bytes
20+
written to the target buffer.
21+
1822
2016-xx-xx - xxxxxxx - lavc 57.37.100 - avcodec.h
1923
Add a new audio/video encoding and decoding API with decoupled input
2024
and output -- avcodec_send_packet(), avcodec_receive_frame(),

libavutil/log.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,20 @@ static void format_line(void *avcl, int level, const char *fmt, va_list vl,
283283

284284
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
285285
char *line, int line_size, int *print_prefix)
286+
{
287+
av_log_format_line2(ptr, level, fmt, vl, line, line_size, print_prefix);
288+
}
289+
290+
int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,
291+
char *line, int line_size, int *print_prefix)
286292
{
287293
AVBPrint part[4];
294+
int ret;
295+
288296
format_line(ptr, level, fmt, vl, part, print_prefix, NULL);
289-
snprintf(line, line_size, "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);
297+
ret = snprintf(line, line_size, "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);
290298
av_bprint_finalize(part+3, NULL);
299+
return ret;
291300
}
292301

293302
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)

libavutil/log.h

+17
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,23 @@ AVClassCategory av_default_get_category(void *ptr);
317317
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
318318
char *line, int line_size, int *print_prefix);
319319

320+
/**
321+
* Format a line of log the same way as the default callback.
322+
* @param line buffer to receive the formatted line;
323+
* may be NULL if line_size is 0
324+
* @param line_size size of the buffer; at most line_size-1 characters will
325+
* be written to the buffer, plus one null terminator
326+
* @param print_prefix used to store whether the prefix must be printed;
327+
* must point to a persistent integer initially set to 1
328+
* @return Returns a negative value if an error occured, otherwise returns
329+
* the number of characters that would have been written for a
330+
* sufficiently large buffer, not including the terminating null
331+
* character. If the return value is not less than line_size, it means
332+
* that the log message was truncated to fit the buffer.
333+
*/
334+
int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,
335+
char *line, int line_size, int *print_prefix);
336+
320337
#if FF_API_DLOG
321338
/**
322339
* av_dlog macros

libavutil/version.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
*/
6565

6666
#define LIBAVUTIL_VERSION_MAJOR 55
67-
#define LIBAVUTIL_VERSION_MINOR 22
68-
#define LIBAVUTIL_VERSION_MICRO 101
67+
#define LIBAVUTIL_VERSION_MINOR 23
68+
#define LIBAVUTIL_VERSION_MICRO 100
6969

7070
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
7171
LIBAVUTIL_VERSION_MINOR, \

0 commit comments

Comments
 (0)