[FFmpeg-devel] [PATCH] Implement av_strerror()
Måns Rullgård
mans
Sun Mar 14 16:52:41 CET 2010
Stefano Sabatini <stefano.sabatini-lala at poste.it> writes:
> On date Sunday 2010-03-14 14:16:17 +0100, Michael Niedermayer encoded:
>> On Sun, Mar 14, 2010 at 01:03:58PM +0100, Stefano Sabatini wrote:
> [...]
>> > +int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
>> > +{
>> > + int ret = 0;
>> > +
>> > + switch (errnum) {
>> > +#define HANDLE_ERROR(ERR, ERRSTR) case AVERROR_##ERR: av_strlcpy(errbuf, ERRSTR, errbuf_size); break
>> > +
>> > +#if LIBAVUTIL_VERSION_MAJOR < 51
>> > + HANDLE_ERROR(IO , "I/O error");
>> > + HANDLE_ERROR(NOENT , "No such file or directory");
>> > + HANDLE_ERROR(NOMEM , "Not enough memory");
>> > +#endif
>> > + HANDLE_ERROR(EOF , "End of file");
>> > + HANDLE_ERROR(INVALIDDATA , "Invalid data found");
>> > + HANDLE_ERROR(NOFMT , "Unknown format");
>> > + HANDLE_ERROR(NOTSUPP , "Operation not supported");
>> > + HANDLE_ERROR(NUMEXPECTED , "Number syntax expected in filename");
>> > + HANDLE_ERROR(PATCHWELCOME , "Not yet implemented in FFmpeg, patches welcome");
>>
>> case X: s= "kjfdkfjhfkjh"; break;
>> ...
>>
>> av_strlcpy(s)
>
> Updated, I have a small preference for keeping the macro but I'll
> remove that if you don't like it.
>
> Regards.
> --
> FFmpeg = Furious and Free Monstrous Peaceless Extended Gigant
>
> From 462a236c4d244f426e35eb3f0dda34ce4356ce32 Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> Date: Sun, 14 Mar 2010 01:06:46 +0100
> Subject: [PATCH 7/8] Implement av_strerror().
>
> ---
> libavutil/Makefile | 1 +
> libavutil/avutil.h | 2 +-
> libavutil/error.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> libavutil/error.h | 11 ++++++++++
> 4 files changed, 68 insertions(+), 1 deletions(-)
> create mode 100644 libavutil/error.c
>
> [...]
>
> +int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
> +{
> + int ret = 0;
> + const char *errstr = NULL;
> +
> + switch (errnum) {
> +#define HANDLE_ERROR(ERR, ERRSTR) case AVERROR_##ERR: errstr = ERRSTR; break
> +
> +#if LIBAVUTIL_VERSION_MAJOR < 51
> + HANDLE_ERROR(IO , "I/O error");
> + HANDLE_ERROR(NOENT , "No such file or directory");
> + HANDLE_ERROR(NOMEM , "Not enough memory");
> +#endif
> + HANDLE_ERROR(EOF , "End of file");
> + HANDLE_ERROR(INVALIDDATA , "Invalid data found");
> + HANDLE_ERROR(NOFMT , "Unknown format");
> + HANDLE_ERROR(NOTSUPP , "Operation not supported");
> + HANDLE_ERROR(NUMEXPECTED , "Number syntax expected in filename");
> + HANDLE_ERROR(PATCHWELCOME , "Not yet implemented in FFmpeg, patches welcome");
> + }
Please drop the macro. It only obfuscates.
> + if (errstr) {
> + av_strlcatf(errbuf, errbuf_size, errstr);
av_strlcpy()
> + } else {
> +#if _POSIX_C_SOURCE >= 200112L
> + ret = strerror_r(AVUNERROR(errnum), errbuf, errbuf_size);
> +#else
> + av_strlcatf(errbuf, errbuf_size, "Error number %d", errnum);
> +#endif
This is wrong for two reasons:
1. We define _POSIX_C_SOURCE to 200112.
2. strerror_r() is optional.
The correct solution is to check_func it in configure.
--
M?ns Rullg?rd
mans at mansr.com
More information about the ffmpeg-devel
mailing list