1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:38:11 +00:00

Implement errno in LibC.

This also meant I had to implement BSS (SHT_NOBITS) sections in ELFLoader.
I also added an strerror() so we can print out what the errors are.
This commit is contained in:
Andreas Kling 2018-10-25 12:06:00 +02:00
parent 434b6a8688
commit 260b14e505
14 changed files with 209 additions and 27 deletions

View file

@ -1,5 +1,6 @@
#include "unistd.h"
#include "string.h"
#include "errno.h"
#include <Kernel/Syscall.h>
extern "C" {
@ -22,35 +23,38 @@ pid_t getpid()
int open(const char* path)
{
size_t length = strlen(path);
return Syscall::invoke(Syscall::PosixOpen, (dword)path, (dword)length);
int rc = Syscall::invoke(Syscall::PosixOpen, (dword)path, (dword)length);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
ssize_t read(int fd, void* buf, size_t count)
{
return Syscall::invoke(Syscall::PosixRead, (dword)fd, (dword)buf, (dword)count);
int rc = Syscall::invoke(Syscall::PosixRead, (dword)fd, (dword)buf, (dword)count);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int close(int fd)
{
return Syscall::invoke(Syscall::PosixClose, fd);
int rc = Syscall::invoke(Syscall::PosixClose, fd);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
pid_t waitpid(pid_t waitee)
{
return Syscall::invoke(Syscall::PosixWaitpid, waitee);
int rc = Syscall::invoke(Syscall::PosixWaitpid, waitee);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int lstat(const char* path, stat* statbuf)
{
return Syscall::invoke(Syscall::PosixLstat, (dword)path, (dword)statbuf);
int rc = Syscall::invoke(Syscall::PosixLstat, (dword)path, (dword)statbuf);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
char* getcwd(char* buffer, size_t size)
{
int rc = Syscall::invoke(Syscall::PosixGetcwd, (dword)buffer, (dword)size);
if (rc != 0)
return nullptr;
return buffer;
__RETURN_WITH_ERRNO(rc, buffer, nullptr);
}
}