Newer
Older
minerva / Ports / citron / patches / 0001-Get-rid-of-wordexp-on-minerva.patch
@minerva minerva on 13 Jul 2 KB Initial commit
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ali Mohammad Pur <ali.mpfard@gmail.com>
Date: Fri, 11 Feb 2022 16:13:52 +0330
Subject: [PATCH] Get rid of wordexp on minerva

---
 src/file.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/file.c b/src/file.c
index a3bfd163f832ca52202d5acc47f1d76ba6c1ce8a..720a6e5bfb4e4512f1f6a33467096fc1991dc11b 100644
--- a/src/file.c
+++ b/src/file.c
@@ -18,11 +18,13 @@
 #include "citron.h"
 #include "siphash.h"
 #include <dirent.h>
+#ifndef __minerva__
 #include <wordexp.h>
 
 #ifndef WORDEXP_READY
 #    define WORDEXP_READY 1
 #endif
+#endif
 
 #include <termios.h>
 static struct termios oldTermios, newTermios;
@@ -461,6 +463,7 @@ ctr_object* ctr_file_rpath(ctr_object* myself, ctr_argument* argumentList)
     char rpath[PATH_MAX + 1];
     char* ret = realpath(cpath, rpath);
     if (!ret) {
+#ifndef __minerva__
         if (WORDEXP_READY) {
             wordexp_t exp_result;
             int st = wordexp(cpath, &exp_result, 0);
@@ -469,6 +472,7 @@ ctr_object* ctr_file_rpath(ctr_object* myself, ctr_argument* argumentList)
                 memset(rpath, 0, PATH_MAX);
                 memcpy(rpath, r, strlen(r));
                 wordfree(&exp_result);
+                ret = rpath;
             } else {
                 char* err;
                 switch (st) {
@@ -499,8 +503,13 @@ ctr_object* ctr_file_rpath(ctr_object* myself, ctr_argument* argumentList)
             CtrStdFlow = ctr_build_string_from_cstring(strerror(errno));
             return CtrStdNil;
         }
+#else
+        ctr_heap_free(cpath);
+        CtrStdFlow = ctr_build_string_from_cstring(strerror(errno));
+        return CtrStdNil;
+#endif
     }
-    path = ctr_build_string_from_cstring(rpath);
+    path = ctr_build_string_from_cstring(ret);
     ctr_heap_free(cpath);
     return path;
 }
@@ -515,6 +524,9 @@ ctr_object* ctr_file_expand(ctr_object* myself, ctr_argument* argumentList)
     if (argumentList->object == NULL)
         return CtrStdNil;
     ctr_object* path = ctr_internal_cast2string(argumentList->object);
+#ifdef __minerva__
+    return path;
+#else
     char* cpath = ctr_heap_allocate_cstring(path);
     wordexp_t exp_result;
     int st = wordexp(cpath, &exp_result, 0);
@@ -557,6 +569,7 @@ ctr_object* ctr_file_expand(ctr_object* myself, ctr_argument* argumentList)
         return CtrStdNil;
     }
     return arr;
+#endif
 }
 
 /**