home: hub: zuo

Download patch

ref: 616c0d990146beeaac1d83b42b75a77067291f9c
parent: c3b0c8f5dbbf0d4de4d48aa88876b1a9893714a3
author: grobe0ba <grobe0ba@tcp80.org>
date: Tue Jun 18 12:52:05 CDT 2024

9front

--- a/lib/zuo/shell.zuo
+++ b/lib/zuo/shell.zuo
@@ -14,6 +14,8 @@
      (cond
        [(eq? (hash-ref (runtime-env) 'system-type) 'unix)
         (process "/bin/sh" "-c" command options)]
+	   [(eq? (hash-ref (runtime-env) 'system-type) 'plan9)
+	    (process "/bin/ape/sh" "-c" command options)]
        [else
         (let ([cmd (build-path (hash-ref (runtime-env) 'sys-dir) "cmd.exe")])
           (process cmd (~a cmd " /c \"" command "\"") (hash-set options 'exact? #t)))]))))
--- a/zuo.c
+++ b/zuo.c
@@ -2,6 +2,16 @@
    as possible. There should be little need for forward function
    declarations. */
 
+#if defined(_PLAN9_SOURCE)
+# define _POSIX_SOURCE
+# define _BSD_EXTENSION
+# define _RESEARCH_SOURCE
+# define _POSIX_C_SOURCE
+
+#include <lib9.h>
+
+#endif
+
 #define ZUO_VERSION 1
 #define ZUO_MINOR_VERSION 10
 
@@ -26,8 +36,10 @@
 # include <time.h>
 # include <dirent.h>
 # include <signal.h>
+#if !defined(_PLAN9_SOURCE)
 # include <poll.h>
 #endif
+#endif
 #ifdef ZUO_WINDOWS
 # include <windows.h>
 # include <direct.h>
@@ -4115,6 +4127,10 @@
     type = toolchain = zuo_symbol("unix");
     ht = zuo_hash_set(ht, zuo_symbol("can-exec?"), z.o_true);
 #endif
+#ifdef _PLAN9_SOURCE
+	type = toolchain = zuo_symbol("plan9");
+	ht = zuo_hash_set(ht, zuo_symbol("can-exec?"), z.o_true);
+#endif
 #ifdef ZUO_WINDOWS
     type = zuo_symbol("windows");
 # if defined(ZUO_WINDOWS_TOOLCHAIN) || (!defined(ZUO_UNIX_TOOLCHAIN) && defined(_MSC_VER))
@@ -4592,6 +4608,7 @@
 #ifdef ZUO_UNIX
   /* loop until on of the handles is marked as done */
   {
+#if !defined(_PLAN9_SOURCE)
     zuo_int_t i;
     int ready;
 
@@ -4620,6 +4637,9 @@
       which = len;
     else
       zuo_fail1w_errno(who, "poll failed", fds_i);
+#else
+      zuo_fail1w_errno(who, "poll failed", fds_i);
+#endif
   }
 #endif
 #ifdef ZUO_WINDOWS
@@ -5061,8 +5081,13 @@
     result = zuo_hash_set(result, zuo_symbol("group-id"), zuo_integer(stat_buf.st_gid));
     result = zuo_hash_set(result, zuo_symbol("device-id-for-special-file"), zuo_integer(stat_buf.st_rdev));
     result = zuo_hash_set(result, zuo_symbol("size"), zuo_integer(stat_buf.st_size));
+# if !defined(_PLAN9_SOURCE)
     result = zuo_hash_set(result, zuo_symbol("block-size"), zuo_integer(stat_buf.st_blksize));
     result = zuo_hash_set(result, zuo_symbol("block-count"), zuo_integer(stat_buf.st_blocks));
+#else
+    result = zuo_hash_set(result, zuo_symbol("block-size"), zuo_integer(512));
+    result = zuo_hash_set(result, zuo_symbol("block-count"), zuo_integer(stat_buf.st_size/512));
+#endif
 # if defined(_POSIX_C_SOURCE)
     /* IEEE Std 1003.1-2017 has `st_atim`, etc., but even when `_POSIX_C_SOURCE` is set to request
        that, it may not be available */
@@ -5383,10 +5408,19 @@
 
     if (dest_fd == -1)
       zuo_fail1w_errno(who, "destination open failed", dest_path);
-
+#if !defined(_PLAN9_SOURCE)
     if (replace_perms)
-      if (fchmod(dest_fd, st_buf.st_mode) != 0)
+        if(fchmod(dest_fd, st_buf.st_mode) != 0)
+            zuo_fail1w_errno(who, "destination permissions update failed", dest_path);
+#else
+    if (replace_perms) {
+	  char buf[4096];
+	  if(fd2path(dest_fd, buf, 4096) != 0)
+		  zuo_fail1w_errno(who, "fd2path failed", dest_path);
+      if (chmod(buf, st_buf.st_mode) != 0)
         zuo_fail1w_errno(who, "destination permissions update failed", dest_path);
+	}
+#endif
 
     buf = malloc(4096);
 
@@ -5600,7 +5634,9 @@
 #ifdef ZUO_UNIX
   struct sigaction sa;
   sigemptyset(&sa.sa_mask);
+#if !defined(_PLAN9_SOURCE)
   sa.sa_flags = SA_RESTART;
+#endif
   sa.sa_handler = zuo_signal_received;
   sigaction(SIGINT, &sa, NULL);
 #endif