]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
API to get string descriptions of errors
authorAlan T. DeKok <aland@freeradius.org>
Sun, 31 Mar 2024 01:36:42 +0000 (21:36 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 31 Mar 2024 01:36:42 +0000 (21:36 -0400)
src/lib/bio/base.c
src/lib/bio/base.h

index dac95ef8dda3d74ff01c85c7eb63d14e0f335c1c..5dd95f1053bc436ea55b867bf4acf2efa5958108 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <freeradius-devel/bio/bio_priv.h>
 #include <freeradius-devel/bio/null.h>
+#include <freeradius-devel/util/syserror.h>
 
 #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 "<unknown>";
+       }
+}
index 7c63f522373cd9d340f230336b2e3cdf62988d0f..b3549cfb06fa84d6e66f22e90b8686ded7c8c447 100644 (file)
@@ -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);