From: Alan T. DeKok Date: Sun, 31 Mar 2024 01:36:42 +0000 (-0400) Subject: API to get string descriptions of errors X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8317b3207960f8c86f3df21dcaaa4d3bcefc61e;p=thirdparty%2Ffreeradius-server.git API to get string descriptions of errors --- diff --git a/src/lib/bio/base.c b/src/lib/bio/base.c index dac95ef8dda..5dd95f1053b 100644 --- a/src/lib/bio/base.c +++ b/src/lib/bio/base.c @@ -24,6 +24,7 @@ #include #include +#include #ifndef NDEBUG /** Free this bio. @@ -192,3 +193,32 @@ int fr_bio_shutdown_intermediate(fr_bio_t *bio) return fr_bio_shutdown(bio); } + +char const *fr_bio_strerror(ssize_t error) +{ + switch (error) { + case fr_bio_error(NONE): + return ""; + + case fr_bio_error(IO_WOULD_BLOCK): + return "IO operation would block"; + + case fr_bio_error(IO): + return fr_syserror(errno); + + case fr_bio_error(GENERIC): + return fr_strerror(); + + case fr_bio_error(VERIFY): + return "Packet fails verification"; + + case fr_bio_error(BUFFER_FULL): + return "Output buffer is full"; + + case fr_bio_error(BUFFER_TOO_SMALL): + return "Output buffer is too small to cache the data"; + + default: + return ""; + } +} diff --git a/src/lib/bio/base.h b/src/lib/bio/base.h index 7c63f522373..b3549cfb06f 100644 --- a/src/lib/bio/base.h +++ b/src/lib/bio/base.h @@ -186,3 +186,5 @@ int fr_bio_destructor(fr_bio_t *bio) CC_HINT(nonnull); int fr_bio_shutdown(fr_bio_t *bio) CC_HINT(nonnull); int fr_bio_free(fr_bio_t *bio) CC_HINT(nonnull); + +char const *fr_bio_strerror(ssize_t error);