summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-08-26 07:24:44 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-08-26 07:24:44 -0700
commit821144757386da5178193874a2df7feaf940f1a8 (patch)
tree2545916a6f9e289a7683bb59786d6996e8688fa4
parent00ce6b18a953b13954a5cad6a54bf4270c9ac275 (diff)
downloadtxr-821144757386da5178193874a2df7feaf940f1a8.tar.gz
txr-821144757386da5178193874a2df7feaf940f1a8.tar.bz2
txr-821144757386da5178193874a2df7feaf940f1a8.zip
itypes: provide a c_size function for size_t.
* itypes.[ch] (c_size): New function.
-rw-r--r--itypes.c15
-rw-r--r--itypes.h2
2 files changed, 17 insertions, 0 deletions
diff --git a/itypes.c b/itypes.c
index 76de9013..a72444e8 100644
--- a/itypes.c
+++ b/itypes.c
@@ -29,6 +29,7 @@
#include <stddef.h>
#include <wchar.h>
#include <signal.h>
+#include <stdlib.h>
#include "config.h"
#include "lib.h"
#include "signal.h"
@@ -262,3 +263,17 @@ unsigned long c_ulong(val n, val self)
#error portme
#endif
}
+
+size_t c_size(val n, val self)
+{
+ switch (sizeof (size_t)) {
+ case sizeof (unsigned):
+ return c_uint(n, self);
+#if SIZEOF_LONG != SIZEOF_INT
+ case sizeof (unsigned long):
+ return c_ulong(n, self);
+#endif
+ default:
+ abort();
+ }
+}
diff --git a/itypes.h b/itypes.h
index 35ef9c92..497486c7 100644
--- a/itypes.h
+++ b/itypes.h
@@ -117,3 +117,5 @@ unsigned int c_uint(val, val self);
long c_long(val, val self);
unsigned long c_ulong(val, val self);
+
+size_t c_size(val, val self);