Commit 01c8e735d89c8e53d32dd1e72e083d96c5ff963a

Thomas de Grivel 2024-08-08T17:43:00

kc3_errno, kc3_strerror

diff --git a/libkc3/abs.h b/libkc3/abs.h
index 185f939..5ce4ab4 100644
--- a/libkc3/abs.h
+++ b/libkc3/abs.h
@@ -16,8 +16,8 @@
  *
  * Functions that return the absolute value of a number.
  */
-#ifndef LIBC3_ABS_H
-#define LIBC3_ABS_H
+#ifndef LIBKC3_ABS_H
+#define LIBKC3_ABS_H
 
 #include "types.h"
 
@@ -35,4 +35,4 @@ DEF_ABS_PROTOTYPE(u32);
 DEF_ABS_PROTOTYPE(u64);
 DEF_ABS_PROTOTYPE(uw);
 
-#endif /* LIBC3_ABS_H */
+#endif /* LIBKC3_ABS_H */
diff --git a/libkc3/kc3.c b/libkc3/kc3.c
index 0f193dc..acf658e 100644
--- a/libkc3/kc3.c
+++ b/libkc3/kc3.c
@@ -11,8 +11,10 @@
  * THIS SOFTWARE.
  */
 #include <dlfcn.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include "assert.h"
 #include "bool.h"
 #include "buf.h"
@@ -136,6 +138,11 @@ void ** kc3_dlopen (const s_str *path, void **dest)
   return dest;
 }
 
+sw kc3_errno (void)
+{
+  return errno;
+}
+
 void kc3_exit (sw code)
 {
   exit((int) code);
@@ -289,6 +296,13 @@ s_str * kc3_str (const s_tag *tag, s_str *dest)
   }
 }
 
+s_str * kc3_strerror (sw err_no, s_str *dest)
+{
+  const char *s;
+  s = strerror(err_no);
+  return str_init_1_alloc(dest, s);
+}
+
 s_tag * kc3_while (const s_tag *cond, const s_tag *body, s_tag *dest)
 {
   return env_while(&g_kc3_env, cond, body, dest);
diff --git a/libkc3/kc3_main.h b/libkc3/kc3_main.h
index ccde0fb..2cafe45 100644
--- a/libkc3/kc3_main.h
+++ b/libkc3/kc3_main.h
@@ -50,10 +50,12 @@ s_tag * kc3_defoperator (const s_sym **name, const s_sym **sym,
                          s_tag *dest);
 s_tag * kc3_defstruct (const s_list * const *spec, s_tag *dest);
 void ** kc3_dlopen (const s_str *path, void **dest);
+sw      kc3_errno (void);
 void    kc3_exit (sw code);
 bool    kc3_load (const s_str *path);
 s_tag * kc3_pin (const s_tag *a, s_tag *dest);
 bool    kc3_require (const s_sym * const *module);
+s_str * kc3_strerror (sw err_no, s_str *dest);
 
 /* Special operators. */
 s_tag * kc3_if_then_else (const s_tag *cond, const s_tag *then,