aboutsummaryrefslogtreecommitdiff
path: root/src/lib/lib.c
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2023-04-10 20:14:18 -0400
committerShav Kinderlehrer <[email protected]>2023-04-10 20:14:18 -0400
commit0e59c5f27cc3badd3e48a87bba39bdac9077e1a5 (patch)
treeb90c2caa254233426b326f6a38011ea15435d840 /src/lib/lib.c
parentaeafcc6891913327aa784da5879bdf9b8cf11cc4 (diff)
downloadlat-0e59c5f27cc3badd3e48a87bba39bdac9077e1a5.tar.gz
lat-0e59c5f27cc3badd3e48a87bba39bdac9077e1a5.zip
Breakup monolithic code
Diffstat (limited to 'src/lib/lib.c')
-rw-r--r--src/lib/lib.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lib/lib.c b/src/lib/lib.c
new file mode 100644
index 0000000..b358ed6
--- /dev/null
+++ b/src/lib/lib.c
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+
+void die(const char *message) {
+ perror(message);
+ exit(1);
+}
+
+char *formatBytes(unsigned bytes, float *rounded) {
+ char *SIZES[] = {"bytes", "kB", "MB", "GB"};
+
+ unsigned size = bytes;
+ unsigned div = 0;
+ unsigned rem = 0;
+
+ while (size >= 1024 && div < (sizeof SIZES / sizeof *SIZES)) {
+ rem = (size % 1024);
+ div++;
+ size /= 1024;
+ }
+
+ *rounded = (float)size + (float)rem / 1024.0;
+
+ return SIZES[div];
+}
+
+int intlen(unsigned i) {
+ int l = 1;
+
+ while (i > 9) {
+ l++;
+ i /= 10;
+ }
+
+ return l;
+}