summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-08-08 09:59:53 -0400
committerJakob Kaivo <jkk@ung.org>2019-08-08 09:59:53 -0400
commit870bc006c145aa96e0c80d5e983b52286335b8f2 (patch)
tree557474d3673d883e4000b20273a229d3e8a196b4
parentae880f1d803dd2bf4473849c4ce3860e398a4aa8 (diff)
split declarations and definitions
-rw-r--r--binary.c24
-rw-r--r--binary.h22
2 files changed, 26 insertions, 20 deletions
diff --git a/binary.c b/binary.c
new file mode 100644
index 0000000..bba7dd0
--- /dev/null
+++ b/binary.c
@@ -0,0 +1,24 @@
+#include <stdint.h>
+#include <string.h>
+
+#include "binary.h"
+
+uintmax_t binary(const char *s)
+{
+ char array[BINSTRLEN];
+ memset(array, '0', sizeof(array));
+ strcpy(array + (sizeof(array) - strlen(s)) - 1, s);
+ return BIN_FROM_ARRAY(array);
+}
+
+char *binstr(size_t n, char s[n], uintmax_t b)
+{
+ memset(s, '0', n);
+ s[n - 1] = '\0';
+ for (size_t i = 0; i < n - 2 && i < BIN_UINTMAXBITS; i++) {
+ if (b & ((uintmax_t)1 << i)) {
+ s[n - (i + 2)] = '1';
+ }
+ }
+ return s;
+}
diff --git a/binary.h b/binary.h
index 5011f64..fd1d6d8 100644
--- a/binary.h
+++ b/binary.h
@@ -1,5 +1,4 @@
#include <limits.h>
-#include <string.h>
#include <stdint.h>
#define BIN_UINTMAXBITS (sizeof(uintmax_t) * CHAR_BIT)
@@ -34,22 +33,5 @@
#define BINSTRLEN (BIN_UINTMAXBITS + 1)
#define BIN(_n) (BIN_FROM_ARRAY(#_n))
-static uintmax_t binfromstr(const char *s)
-{
- char array[BINSTRLEN];
- memset(array, '0', sizeof(array));
- strcpy(array + (sizeof(array) - strlen(s)) - 1, s);
- return BIN_FROM_ARRAY(array);
-}
-
-static char *binstr(size_t n, char s[n], uintmax_t b)
-{
- memset(s, '0', n);
- s[n - 1] = '\0';
- for (size_t i = 0; i < n - 2 && i < BIN_UINTMAXBITS; i++) {
- if (b & ((uintmax_t)1 << i)) {
- s[n - (i + 2)] = '1';
- }
- }
- return s;
-}
+uintmax_t binary(const char *s);
+char *binstr(size_t n, char s[n], uintmax_t b);