aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-04-21 23:25:57 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2022-04-21 23:25:57 +0300
commit42451ed4718af3f93770feb201bd023625d69b3a (patch)
tree7f69bc86e0fc0591f176ca086db377e1cb99a718 /include
parent1a5248bb177242a34fd51efadb4af941853d5e35 (diff)
downloadkmi-42451ed4718af3f93770feb201bd023625d69b3a.tar.gz
kmi-42451ed4718af3f93770feb201bd023625d69b3a.zip
fix warnings on 32bit riscv
+ Will most probably not work on 32bit, but nice to make 'portable' code.
Diffstat (limited to 'include')
-rw-r--r--include/apos/types.h10
-rw-r--r--include/apos/utils.h14
2 files changed, 14 insertions, 10 deletions
diff --git a/include/apos/types.h b/include/apos/types.h
index 01c5317..d413957 100644
--- a/include/apos/types.h
+++ b/include/apos/types.h
@@ -37,9 +37,13 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
-/* sort of unconventional, but should be fine */
-typedef uintmax_t size_t;
-typedef intmax_t ssize_t;
+#if __SIZE_WIDTH__ == 64
+typedef uint64_t size_t;
+typedef int64_t ssize_t;
+#else
+typedef uint32_t size_t;
+typedef int32_t ssize_t;
+#endif
#define INT8_C __INT8_C
#define INT16_C __INT16_C
diff --git a/include/apos/utils.h b/include/apos/utils.h
index af0534a..1d1d6dd 100644
--- a/include/apos/utils.h
+++ b/include/apos/utils.h
@@ -28,7 +28,7 @@
#if __has_builtin(__builtin_offsetof)
#define offsetof(type, member) __builtin_offsetof(type, member)
#else
-#define offsetof(type, member) ((size_t) & ((type *)0)->member)
+#define offsetof(type, member) ((uintptr_t) & ((type *)0)->member)
#endif
#if __has_builtin(__builtin_expect)
@@ -49,12 +49,12 @@
#include <apos/types.h>
-static inline size_t align_up(size_t val, size_t a)
+static inline uintptr_t align_up(uintptr_t val, uintptr_t a)
{
if (!a)
return val;
- size_t rem = val % a;
+ uintptr_t rem = val % a;
if (rem == 0)
return val;
@@ -62,7 +62,7 @@ static inline size_t align_up(size_t val, size_t a)
return val + a - rem;
}
-static inline size_t align_down(size_t val, size_t a)
+static inline uintptr_t align_down(uintptr_t val, uintptr_t a)
{
if (!a)
return val;
@@ -70,7 +70,7 @@ static inline size_t align_down(size_t val, size_t a)
return val - (val % a);
}
-static inline bool aligned(size_t val, size_t a)
+static inline bool aligned(uintmax_t val, uintmax_t a)
{
if (!a)
return true;
@@ -78,7 +78,7 @@ static inline bool aligned(size_t val, size_t a)
return val % a == 0;
}
-static inline size_t asciinum(char c)
+static inline int asciinum(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
@@ -90,7 +90,7 @@ static inline size_t asciinum(char c)
return 0;
}
-static inline size_t convnum(const char *c, size_t len, size_t base)
+static inline uintmax_t convnum(const char *c, size_t len, size_t base)
{
size_t multiplier = 1;
size_t sum = 0;