summaryrefslogtreecommitdiff
path: root/base/base.c
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-01-28 13:13:40 +0100
committernasr <nsrddyn@gmail.com>2026-01-28 13:13:40 +0100
commit3913d1778318cd0c6bfb871148d38abb33ec7fd3 (patch)
tree917728adbf32c877ad591ad9d42f727cc7540b9b /base/base.c
parent7dead79e05e03a71a502ca4e75d05d126ff9f25c (diff)
checkpoint
Diffstat (limited to 'base/base.c')
-rw-r--r--base/base.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/base/base.c b/base/base.c
new file mode 100644
index 0000000..ba8ba32
--- /dev/null
+++ b/base/base.c
@@ -0,0 +1,69 @@
1#include "base/base.h"
2#include "stddef.h"
3
4/**
5 * Helper function to parse strings to int using ascii codes
6 * */
7local_internal u64
8parse_u64(char *buf, size_t len)
9{
10 u64 value = 0;
11
12 for (
13 size_t buffer_idx = 0;
14 buffer_idx < len;
15 ++buffer_idx)
16 {
17 char c = buf[buffer_idx];
18 if (c < '0' || c > '9')
19 {
20 break;
21 }
22 value = value * 10 + (c - '0');
23 }
24
25 return value;
26}
27
28/*
29 * is_numeric - Check if a string contains only digits
30 * @s: String to check
31 *
32 * Return: 1 if string contains only numeric characters, 0 otherwise
33 */
34local_internal b8
35is_numeric(char *s)
36{
37 for (; *s; ++s)
38 {
39 if (*s < '0' || *s > '9')
40 {
41 return 0;
42 }
43 }
44 return 1;
45}
46
47local_internal b8
48compare_string(const char *c1, const char *c2)
49{
50 if (sizeof(c1) != sizeof(c2))
51 {
52 return -1;
53 }
54
55 for (
56 u64 word_idx = 0;
57 word_idx <= sizeof(*c1);
58 ++word_idx)
59 {
60 if (*c1 != *c2)
61 {
62 return -1;
63 }
64 ++c1;
65 ++c2;
66 }
67
68 return 0;
69}