summaryrefslogtreecommitdiff
path: root/lib9p/9p.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-01-12 22:33:38 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-01-17 12:22:34 -0700
commit6381e08fd03e322d7d95973ca00c5605afb67707 (patch)
tree6ed780abe70a36f048e1638ecdc6042ea622e068 /lib9p/9p.c
parenta35db3be439c9a27f0763036cf3d4992ccf893eb (diff)
lib9p: Consolidate enum-string functions
Diffstat (limited to 'lib9p/9p.c')
-rw-r--r--lib9p/9p.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/lib9p/9p.c b/lib9p/9p.c
index ecb75fd..de6f05b 100644
--- a/lib9p/9p.c
+++ b/lib9p/9p.c
@@ -16,6 +16,25 @@
#include "internal.h"
+/* strings ********************************************************************/
+
+const char *lib9p_version_str(enum lib9p_version ver) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
+ assert(0 <= ver && ver < LIB9P_VER_NUM);
+#pragma GCC diagnostic pop
+ return _lib9p_table_ver_name[ver];
+}
+
+const char *lib9p_msgtype_str(enum lib9p_version ver, enum lib9p_msg_type typ) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
+ assert(0 <= ver && ver < LIB9P_VER_NUM);
+ assert(0 <= typ && typ <= 0xFF);
+#pragma GCC diagnostic pop
+ return _lib9p_table_msg_name[ver][typ] ?: const_byte_str(typ);
+}
+
/* ctx ************************************************************************/
void lib9p_ctx_clear_error(struct lib9p_ctx *ctx) {
@@ -67,14 +86,6 @@ int lib9p_errorf(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *fmt, .
return -1;
}
-const char *lib9p_msg_type_str(struct lib9p_ctx *ctx, enum lib9p_msg_type typ) {
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wtype-limits"
- assert(0 <= typ && typ <= 0xFF);
-#pragma GCC diagnostic pop
- return _lib9p_table_msg_name[ctx->version][typ] ?: const_byte_str(typ);
-}
-
/* main message functions *****************************************************/
static
@@ -96,11 +107,11 @@ ssize_t _lib9p_validate(uint8_t xxx_low_typ_bit,
uint8_t typ = net_bytes[4];
if (typ % 2 != xxx_low_typ_bit)
return lib9p_errorf(ctx, LINUX_EOPNOTSUPP, "%s: message_type=%s", xxx_errmsg,
- lib9p_msg_type_str(ctx, typ));
+ lib9p_msgtype_str(ctx->version, typ));
struct _lib9p_recv_tentry tentry = xxx_table[ctx->version][typ/2];
if (!tentry.validate)
return lib9p_errorf(ctx, LINUX_EOPNOTSUPP, "unknown message type: %s (protocol_version=%s)",
- lib9p_msg_type_str(ctx, typ), lib9p_version_str(ctx->version));
+ lib9p_msgtype_str(ctx->version, typ), lib9p_version_str(ctx->version));
/* Now use the message-type-specific tentry to process the whole thing. */
if (tentry.validate(&subctx))