[FFmpeg-devel] [PATCH] lavu/error: add av_make_strerr() and av_err2str() convenience utilities
Stefano Sabatini
stefasab at gmail.com
Sun Jun 10 00:20:05 CEST 2012
These functions are modeled after the corresponding utilities in
libavutil/timestamp.h.
---
libavutil/error.c | 7 ++-----
libavutil/error.h | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/libavutil/error.c b/libavutil/error.c
index 16c2587..7f08314 100644
--- a/libavutil/error.c
+++ b/libavutil/error.c
@@ -78,17 +78,14 @@ int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
int main(void)
{
int i;
- char errbuf[256];
for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
struct error_entry *entry = &error_entries[i];
- av_strerror(entry->num, errbuf, sizeof(errbuf));
- printf("%d: %s [%s]\n", entry->num, errbuf, entry->tag);
+ printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), entry->tag);
}
for (i = 0; i < 256; i++) {
- av_strerror(-i, errbuf, sizeof(errbuf));
- printf("%d: %s\n", -i, errbuf);
+ printf("%d: %s\n", -i, av_err2str(-i));
}
return 0;
diff --git a/libavutil/error.h b/libavutil/error.h
index 316734f..0f3945e 100644
--- a/libavutil/error.h
+++ b/libavutil/error.h
@@ -82,6 +82,28 @@
*/
int av_strerror(int errnum, char *errbuf, size_t errbuf_size);
+#define AV_ERROR_MAX_STRING_SIZE 64
+
+/**
+ * Fill the provided buffer with a string containing an error string
+ * representation.
+ *
+ * @param buf a buffer with size in bytes of at least AV_ERROR_MAX_STRING_SIZE
+ * @param errnum error code to describe
+ * @return the buffer in input, filled with the error description
+ */
+static inline char *av_make_strerr(char *errbuf, int errnum)
+{
+ av_strerror(errnum, errbuf, AV_ERROR_MAX_STRING_SIZE);
+ return errbuf;
+}
+
+/**
+ * Convenience macro, the return value should be used only directly in
+ * function arguments but never stand-alone.
+ */
+#define av_err2str(errnum) av_make_strerr((char[AV_ERROR_MAX_STRING_SIZE]){0}, errnum)
+
/**
* @}
*/
--
1.7.5.4
More information about the ffmpeg-devel
mailing list