Commit 656b8d74bf399af97009cff2edcda65f887a30b2

Thomas de Grivel 2024-09-03T15:16:44

file_open_r: use buf_fd_open_r

diff --git a/env b/env
index 336b40f..5d7cb09 100644
--- a/env
+++ b/env
@@ -1,4 +1,4 @@
 export LD_LIBRARY_PATH="$PWD/libkc3/.libs:$PWD/ekc3/.libs:$PWD/http/.libs:$PWD/lib/kc3/0.1:$LD_LIBRARY_PATH"
 export KC3_HTTPD_HOST=0.0.0.0
 export KC3_HTTPD_PORT=58000
-export MALLOC_OPTIONS=CDFGJU
+#export MALLOC_OPTIONS=CDFGJU
diff --git a/libkc3/file.c b/libkc3/file.c
index 1452d23..afc5e7d 100644
--- a/libkc3/file.c
+++ b/libkc3/file.c
@@ -20,6 +20,7 @@
 #include "alloc.h"
 #include "assert.h"
 #include "buf.h"
+#include "buf_fd.h"
 #include "buf_file.h"
 #include "buf_save.h"
 #include "config.h"
@@ -255,20 +256,26 @@ FILE * file_open (const char *path, const char *mode)
 
 s_buf * file_open_r (const s_str *path, s_buf *dest)
 {
-  FILE *fp;
+  sw e;
+  sw fd;
   s_buf tmp;
   assert(path);
   assert(dest);
-  fp = file_open(path->ptr.pchar, "rb");
-  if (! fp)
+  if ((fd = open(path->ptr.pchar, O_RDONLY | O_BINARY)) < 0) {
+    e = errno;
+    err_write_1("file_open_r: ");
+    err_inspect_str(path);
+    err_write_1(": ");
+    err_puts(strerror(e));
     return NULL;
+  }
   if (! buf_init_alloc(&tmp, BUF_SIZE)) {
-    fclose(fp);
+    close(fd);
     return NULL;
   }
-  if (! buf_file_open_r(&tmp, fp)) {
+  if (! buf_fd_open_r(&tmp, fd)) {
     buf_clean(&tmp);
-    fclose(fp);
+    close(fd);
     return NULL;
   }
   *dest = tmp;