liblinux++

Log | Files | Refs

commit d96ae84c979ca4198154c5e4ddf44f9ab626355f
parent fef1d6a8707776fec14fada0070e678a03efeacd
Author: Henry Wilson <henry@henryandlizzy.uk>
Date:   Mon, 22 Dec 2025 20:53:28 +0000

add sleep

Diffstat:
Mlinux.hpp | 34++++++++++++++++++++++++----------
Asleep.cpp | 7+++++++
Mx86_64.s | 4++++
3 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/linux.hpp b/linux.hpp @@ -1,11 +1,21 @@ #pragma once -typedef unsigned long long size_t; -typedef signed long long ssize_t; -typedef unsigned long long uintptr_t; -typedef signed long long intptr_t; -typedef unsigned long long ino64_t; -typedef signed long long off64_t; +using uint64_t = unsigned long long; +using int64_t = signed long long; +using uint32_t = unsigned int; +using int32_t = signed int; +using uint16_t = unsigned short; +using int16_t = signed short; +using uint8_t = unsigned char; +using int8_t = signed char; + +using size_t = uint64_t; +using ssize_t = int64_t; +using uintptr_t = uint64_t; +using intptr_t = int64_t; +using ino64_t = uint64_t; +using off64_t = int64_t; +using time_t = int64_t; enum { AT_FDCWD = -100, @@ -62,9 +72,6 @@ extern "C" { extern int write(int fd, char const* data, size_t count); } 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); @@ -78,10 +85,17 @@ struct linux_dirent64 { unsigned char d_type; /* File type */ char d_name[]; /* Filename (null-terminated) */ }; -extern ssize_t getdents64(int fd, struct linux_dirent64 dirp[], size_t count); +extern ssize_t getdents64(int fd, linux_dirent64 dirp[], size_t count); extern intptr_t mmap(void* addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long off); +struct timespec { + time_t tv_sec; /* Seconds */ + uint32_t tv_nsec; /* Nanoseconds [0, 999'999'999] */ +}; + +extern int nanosleep(const timespec *duration, timespec */*_Nullable*/ rem); + static unsigned get_errno(ssize_t ret) { if (0 > ret && ret >= -0xFFFF) diff --git a/sleep.cpp b/sleep.cpp @@ -0,0 +1,7 @@ +#include "linux.hpp" + +int main() +{ + timespec duration{1, 0}; + nanosleep(&duration, nullptr); +} diff --git a/x86_64.s b/x86_64.s @@ -61,6 +61,10 @@ extern writev extern_alias _Z5writei4spanIKS_IKcEE _syscall 20 syscall3 +extern nanosleep +extern_alias _Z9nanosleepPK8timespecPS_ +_syscall 35 syscall3 + extern exit _syscall 60 syscall3