ref: 84fa11317ae6dafc90f72b330447c188ca00d462
parent: 3d986fe3addb1fe33acba63693c00766dbbf3d33
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Jan 5 14:37:54 EST 2025
ios_trunc: add support for Plan 9 References: https://todo.sr.ht/~ft/femtolisp/37
--- a/ios.c
+++ b/ios.c
@@ -484,11 +484,7 @@
s->size = size;
return 0;
}
-#if defined(__plan9__)
- return -1;
-#else
return ios_flush(s) == 0 ? ftruncate(s->fd, size) : -1;
-#endif
}
bool
--- a/plan9/platform.h
+++ b/plan9/platform.h
@@ -145,3 +145,4 @@
typedef enum { false, true } bool;
int wcwidth(Rune c);
+int ftruncate(int f, off_t sz);
--- a/sys_plan9.c
+++ b/sys_plan9.c
@@ -67,6 +67,16 @@
sleep(ms);
}
+int
+ftruncate(int f, off_t sz)
+{
+ Dir d;
+
+ nulldir(&d);
+ d.length = sz;
+ return dirfwstat(f, &d) > 0 ? 0 : -1;
+}
+
extern uchar bootcode[];
extern ulong bootlen;