commit fef1d6a8707776fec14fada0070e678a03efeacd
parent e1bb4555001f97b03a501bab39c9ad6341055161
Author: Henry Wilson <henry@henryandlizzy.uk>
Date: Mon, 22 Dec 2025 01:36:45 +0000
replace iovecc with span<char const>
Diffstat:
3 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/linux.hpp b/linux.hpp
@@ -33,24 +33,40 @@ enum {
DT_WHT = 14,
};
-struct iovecc
+template <typename T>
+struct span
{
- char const* data;
+ T* data;
size_t len;
+
+ inline span(T* p, size_t n)
+ : data{p}
+ , len{n}
+ {}
+
+ template <size_t N>
+ inline span(T (&arr)[N])
+ : span{arr, N}
+ {}
};
__attribute__((noreturn))
extern void exit(int error_code);
+extern "C" {
extern int read(int fd, char* data, size_t count);
+}
+extern int read(int fd, span<char> data);
extern "C" {
extern int write(int fd, char const* data, size_t count);
}
-extern int write(int fd, iovecc data);
+extern int write(int fd, span<char const> data);
extern ssize_t writev(int fd, struct iovecc const* iov, size_t count);
+extern ssize_t write(int fd, span<span<char const> const> data);
+
extern int openat(int fd, char const* name, int flags, int mode);
extern int close(int fd);
diff --git a/test.cpp b/test.cpp
@@ -13,7 +13,7 @@ void text()
bss[1] = 's';
bss[2] = 's';
bss[3] = '\n';
- write(1, bss, sizeof(bss));
+ write(1, bss);
}
int main()
diff --git a/x86_64.s b/x86_64.s
@@ -48,7 +48,7 @@ extern read
_syscall 0 syscall3
extern write
-extern_alias _Z5writei6iovecc
+extern_alias _Z5writei4spanIKcE
_syscall 1 syscall3
extern close
@@ -58,6 +58,7 @@ extern mmap
_syscall 9 syscall6
extern writev
+extern_alias _Z5writei4spanIKS_IKcEE
_syscall 20 syscall3
extern exit