file exist in kc3 and c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/lib/kc3/0.1/file.kc3 b/lib/kc3/0.1/file.kc3
new file mode 100644
index 0000000..2496ef9
--- /dev/null
+++ b/lib/kc3/0.1/file.kc3
@@ -0,0 +1,5 @@
+defmodule File do
+
+ def exists? = cfn Bool "file_exists" (Str, Result)
+
+end
diff --git a/libkc3/file.c b/libkc3/file.c
index 7129e9d..05589a2 100644
--- a/libkc3/file.c
+++ b/libkc3/file.c
@@ -14,6 +14,7 @@
#include <fcntl.h>
#include <errno.h>
#include <string.h>
+#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "buf.h"
@@ -121,6 +122,15 @@ s_str * file_dirname (const s_str *path, s_str *dest)
return str_init_slice(dest, path, 0, dirsep_pos + 1);
}
+bool * file_exists (const s_str *path, bool *dest)
+{
+ struct stat sb;
+ assert(path);
+ assert(dest);
+ *dest = ! stat(path->ptr.pchar, &sb);
+ return dest;
+}
+
s_tag * file_mtime (const s_str *path, s_tag *dest)
{
s32 e;