Summary Files Commits Branches @commit @diff @stats
path: root / fmt.c
diff options
context:
space:
mode:
Commit58af594c9d9cfe7070742ff09ef8528c11d65bef (patch)
Author
 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
2022-02-26 13:41:55 +0100
Committer
 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
2022-02-26 13:54:50 +0100
Files8afad723d41000fd849a4a76fec04cbecdecbfae /fmt.c
goodwolf-58af594c9d9cfe7070742ff09ef8528c11d65bef.tar
goodwolf-58af594c9d9cfe7070742ff09ef8528c11d65bef.tar.gz
goodwolf-58af594c9d9cfe7070742ff09ef8528c11d65bef.zip
Parenteceb1437726a1fae5280ec57bb35a8065996e21d (diff)
fmt: Grab fmt_context_id for tests
1 files changed, 31 insertions, 0 deletions
-rw-r--r--fmt.c31
diff --git a/fmt.c b/fmt.c
new file mode 100644
index 0000000..a88e8cb
--- /dev/null
+++ b/fmt.c
@@ -0,0 +1,31 @@
+// BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser
+// Copyright © 2019-2021 Badwolf Authors <https://hacktivis.me/projects/badwolf>
+// SPDX-License-Identifier: BSD-3-Clause
+
+#include "fmt.h"
+
+/* flawfinder: ignore. `alpha_digits` is never modified */
+static const char alpha_digits[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+void
+fmt_context_id(uint64_t num, char *out)
+{
+ /* flawfinder: ignore. bound checks are done */
+ char buf[BADWOLF_CTX_SIZ] = {0, 0, 0, 0, 0, 0, 0};
+ int len = 0;
+
+ buf[++len] = ' ';
+ buf[++len] = ':';
+
+ buf[++len] = alpha_digits[num % 26];
+ num /= 26;
+ while(num > 0 && len < (BADWOLF_CTX_SIZ - 1))
+ {
+ buf[++len] = alpha_digits[(num - 1) % 26];
+ num /= 26;
+ }
+
+ for(int i = 0; i < len; i++)
+ {
+ out[i] = buf[len - i];
+ }
+}