xref: /netbsd-src/external/bsd/ntp/dist/libntp/modetoa.c (revision eabc0478de71e4e011a5b4e0392741e01d491794)
1*eabc0478Schristos /*	$NetBSD: modetoa.c,v 1.10 2024/08/18 20:47:13 christos Exp $	*/
2abb0f93cSkardel 
3abb0f93cSkardel /*
4abb0f93cSkardel  * modetoa - return an asciized mode
5abb0f93cSkardel  */
62950cc38Schristos #include <config.h>
7abb0f93cSkardel #include <stdio.h>
8abb0f93cSkardel 
9abb0f93cSkardel #include "ntp_stdlib.h"
10abb0f93cSkardel 
11abb0f93cSkardel const char *
12abb0f93cSkardel modetoa(
13e19314b7Schristos 	size_t mode
14abb0f93cSkardel 	)
15abb0f93cSkardel {
16abb0f93cSkardel 	char *bp;
172950cc38Schristos 	static const char * const modestrings[] = {
18abb0f93cSkardel 		"unspec",
19abb0f93cSkardel 		"sym_active",
20abb0f93cSkardel 		"sym_passive",
21abb0f93cSkardel 		"client",
22abb0f93cSkardel 		"server",
23abb0f93cSkardel 		"broadcast",
24abb0f93cSkardel 		"control",
25abb0f93cSkardel 		"private",
26abb0f93cSkardel 		"bclient",
27abb0f93cSkardel 	};
28abb0f93cSkardel 
293123f114Skardel 	if (mode >= COUNTOF(modestrings)) {
30abb0f93cSkardel 		LIB_GETBUF(bp);
313123f114Skardel 		snprintf(bp, LIB_BUFLENGTH, "mode#%zu", mode);
32abb0f93cSkardel 		return bp;
33abb0f93cSkardel 	}
34abb0f93cSkardel 
35abb0f93cSkardel 	return modestrings[mode];
36abb0f93cSkardel }
37