1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Replace Maxsi::Error:: with <errno.h>.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-09-22 16:44:50 +02:00
parent 42754f1728
commit 5d082b3bbb
32 changed files with 234 additions and 298 deletions

View file

@ -1079,12 +1079,11 @@ char* GetCurrentVideoMode()
// TODO: This should be in libc and not use libmaxsi. // TODO: This should be in libc and not use libmaxsi.
#include <libmaxsi/platform.h> #include <libmaxsi/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
using namespace Maxsi; using namespace Maxsi;
bool ReadParamString(const char* str, ...) extern "C" bool ReadParamString(const char* str, ...)
{ {
if ( String::Seek(str, '\n') ) { Error::Set(EINVAL); } if ( String::Seek(str, '\n') ) { errno = EINVAL; }
const char* keyname; const char* keyname;
va_list args; va_list args;
while ( *str ) while ( *str )
@ -1092,9 +1091,9 @@ bool ReadParamString(const char* str, ...)
size_t varlen = String::Reject(str, ","); size_t varlen = String::Reject(str, ",");
if ( !varlen ) { str++; continue; } if ( !varlen ) { str++; continue; }
size_t namelen = String::Reject(str, "="); size_t namelen = String::Reject(str, "=");
if ( !namelen ) { Error::Set(EINVAL); goto cleanup; } if ( !namelen ) { errno = EINVAL; goto cleanup; }
if ( !str[namelen] ) { Error::Set(EINVAL); goto cleanup; } if ( !str[namelen] ) { errno = EINVAL; goto cleanup; }
if ( varlen < namelen ) { Error::Set(EINVAL); goto cleanup; } if ( varlen < namelen ) { errno = EINVAL; goto cleanup; }
size_t valuelen = varlen - 1 /*=*/ - namelen; size_t valuelen = varlen - 1 /*=*/ - namelen;
char* name = String::Substring(str, 0, namelen); char* name = String::Substring(str, 0, namelen);
if ( !name ) { goto cleanup; } if ( !name ) { goto cleanup; }

View file

@ -1,4 +1,4 @@
/****************************************************************************** /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
@ -11,8 +11,8 @@
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
more details. details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>. along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
@ -23,15 +23,12 @@
*******************************************************************************/ *******************************************************************************/
#define __SORTIX_STDLIB_REDIRECTS 0 #define __SORTIX_STDLIB_REDIRECTS 0
#include <libmaxsi/platform.h> #include <errno.h>
#include <libmaxsi/error.h> #include <stddef.h>
#ifndef SORTIX_KERNEL #ifndef SORTIX_KERNEL
#include <stdio.h> #include <stdio.h>
#endif #endif
namespace Maxsi {
namespace Error {
extern "C" { int global_errno = 0; } extern "C" { int global_errno = 0; }
extern "C" { errno_location_func_t errno_location_func = NULL; } extern "C" { errno_location_func_t errno_location_func = NULL; }
@ -102,6 +99,3 @@ extern "C" char* strerror(int errnum)
{ {
return (char*) sortix_strerror(errnum); return (char*) sortix_strerror(errnum);
} }
} // namespace Error
} // namespace Maxsi

View file

@ -25,7 +25,6 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <libmaxsi/platform.h> #include <libmaxsi/platform.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <libmaxsi/error.h>
#ifdef SORTIX_KERNEL #ifdef SORTIX_KERNEL
#define HEAP_GROWS_DOWNWARDS #define HEAP_GROWS_DOWNWARDS
@ -38,6 +37,7 @@
#endif #endif
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <malloc.h> #include <malloc.h>
#define PARANOIA 1 #define PARANOIA 1
@ -454,7 +454,7 @@ namespace Maxsi
// TODO: Overflow MAY happen here! // TODO: Overflow MAY happen here!
if ( heapmaxsize <= heapsize + wildernesssize + bytesneeded ) if ( heapmaxsize <= heapsize + wildernesssize + bytesneeded )
{ {
Error::Set(ENOMEM); errno = ENOMEM;
return true; return true;
} }
@ -554,7 +554,7 @@ namespace Maxsi
// Check if the wilderness can meet our requirements. // Check if the wilderness can meet our requirements.
if ( wildernesssize < size && !ExpandWilderness(size) ) if ( wildernesssize < size && !ExpandWilderness(size) )
{ {
Error::Set(ENOMEM); errno = ENOMEM;
return NULL; return NULL;
} }

View file

@ -1,54 +0,0 @@
/******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
This file is part of LibMaxsi.
LibMaxsi is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details.
You should have received a copy of the GNU Lesser General Public License
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
error.h
Error reporting functions and utilities.
******************************************************************************/
#ifndef LIBMAXSI_ERROR_H
#define LIBMAXSI_ERROR_H
extern "C"
{
@include(errno_decl.h);
@include(errno_values.h)
}
namespace Maxsi
{
namespace Error
{
inline int Last() { return errno; }
inline void Set(int error) { errno = error; }
inline int* GetErrnoLocation()
{
return get_errno_location();
}
inline void SetErrnoLocationFunc(errno_location_func_t func)
{
set_errno_location_func(func);
}
}
}
#endif

View file

@ -24,7 +24,6 @@
#include <libmaxsi/platform.h> #include <libmaxsi/platform.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <libmaxsi/error.h>
#ifndef SORTIX_KERNEL #ifndef SORTIX_KERNEL
#include <sys/syscall.h> #include <sys/syscall.h>
#endif #endif

View file

@ -23,15 +23,15 @@
*******************************************************************************/ *******************************************************************************/
#include <libmaxsi/platform.h> #include <libmaxsi/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <errno.h>
#include <readparamstring.h> #include <readparamstring.h>
using namespace Maxsi; using namespace Maxsi;
extern "C" bool ReadParamString(const char* str, ...) extern "C" bool ReadParamString(const char* str, ...)
{ {
if ( String::Seek(str, '\n') ) { Error::Set(EINVAL); } if ( String::Seek(str, '\n') ) { errno = EINVAL; }
const char* keyname; const char* keyname;
va_list args; va_list args;
while ( *str ) while ( *str )
@ -39,9 +39,9 @@ extern "C" bool ReadParamString(const char* str, ...)
size_t varlen = String::Reject(str, ","); size_t varlen = String::Reject(str, ",");
if ( !varlen ) { str++; continue; } if ( !varlen ) { str++; continue; }
size_t namelen = String::Reject(str, "="); size_t namelen = String::Reject(str, "=");
if ( !namelen ) { Error::Set(EINVAL); goto cleanup; } if ( !namelen ) { errno = EINVAL; goto cleanup; }
if ( !str[namelen] ) { Error::Set(EINVAL); goto cleanup; } if ( !str[namelen] ) { errno = EINVAL; goto cleanup; }
if ( varlen < namelen ) { Error::Set(EINVAL); goto cleanup; } if ( varlen < namelen ) { errno = EINVAL; goto cleanup; }
size_t valuelen = varlen - 1 /*=*/ - namelen; size_t valuelen = varlen - 1 /*=*/ - namelen;
char* name = String::Substring(str, 0, namelen); char* name = String::Substring(str, 0, namelen);
if ( !name ) { goto cleanup; } if ( !name ) { goto cleanup; }

View file

@ -25,8 +25,8 @@
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <sortix/kernel/kthread.h> #include <sortix/kernel/kthread.h>
#include "cpu.h" #include "cpu.h"
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <errno.h>
#include "ata.h" #include "ata.h"
#include "fs/devfs.h" #include "fs/devfs.h"
@ -93,7 +93,7 @@ namespace Sortix
// Detect if there is no such bus. // Detect if there is no such bus.
if ( status == 0xFF ) if ( status == 0xFF )
{ {
Error::Set(ENODEV); errno = ENODEV;
return NULL; return NULL;
} }
return new ATABus(portoffset, altport); return new ATABus(portoffset, altport);
@ -119,7 +119,7 @@ namespace Sortix
ATADrive* ATABus::Instatiate(unsigned driveid) ATADrive* ATABus::Instatiate(unsigned driveid)
{ {
if ( 1 < driveid ) { Error::Set(EINVAL); return false; } if ( 1 < driveid ) { errno = EINVAL; return false; }
curdriveid = 0; curdriveid = 0;
uint8_t drivemagic = 0xA0 | (driveid << 4); uint8_t drivemagic = 0xA0 | (driveid << 4);
@ -133,12 +133,12 @@ namespace Sortix
while ( true ) while ( true )
{ {
status = CPU::InPortB(iobase + STATUS); status = CPU::InPortB(iobase + STATUS);
if ( !status || status == 0xFF ) { Error::Set(ENODEV); return false; } if ( !status || status == 0xFF ) { errno = ENODEV; return false; }
if ( !(status & STATUS_BUSY) ) { break; } if ( !(status & STATUS_BUSY) ) { break; }
} }
if ( CPU::InPortB(iobase + LBA_MID) || CPU::InPortB(iobase + LBA_MID) ) if ( CPU::InPortB(iobase + LBA_MID) || CPU::InPortB(iobase + LBA_MID) )
{ {
Error::Set(ENODEV); return false; // ATAPI device not following spec. errno = ENODEV; return false; // ATAPI device not following spec.
} }
while ( !(status & STATUS_DATAREADY) && !(status & STATUS_ERROR) ) while ( !(status & STATUS_DATAREADY) && !(status & STATUS_ERROR) )
{ {
@ -164,7 +164,7 @@ namespace Sortix
{ {
//Log::PrintF("Error status during identify\n"); //Log::PrintF("Error status during identify\n");
} }
Error::Set(EIO); errno = EIO;
return false; return false;
} }
ATADrive* drive = new ATADrive(this, driveid, iobase, altport); ATADrive* drive = new ATADrive(this, driveid, iobase, altport);
@ -174,7 +174,7 @@ namespace Sortix
bool ATABus::SelectDrive(unsigned driveid) bool ATABus::SelectDrive(unsigned driveid)
{ {
if ( driveid == curdriveid ) { return true; } if ( driveid == curdriveid ) { return true; }
if ( 1 < driveid ) { Error::Set(EINVAL); return false; } if ( 1 < driveid ) { errno = EINVAL; return false; }
uint8_t drivemagic = 0xA0 | (driveid << 4); uint8_t drivemagic = 0xA0 | (driveid << 4);
CPU::OutPortB(iobase + DRIVE_SELECT, drivemagic); CPU::OutPortB(iobase + DRIVE_SELECT, drivemagic);
@ -227,10 +227,10 @@ namespace Sortix
bool ATADrive::PrepareIO(bool write, off_t sector) bool ATADrive::PrepareIO(bool write, off_t sector)
{ {
if ( numsectors <= sector ) { Error::Set(EINVAL); return false; } if ( numsectors <= sector ) { errno = EINVAL; return false; }
if ( write && !ENABLE_DISKWRITE ) if ( write && !ENABLE_DISKWRITE )
{ {
Error::Set(EPERM); errno = EPERM;
return false; return false;
} }
bus->SelectDrive(driveid); bus->SelectDrive(driveid);
@ -260,8 +260,8 @@ namespace Sortix
uint8_t status = CPU::InPortB(iobase + STATUS); uint8_t status = CPU::InPortB(iobase + STATUS);
if ( status & STATUS_BUSY ) { continue; } if ( status & STATUS_BUSY ) { continue; }
if ( status & STATUS_DATAREADY ) { break; } if ( status & STATUS_DATAREADY ) { break; }
if ( status & STATUS_ERROR ) { Error::Set(EIO); return false; } if ( status & STATUS_ERROR ) { errno = EIO; return false; }
if ( status & STATUS_DRIVEFAULT ) { Error::Set(EIO); return false; } if ( status & STATUS_DRIVEFAULT ) { errno = EIO; return false; }
} }
return true; return true;
} }
@ -294,8 +294,8 @@ namespace Sortix
while ( true ) while ( true )
{ {
uint8_t status = CPU::InPortB(iobase + STATUS); uint8_t status = CPU::InPortB(iobase + STATUS);
if ( status & STATUS_ERROR ) { Error::Set(EIO); return false; } if ( status & STATUS_ERROR ) { errno = EIO; return false; }
if ( status & STATUS_DRIVEFAULT ) { Error::Set(EIO); return false; } if ( status & STATUS_DRIVEFAULT ) { errno = EIO; return false; }
if ( !(status & STATUS_BUSY) ) { break; } if ( !(status & STATUS_BUSY) ) { break; }
} }
return true; return true;

View file

@ -29,9 +29,9 @@
#include <sortix/kernel/memorymanagement.h> #include <sortix/kernel/memorymanagement.h>
#include <sortix/kernel/pci.h> #include <sortix/kernel/pci.h>
#include <sortix/mman.h> #include <sortix/mman.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <errno.h>
#include "x86-family/memorymanagement.h" #include "x86-family/memorymanagement.h"
#include "lfbtextbuffer.h" #include "lfbtextbuffer.h"
#include "cpu.h" #include "cpu.h"
@ -287,7 +287,7 @@ bool BGADriver::ShutDown()
if ( curmode ) if ( curmode )
{ {
delete[] curmode; curmode = NULL; delete[] curmode; curmode = NULL;
Error::Set(ENOSYS); errno = ENOSYS;
return false; // TODO: Return to VGA Text Mode. return false; // TODO: Return to VGA Text Mode.
} }
return true; return true;
@ -295,7 +295,7 @@ bool BGADriver::ShutDown()
char* BGADriver::GetCurrentMode() const char* BGADriver::GetCurrentMode() const
{ {
if ( !curmode ) { Error::Set(EINVAL); return NULL; } if ( !curmode ) { errno = EINVAL; return NULL; }
return String::Clone(curmode); return String::Clone(curmode);
} }

View file

@ -24,7 +24,7 @@
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <sortix/kernel/kthread.h> #include <sortix/kernel/kthread.h>
#include <libmaxsi/error.h> #include <errno.h>
#include "interrupt.h" #include "interrupt.h"
#include "stream.h" #include "stream.h"
#include "syscall.h" #include "syscall.h"
@ -268,7 +268,7 @@ ssize_t DevCOMPort::Read(uint8_t* dest, size_t count)
while ( !(CPU::InPortB(port + LSR) & LSR_READY) ) while ( !(CPU::InPortB(port + LSR) & LSR_READY) )
if ( Signal::IsPending() ) if ( Signal::IsPending() )
{ {
Error::Set(EINTR); errno = EINTR;
return -1; return -1;
} }
#else #else
@ -282,9 +282,9 @@ ssize_t DevCOMPort::Read(uint8_t* dest, size_t count)
if ( !(lsr & LSR_READY) ) if ( !(lsr & LSR_READY) )
{ {
#if POLL_EAGAIN #if POLL_EAGAIN
Error::Set(EAGAIN); errno = EAGAIN;
#else #else
Error::Set(EBLOCKING); errno = EBLOCKING;
Syscall::Yield(); Syscall::Yield();
#endif #endif
return -1; return -1;
@ -312,7 +312,7 @@ ssize_t DevCOMPort::Write(const uint8_t* src, size_t count)
while ( !(CPU::InPortB(port + LSR) & LSR_THRE) ) while ( !(CPU::InPortB(port + LSR) & LSR_THRE) )
if ( Signal::IsPending() ) if ( Signal::IsPending() )
{ {
Error::Set(EINTR); errno = EINTR;
return -1; return -1;
} }
#else #else
@ -326,9 +326,9 @@ ssize_t DevCOMPort::Write(const uint8_t* src, size_t count)
if ( !(lsr & LSR_THRE) ) if ( !(lsr & LSR_THRE) )
{ {
#if POLL_EAGAIN #if POLL_EAGAIN
Error::Set(EAGAIN); errno = EAGAIN;
#else #else
Error::Set(EBLOCKING); errno = EBLOCKING;
Syscall::Yield(); Syscall::Yield();
#endif #endif
return -1; return -1;
@ -362,7 +362,7 @@ ssize_t DevCOMPort::Read(uint8_t* dest, size_t count)
#else #else
dataevent.Register(); dataevent.Register();
#endif #endif
Error::Set(EBLOCKING); errno = EBLOCKING;
return -1; return -1;
} }
@ -391,7 +391,7 @@ ssize_t DevCOMPort::Write(const uint8_t* src, size_t count)
#else #else
sentevent.Register(); sentevent.Register();
#endif #endif
Error::Set(EBLOCKING); errno = EBLOCKING;
return -1; return -1;
} }

View file

@ -23,10 +23,10 @@
******************************************************************************/ ******************************************************************************/
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "syscall.h" #include "syscall.h"
#include "process.h" #include "process.h"
#include "device.h" #include "device.h"
@ -44,8 +44,8 @@ namespace Sortix
{ {
Process* process = CurrentProcess(); Process* process = CurrentProcess();
Device* dev = process->descriptors.Get(fd); Device* dev = process->descriptors.Get(fd);
if ( !dev ) { Error::Set(EBADF); return -1; } if ( !dev ) { errno = EBADF; return -1; }
if ( !dev->IsType(Device::DIRECTORY) ) { Error::Set(EBADF); return -1; } if ( !dev->IsType(Device::DIRECTORY) ) { errno = EBADF; return -1; }
DevDirectory* dir = (DevDirectory*) dev; DevDirectory* dir = (DevDirectory*) dev;
sortix_dirent* prev = NULL; sortix_dirent* prev = NULL;
@ -57,7 +57,7 @@ namespace Sortix
if ( size < sizeof(sortix_dirent) ) if ( size < sizeof(sortix_dirent) )
{ {
if ( prev ) { return 0; } // We did some work. if ( prev ) { return 0; } // We did some work.
Error::Set(EINVAL); // Nope, userspace was cheap. errno = EINVAL; // Nope, userspace was cheap.
return -1; return -1;
} }
@ -94,7 +94,7 @@ namespace Sortix
Process* process = CurrentProcess(); Process* process = CurrentProcess();
const char* wd = process->workingdir; const char* wd = process->workingdir;
char* abs = MakeAbsolute(wd, path); char* abs = MakeAbsolute(wd, path);
if ( !abs ) { Error::Set(ENOMEM); return -1; } if ( !abs ) { errno = ENOMEM; return -1; }
size_t abslen = String::Length(abs); size_t abslen = String::Length(abs);
if ( 1 < abslen && abs[abslen-1] == '/' ) if ( 1 < abslen && abs[abslen-1] == '/' )
{ {
@ -104,9 +104,9 @@ namespace Sortix
// Lookup the path and see if it is a directory. // Lookup the path and see if it is a directory.
size_t pathoffset = 0; size_t pathoffset = 0;
DevFileSystem* fs = Mount::WhichFileSystem(abs, &pathoffset); DevFileSystem* fs = Mount::WhichFileSystem(abs, &pathoffset);
if ( !fs ) { delete[] abs; Error::Set(EINVAL); return -1; } if ( !fs ) { delete[] abs; errno = EINVAL; return -1; }
Device* dev = fs->Open(abs + pathoffset, O_SEARCH | O_DIRECTORY, 0); Device* dev = fs->Open(abs + pathoffset, O_SEARCH | O_DIRECTORY, 0);
if ( !dev ) { Error::Set(ENOTDIR); return -1; } if ( !dev ) { errno = ENOTDIR; return -1; }
dev->Unref(); dev->Unref();
// Alright, the path passed. // Alright, the path passed.
@ -123,7 +123,7 @@ namespace Sortix
const char* wd = process->workingdir; const char* wd = process->workingdir;
if ( !wd ) { wd = "/"; } if ( !wd ) { wd = "/"; }
size_t wdsize = String::Length(wd) + 1; size_t wdsize = String::Length(wd) + 1;
if ( size < wdsize ) { Error::Set(ERANGE); return NULL; } if ( size < wdsize ) { errno = ERANGE; return NULL; }
String::Copy(buf, wd); String::Copy(buf, wd);
return buf; return buf;
} }

View file

@ -24,9 +24,9 @@
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <sortix/mman.h> #include <sortix/mman.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "elf.h" #include "elf.h"
#include <sortix/kernel/memorymanagement.h> #include <sortix/kernel/memorymanagement.h>
#include <sortix/kernel/panic.h> #include <sortix/kernel/panic.h>
@ -142,7 +142,7 @@ namespace Sortix
addr_t Construct64(Process* process, const void* file, size_t filelen) addr_t Construct64(Process* process, const void* file, size_t filelen)
{ {
#ifndef PLATFORM_X64 #ifndef PLATFORM_X64
Error::Set(ENOEXEC); errno = ENOEXEC;
return 0; return 0;
#else #else
if ( filelen < sizeof(Header64) ) { return 0; } if ( filelen < sizeof(Header64) ) { return 0; }
@ -228,13 +228,13 @@ namespace Sortix
addr_t Construct(Process* process, const void* file, size_t filelen) addr_t Construct(Process* process, const void* file, size_t filelen)
{ {
if ( filelen < sizeof(Header) ) { Error::Set(ENOEXEC); return 0; } if ( filelen < sizeof(Header) ) { errno = ENOEXEC; return 0; }
const Header* header = (const Header*) file; const Header* header = (const Header*) file;
if ( !(header->magic[0] == 0x7F && header->magic[1] == 'E' && if ( !(header->magic[0] == 0x7F && header->magic[1] == 'E' &&
header->magic[2] == 'L' && header->magic[3] == 'F' ) ) header->magic[2] == 'L' && header->magic[3] == 'F' ) )
{ {
Error::Set(ENOEXEC); errno = ENOEXEC;
return 0; return 0;
} }

View file

@ -23,9 +23,9 @@
******************************************************************************/ ******************************************************************************/
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <errno.h>
#include "syscall.h" #include "syscall.h"
#include "process.h" #include "process.h"
#include "filesystem.h" #include "filesystem.h"
@ -46,7 +46,7 @@ namespace Sortix
Process* process = CurrentProcess(); Process* process = CurrentProcess();
const char* wd = process->workingdir; const char* wd = process->workingdir;
char* abs = Directory::MakeAbsolute(wd, path); char* abs = Directory::MakeAbsolute(wd, path);
if ( !abs ) { Error::Set(ENOMEM); return NULL; } if ( !abs ) { errno = ENOMEM; return NULL; }
size_t pathoffset = 0; size_t pathoffset = 0;
DevFileSystem* fs = Mount::WhichFileSystem(abs, &pathoffset); DevFileSystem* fs = Mount::WhichFileSystem(abs, &pathoffset);
@ -61,7 +61,7 @@ namespace Sortix
Process* process = CurrentProcess(); Process* process = CurrentProcess();
const char* wd = process->workingdir; const char* wd = process->workingdir;
char* abs = Directory::MakeAbsolute(wd, path); char* abs = Directory::MakeAbsolute(wd, path);
if ( !abs ) { Error::Set(ENOMEM); return false; } if ( !abs ) { errno = ENOMEM; return false; }
size_t pathoffset = 0; size_t pathoffset = 0;
DevFileSystem* fs = Mount::WhichFileSystem(abs, &pathoffset); DevFileSystem* fs = Mount::WhichFileSystem(abs, &pathoffset);
@ -113,28 +113,28 @@ namespace Sortix
int SysMkDir(const char* pathname, mode_t mode) int SysMkDir(const char* pathname, mode_t mode)
{ {
// TODO: Add the proper filesystem support! // TODO: Add the proper filesystem support!
Error::Set(ENOSYS); errno = ENOSYS;
return -1; return -1;
} }
int SysRmDir(const char* pathname) int SysRmDir(const char* pathname)
{ {
// TODO: Add the proper filesystem support! // TODO: Add the proper filesystem support!
Error::Set(ENOSYS); errno = ENOSYS;
return -1; return -1;
} }
int SysTruncate(const char* pathname, off_t length) int SysTruncate(const char* pathname, off_t length)
{ {
// TODO: Add the proper filesystem support! // TODO: Add the proper filesystem support!
Error::Set(ENOSYS); errno = ENOSYS;
return -1; return -1;
} }
int SysFTruncate(const char* pathname, off_t length) int SysFTruncate(const char* pathname, off_t length)
{ {
// TODO: Add the proper filesystem support! // TODO: Add the proper filesystem support!
Error::Set(ENOSYS); errno = ENOSYS;
return -1; return -1;
} }
@ -161,7 +161,7 @@ namespace Sortix
int SysStat(const char* pathname, struct stat* st) int SysStat(const char* pathname, struct stat* st)
{ {
Device* dev = Open(pathname, O_RDONLY, 0); Device* dev = Open(pathname, O_RDONLY, 0);
if ( !dev && Error::Last() == EISDIR ) if ( !dev && errno == EISDIR )
{ {
dev = Open(pathname, O_SEARCH, 0); dev = Open(pathname, O_SEARCH, 0);
} }
@ -176,7 +176,7 @@ namespace Sortix
Process* process = CurrentProcess(); Process* process = CurrentProcess();
DescriptorTable* descs = &(process->descriptors); DescriptorTable* descs = &(process->descriptors);
Device* dev = descs->Get(fd); Device* dev = descs->Get(fd);
if ( !dev ) { Error::Set(EBADF); return -1; } if ( !dev ) { errno = EBADF; return -1; }
HackStat(dev, st); HackStat(dev, st);
return 0; return 0;
} }
@ -186,17 +186,17 @@ namespace Sortix
Process* process = CurrentProcess(); Process* process = CurrentProcess();
DescriptorTable* descs = &(process->descriptors); DescriptorTable* descs = &(process->descriptors);
Device* dev = descs->Get(fd); Device* dev = descs->Get(fd);
if ( !dev ) { Error::Set(EBADF); return -1; } if ( !dev ) { errno = EBADF; return -1; }
switch ( cmd ) switch ( cmd )
{ {
case F_SETFD: descs->SetFlags(fd, (int) arg); return 0; case F_SETFD: descs->SetFlags(fd, (int) arg); return 0;
case F_GETFD: return descs->GetFlags(fd); case F_GETFD: return descs->GetFlags(fd);
case F_SETFL: Error::Set(ENOSYS); return -1; case F_SETFL: errno = ENOSYS; return -1;
case F_GETFL: case F_GETFL:
if ( dev->IsType(Device::DIRECTORY) ) { return O_SEARCH; } if ( dev->IsType(Device::DIRECTORY) ) { return O_SEARCH; }
if ( !dev->IsType(Device::STREAM) ) if ( !dev->IsType(Device::STREAM) )
{ {
Error::Set(ENOSYS); errno = ENOSYS;
return -1; return -1;
} }
DevStream* stream = (DevStream*) stream; DevStream* stream = (DevStream*) stream;
@ -208,7 +208,7 @@ namespace Sortix
return O_EXEC; return O_EXEC;
break; break;
} }
Error::Set(EINVAL); errno = EINVAL;
return 1; return 1;
} }

View file

@ -23,10 +23,10 @@
******************************************************************************/ ******************************************************************************/
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "../filesystem.h" #include "../filesystem.h"
#include "../directory.h" #include "../directory.h"
#include "../stream.h" #include "../stream.h"
@ -89,7 +89,7 @@ namespace Sortix
ssize_t DevATA::Write(const uint8_t* src, size_t count) ssize_t DevATA::Write(const uint8_t* src, size_t count)
{ {
if ( SIZE_MAX < count ) { count = SIZE_MAX; } if ( SIZE_MAX < count ) { count = SIZE_MAX; }
if ( drive->GetSize() <= offset && count ) { Error::Set(ENOSPC); return -1; } if ( drive->GetSize() <= offset && count ) { errno = ENOSPC; return -1; }
if ( drive->GetSize() - offset < count ) { count = drive->GetSize() - offset; } if ( drive->GetSize() - offset < count ) { count = drive->GetSize() - offset; }
size_t amount = drive->Write(offset, src, count); size_t amount = drive->Write(offset, src, count);
if ( count && !amount ) { return -1; } if ( count && !amount ) { return -1; }
@ -124,14 +124,14 @@ namespace Sortix
bool DevATA::Seek(uintmax_t position) bool DevATA::Seek(uintmax_t position)
{ {
if ( drive->GetSize() <= position ) { Error::Set(ENOSPC); return false; } if ( drive->GetSize() <= position ) { errno = ENOSPC; return false; }
offset = position; offset = position;
return true; return true;
} }
bool DevATA::Resize(uintmax_t /*size*/) bool DevATA::Resize(uintmax_t /*size*/)
{ {
Error::Set(EPERM); errno = EPERM;
return false; return false;
} }
@ -330,7 +330,7 @@ namespace Sortix
if ( available < needed ) if ( available < needed )
{ {
dirent->d_namelen = needed; dirent->d_namelen = needed;
Error::Set(ERANGE); errno = ERANGE;
return -1; return -1;
} }
@ -356,7 +356,7 @@ namespace Sortix
if ( !path[0] || (path[0] == '/' && !path[1]) ) if ( !path[0] || (path[0] == '/' && !path[1]) )
{ {
if ( lowerflags != O_SEARCH ) { Error::Set(EISDIR); return NULL; } if ( lowerflags != O_SEARCH ) { errno = EISDIR; return NULL; }
return new DevDevFSDir(); return new DevDevFSDir();
} }
@ -372,7 +372,7 @@ namespace Sortix
Device* dev = DeviceFS::LookUp(path + 1); Device* dev = DeviceFS::LookUp(path + 1);
if ( !dev ) if ( !dev )
{ {
Error::Set(flags & O_CREAT ? EPERM : ENOENT); errno = flags & O_CREAT ? EPERM : ENOENT;
return NULL; return NULL;
} }
if ( dev->IsType(Device::BUFFER) ) if ( dev->IsType(Device::BUFFER) )
@ -395,11 +395,11 @@ namespace Sortix
if ( *path == '\0' || ( *path++ == '/' && *path == '\0' ) ) if ( *path == '\0' || ( *path++ == '/' && *path == '\0' ) )
{ {
Error::Set(EISDIR); errno = EISDIR;
return false; return false;
} }
Error::Set(EPERM); errno = EPERM;
return false; return false;
} }
} }

View file

@ -24,9 +24,9 @@
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <sortix/kernel/kthread.h> #include <sortix/kernel/kthread.h>
#include <libmaxsi/error.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <errno.h>
#include "../filesystem.h" #include "../filesystem.h"
#include "../directory.h" #include "../directory.h"
#include "../stream.h" #include "../stream.h"
@ -102,14 +102,14 @@ namespace Sortix
bool DevInitFSFile::Seek(uintmax_t position) bool DevInitFSFile::Seek(uintmax_t position)
{ {
ScopedLock lock(&filelock); ScopedLock lock(&filelock);
if ( SIZE_MAX < position ) { Error::Set(EOVERFLOW); return false; } if ( SIZE_MAX < position ) { errno = EOVERFLOW; return false; }
offset = position; offset = position;
return true; return true;
} }
bool DevInitFSFile::Resize(uintmax_t /*size*/) bool DevInitFSFile::Resize(uintmax_t /*size*/)
{ {
Error::Set(EBADF); errno = EBADF;
return false; return false;
} }
@ -127,7 +127,7 @@ namespace Sortix
ssize_t DevInitFSFile::Write(const uint8_t* /*src*/, size_t /*count*/) ssize_t DevInitFSFile::Write(const uint8_t* /*src*/, size_t /*count*/)
{ {
Error::Set(EBADF); errno = EBADF;
return false; return false;
} }
@ -194,7 +194,7 @@ namespace Sortix
if ( available < needed ) if ( available < needed )
{ {
dirent->d_namelen = needed; dirent->d_namelen = needed;
Error::Set(ERANGE); errno = ERANGE;
return -1; return -1;
} }
@ -219,11 +219,11 @@ namespace Sortix
if ( !path[0] || (path[0] == '/' && !path[1]) ) if ( !path[0] || (path[0] == '/' && !path[1]) )
{ {
if ( lowerflags != O_SEARCH ) { Error::Set(EISDIR); return NULL; } if ( lowerflags != O_SEARCH ) { errno = EISDIR; return NULL; }
return new DevInitFSDir(InitRD::Root()); return new DevInitFSDir(InitRD::Root());
} }
if ( *path++ != '/' ) { Error::Set(ENOENT); return NULL; } if ( *path++ != '/' ) { errno = ENOENT; return NULL; }
uint32_t ino = InitRD::Traverse(InitRD::Root(), path); uint32_t ino = InitRD::Traverse(InitRD::Root(), path);
if ( !ino ) { return NULL; } if ( !ino ) { return NULL; }
@ -231,21 +231,21 @@ namespace Sortix
const uint8_t* buffer = InitRD::Open(ino, &buffersize); const uint8_t* buffer = InitRD::Open(ino, &buffersize);
if ( !buffer ) { return NULL; } if ( !buffer ) { return NULL; }
if ( lowerflags == O_SEARCH ) { Error::Set(ENOTDIR); return NULL; } if ( lowerflags == O_SEARCH ) { errno = ENOTDIR; return NULL; }
if ( lowerflags != O_RDONLY ) { Error::Set(EROFS); return NULL; } if ( lowerflags != O_RDONLY ) { errno = EROFS; return NULL; }
char* newpath = String::Clone(path); char* newpath = String::Clone(path);
if ( !newpath ) { Error::Set(ENOSPC); return NULL; } if ( !newpath ) { errno = ENOSPC; return NULL; }
Device* result = new DevInitFSFile(newpath, buffer, buffersize); Device* result = new DevInitFSFile(newpath, buffer, buffersize);
if ( !result ) { delete[] newpath; Error::Set(ENOSPC); return NULL; } if ( !result ) { delete[] newpath; errno = ENOSPC; return NULL; }
return result; return result;
} }
bool DevInitFS::Unlink(const char* path) bool DevInitFS::Unlink(const char* path)
{ {
Error::Set(EROFS); errno = EROFS;
return false; return false;
} }
} }

View file

@ -23,10 +23,10 @@
******************************************************************************/ ******************************************************************************/
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "../filesystem.h" #include "../filesystem.h"
#include "../directory.h" #include "../directory.h"
#include "../stream.h" #include "../stream.h"
@ -99,16 +99,16 @@ namespace Sortix
bool DevRAMFSFile::Seek(uintmax_t position) bool DevRAMFSFile::Seek(uintmax_t position)
{ {
if ( SIZE_MAX < position ) { Error::Set(EOVERFLOW); return false; } if ( SIZE_MAX < position ) { errno = EOVERFLOW; return false; }
offset = position; offset = position;
return true; return true;
} }
bool DevRAMFSFile::Resize(uintmax_t size) bool DevRAMFSFile::Resize(uintmax_t size)
{ {
if ( SIZE_MAX < size ) { Error::Set(EOVERFLOW); return false; } if ( SIZE_MAX < size ) { errno = EOVERFLOW; return false; }
uint8_t* newbuffer = new uint8_t[size]; uint8_t* newbuffer = new uint8_t[size];
if ( !newbuffer ) { Error::Set(ENOSPC); return false; } if ( !newbuffer ) { errno = ENOSPC; return false; }
size_t sharedmemsize = ( size < bufferused ) ? size : bufferused; size_t sharedmemsize = ( size < bufferused ) ? size : bufferused;
Memory::Copy(newbuffer, buffer, sharedmemsize); Memory::Copy(newbuffer, buffer, sharedmemsize);
delete[] buffer; delete[] buffer;
@ -223,7 +223,7 @@ namespace Sortix
if ( available < needed ) if ( available < needed )
{ {
dirent->d_namelen = needed; dirent->d_namelen = needed;
Error::Set(ERANGE); errno = ERANGE;
return -1; return -1;
} }
@ -252,31 +252,31 @@ namespace Sortix
return new DevRAMFSDir(this); return new DevRAMFSDir(this);
} }
Error::Set(EISDIR); errno = EISDIR;
return NULL; return NULL;
} }
if ( (flags & O_LOWERFLAGS) == O_SEARCH ) { Error::Set(ENOTDIR); return NULL; } if ( (flags & O_LOWERFLAGS) == O_SEARCH ) { errno = ENOTDIR; return NULL; }
if ( *path++ != '/' ) { Error::Set(ENOENT); return NULL; } if ( *path++ != '/' ) { errno = ENOENT; return NULL; }
size_t pathlen = String::Length(path); size_t pathlen = String::Length(path);
for ( size_t i = 0; i < pathlen; i++ ) for ( size_t i = 0; i < pathlen; i++ )
{ {
if ( path[i] == '/' ) { Error::Set(ENOENT); return NULL; } if ( path[i] == '/' ) { errno = ENOENT; return NULL; }
} }
DevBuffer* file = OpenFile(path, flags, mode); DevBuffer* file = OpenFile(path, flags, mode);
if ( !file ) { return NULL; } if ( !file ) { return NULL; }
Device* wrapper = new DevFileWrapper(file, flags); Device* wrapper = new DevFileWrapper(file, flags);
if ( !wrapper ) { Error::Set(ENOSPC); return NULL; } if ( !wrapper ) { errno = ENOSPC; return NULL; }
return wrapper; return wrapper;
} }
DevBuffer* DevRAMFS::OpenFile(const char* path, int flags, mode_t mode) DevBuffer* DevRAMFS::OpenFile(const char* path, int flags, mode_t mode)
{ {
// Hack to prevent / from being a filename. // Hack to prevent / from being a filename.
if ( path == 0 ) { Error::Set(ENOENT); return NULL; } if ( path == 0 ) { errno = ENOENT; return NULL; }
if ( files ) if ( files )
{ {
@ -294,26 +294,26 @@ namespace Sortix
DevBuffer* DevRAMFS::CreateFile(const char* path, int flags, mode_t mode) DevBuffer* DevRAMFS::CreateFile(const char* path, int flags, mode_t mode)
{ {
if ( !(flags & O_CREAT) ) { Error::Set(ENOENT); return NULL; } if ( !(flags & O_CREAT) ) { errno = ENOENT; return NULL; }
if ( !files ) if ( !files )
{ {
files = new SortedList<DevRAMFSFile*>(CompareFiles); files = new SortedList<DevRAMFSFile*>(CompareFiles);
if ( !files) { Error::Set(ENOSPC); return NULL; } if ( !files) { errno = ENOSPC; return NULL; }
} }
if ( files->Search(LookupFile, path) != SIZE_MAX ) if ( files->Search(LookupFile, path) != SIZE_MAX )
{ {
Error::Set(EEXIST); errno = EEXIST;
return NULL; return NULL;
} }
char* newpath = String::Clone(path); char* newpath = String::Clone(path);
if ( !newpath ) { Error::Set(ENOSPC); return NULL; } if ( !newpath ) { errno = ENOSPC; return NULL; }
DevRAMFSFile* file = new DevRAMFSFile(newpath); DevRAMFSFile* file = new DevRAMFSFile(newpath);
if ( !file ) { delete[] newpath; Error::Set(ENOSPC); return NULL; } if ( !file ) { delete[] newpath; errno = ENOSPC; return NULL; }
if ( !files->Add(file) ) { delete file; Error::Set(ENOSPC); return NULL; } if ( !files->Add(file) ) { delete file; errno = ENOSPC; return NULL; }
file->Refer(); file->Refer();
@ -324,13 +324,13 @@ namespace Sortix
{ {
if ( *path == '\0' || ( *path++ == '/' && *path == '\0' ) ) if ( *path == '\0' || ( *path++ == '/' && *path == '\0' ) )
{ {
Error::Set(EISDIR); errno = EISDIR;
return false; return false;
} }
if ( !files ) { Error::Set(ENOENT); return false; } if ( !files ) { errno = ENOENT; return false; }
size_t index = files->Search(LookupFile, path); size_t index = files->Search(LookupFile, path);
if ( index == SIZE_MAX ) { Error::Set(ENOENT); return false; } if ( index == SIZE_MAX ) { errno = ENOENT; return false; }
Device* dev = files->Remove(index); Device* dev = files->Remove(index);
assert(dev); assert(dev);

View file

@ -23,9 +23,9 @@
*******************************************************************************/ *******************************************************************************/
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <errno.h>
#include "util.h" #include "util.h"
using namespace Maxsi; using namespace Maxsi;
@ -61,14 +61,14 @@ uintmax_t DevStringBuffer::Position()
bool DevStringBuffer::Seek(uintmax_t position) bool DevStringBuffer::Seek(uintmax_t position)
{ {
if ( strlength <= position ) { Error::Set(EINVAL); return false; } if ( strlength <= position ) { errno = EINVAL; return false; }
off = position; off = position;
return true; return true;
} }
bool DevStringBuffer::Resize(uintmax_t size) bool DevStringBuffer::Resize(uintmax_t size)
{ {
if ( size != strlength ) { Error::Set(EBADF); } if ( size != strlength ) { errno = EBADF; }
return false; return false;
} }
@ -83,7 +83,7 @@ ssize_t DevStringBuffer::Read(uint8_t* dest, size_t count)
ssize_t DevStringBuffer::Write(const uint8_t* /*src*/, size_t /*count*/) ssize_t DevStringBuffer::Write(const uint8_t* /*src*/, size_t /*count*/)
{ {
Error::Set(EBADF); errno = EBADF;
return -1; return -1;
} }
@ -112,15 +112,15 @@ DevLineCommand::~DevLineCommand()
ssize_t DevLineCommand::Read(uint8_t* /*dest*/, size_t /*count*/) ssize_t DevLineCommand::Read(uint8_t* /*dest*/, size_t /*count*/)
{ {
Error::Set(EBADF); errno = EBADF;
return -1; return -1;
} }
ssize_t DevLineCommand::Write(const uint8_t* src, size_t count) ssize_t DevLineCommand::Write(const uint8_t* src, size_t count)
{ {
if ( handled ) { Error::Set(EINVAL); return -1; } if ( handled ) { errno = EINVAL; return -1; }
size_t available = CMDMAX - sofar; size_t available = CMDMAX - sofar;
if ( !available && count ) { Error::Set(ENOSPC); return -1; } if ( !available && count ) { errno = ENOSPC; return -1; }
if ( available < count ) { count = available; } if ( available < count ) { count = available; }
Memory::Copy(cmd + sofar, src, count); Memory::Copy(cmd + sofar, src, count);
cmd[sofar += count] = 0; cmd[sofar += count] = 0;
@ -180,7 +180,7 @@ bool DevMemoryBuffer::Seek(uintmax_t position)
bool DevMemoryBuffer::Resize(uintmax_t size) bool DevMemoryBuffer::Resize(uintmax_t size)
{ {
if ( size != bufsize ) { Error::Set(EPERM); return false; } if ( size != bufsize ) { errno = EPERM; return false; }
return true; return true;
} }
@ -196,8 +196,8 @@ ssize_t DevMemoryBuffer::Read(uint8_t* dest, size_t count)
ssize_t DevMemoryBuffer::Write(const uint8_t* src, size_t count) ssize_t DevMemoryBuffer::Write(const uint8_t* src, size_t count)
{ {
if ( !write ) { Error::Set(EBADF); return -1; } if ( !write ) { errno = EBADF; return -1; }
if ( bufsize <= off ) { Error::Set(EPERM); return -1; } if ( bufsize <= off ) { errno = EPERM; return -1; }
size_t available = bufsize - off; size_t available = bufsize - off;
if ( available < count ) { count = available; } if ( available < count ) { count = available; }
Memory::Copy(buf + off, src, count); Memory::Copy(buf + off, src, count);

View file

@ -24,9 +24,9 @@
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <sortix/kernel/video.h> #include <sortix/kernel/video.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <errno.h>
#include "../directory.h" #include "../directory.h"
#include "util.h" #include "util.h"
#include "videofs.h" #include "videofs.h"
@ -89,7 +89,7 @@ bool DevFrameBuffer::Seek(uintmax_t position)
bool DevFrameBuffer::Resize(uintmax_t /*size*/) bool DevFrameBuffer::Resize(uintmax_t /*size*/)
{ {
Error::Set(EBADF); errno = EBADF;
return false; return false;
} }
@ -147,18 +147,18 @@ Device* MakeSetMode(int /*flags*/, mode_t /*mode*/)
Device* MakeMode(int flags, mode_t mode) Device* MakeMode(int flags, mode_t mode)
{ {
int lowerflags = flags & O_LOWERFLAGS; int lowerflags = flags & O_LOWERFLAGS;
if ( lowerflags == O_SEARCH ) { Error::Set(ENOTDIR); return NULL; } if ( lowerflags == O_SEARCH ) { errno = ENOTDIR; return NULL; }
if ( lowerflags == O_RDONLY ) { return MakeGetMode(flags, mode); } if ( lowerflags == O_RDONLY ) { return MakeGetMode(flags, mode); }
if ( lowerflags == O_WRONLY ) { return MakeSetMode(flags, mode); } if ( lowerflags == O_WRONLY ) { return MakeSetMode(flags, mode); }
Error::Set(EPERM); errno = EPERM;
return NULL; return NULL;
} }
Device* MakeModes(int flags, mode_t /*mode*/) Device* MakeModes(int flags, mode_t /*mode*/)
{ {
int lowerflags = flags & O_LOWERFLAGS; int lowerflags = flags & O_LOWERFLAGS;
if ( lowerflags == O_SEARCH ) { Error::Set(ENOTDIR); return NULL; } if ( lowerflags == O_SEARCH ) { errno = ENOTDIR; return NULL; }
if ( lowerflags != O_RDONLY ) { Error::Set(EPERM); return NULL; } if ( lowerflags != O_RDONLY ) { errno = EPERM; return NULL; }
size_t nummodes = 0; size_t nummodes = 0;
char** modes = Video::GetModes(&nummodes); char** modes = Video::GetModes(&nummodes);
if ( !modes ) { return NULL; } if ( !modes ) { return NULL; }
@ -189,14 +189,14 @@ out:
Device* MakeSupports(int flags, mode_t /*mode*/) Device* MakeSupports(int flags, mode_t /*mode*/)
{ {
int lowerflags = flags & O_LOWERFLAGS; int lowerflags = flags & O_LOWERFLAGS;
if ( lowerflags == O_SEARCH ) { Error::Set(ENOTDIR); return NULL; } if ( lowerflags == O_SEARCH ) { errno = ENOTDIR; return NULL; }
return new DevLineCommand(SupportsModeHandler, NULL); return new DevLineCommand(SupportsModeHandler, NULL);
} }
Device* MakeFB(int flags, mode_t /*mode*/) Device* MakeFB(int flags, mode_t /*mode*/)
{ {
int lowerflags = flags & O_LOWERFLAGS; int lowerflags = flags & O_LOWERFLAGS;
if ( lowerflags == O_SEARCH ) { Error::Set(ENOTDIR); return NULL; } if ( lowerflags == O_SEARCH ) { errno = ENOTDIR; return NULL; }
return new DevFrameBuffer(); return new DevFrameBuffer();
} }
@ -275,7 +275,7 @@ int DevVideoFSDir::Read(sortix_dirent* dirent, size_t available)
if ( available < needed ) if ( available < needed )
{ {
dirent->d_namelen = needed; dirent->d_namelen = needed;
Error::Set(ERANGE); errno = ERANGE;
return -1; return -1;
} }
@ -298,24 +298,24 @@ Device* DevVideoFS::Open(const char* path, int flags, mode_t mode)
if ( !String::Compare(path, "") || !String::Compare(path, "/") ) if ( !String::Compare(path, "") || !String::Compare(path, "/") )
{ {
if ( (flags & O_LOWERFLAGS) == O_SEARCH ) { return new DevVideoFSDir; } if ( (flags & O_LOWERFLAGS) == O_SEARCH ) { return new DevVideoFSDir; }
Error::Set(EISDIR); errno = EISDIR;
return NULL; return NULL;
} }
if ( *path++ != '/' ) { Error::Set(ENOENT); return NULL; } if ( *path++ != '/' ) { errno = ENOENT; return NULL; }
for ( size_t i = 0; i < NumNodes(); i++ ) for ( size_t i = 0; i < NumNodes(); i++ )
{ {
if ( String::Compare(path, nodes[i].name) ) { continue; } if ( String::Compare(path, nodes[i].name) ) { continue; }
return nodes[i].factory(flags, mode); return nodes[i].factory(flags, mode);
} }
Error::Set(ENOENT); errno = ENOENT;
return NULL; return NULL;
} }
bool DevVideoFS::Unlink(const char* /*path*/) bool DevVideoFS::Unlink(const char* /*path*/)
{ {
Error::Set(EPERM); errno = EPERM;
return false; return false;
} }

View file

@ -27,10 +27,10 @@
#include <sortix/stat.h> #include <sortix/stat.h>
#include <sortix/mman.h> #include <sortix/mman.h>
#include <sortix/initrd.h> #include <sortix/initrd.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <libmaxsi/crc32.h> #include <libmaxsi/crc32.h>
#include <errno.h>
#include "initrd.h" #include "initrd.h"
#include "syscall.h" #include "syscall.h"
@ -78,7 +78,7 @@ uint32_t Root()
static const initrd_inode_t* GetInode(uint32_t inode) static const initrd_inode_t* GetInode(uint32_t inode)
{ {
if ( sb->inodecount <= inode ) { Error::Set(EINVAL); return NULL; } if ( sb->inodecount <= inode ) { errno = EINVAL; return NULL; }
uint32_t pos = sb->inodeoffset + sb->inodesize * inode; uint32_t pos = sb->inodeoffset + sb->inodesize * inode;
return (const initrd_inode_t*) (initrd + pos); return (const initrd_inode_t*) (initrd + pos);
} }
@ -113,7 +113,7 @@ uint32_t Traverse(uint32_t ino, const char* name)
{ {
const initrd_inode_t* inode = GetInode(ino); const initrd_inode_t* inode = GetInode(ino);
if ( !inode ) { return 0; } if ( !inode ) { return 0; }
if ( !INITRD_S_ISDIR(inode->mode) ) { Error::Set(ENOTDIR); return 0; } if ( !INITRD_S_ISDIR(inode->mode) ) { errno = ENOTDIR; return 0; }
uint32_t offset = 0; uint32_t offset = 0;
while ( offset < inode->size ) while ( offset < inode->size )
{ {
@ -125,7 +125,7 @@ uint32_t Traverse(uint32_t ino, const char* name)
} }
offset += dirent->reclen; offset += dirent->reclen;
} }
Error::Set(ENOENT); errno = ENOENT;
return 0; return 0;
} }
@ -134,7 +134,7 @@ const char* GetFilename(uint32_t dir, size_t index)
{ {
const initrd_inode_t* inode = GetInode(dir); const initrd_inode_t* inode = GetInode(dir);
if ( !inode ) { return 0; } if ( !inode ) { return 0; }
if ( !INITRD_S_ISDIR(inode->mode) ) { Error::Set(ENOTDIR); return 0; } if ( !INITRD_S_ISDIR(inode->mode) ) { errno = ENOTDIR; return 0; }
uint32_t offset = 0; uint32_t offset = 0;
while ( offset < inode->size ) while ( offset < inode->size )
{ {
@ -143,7 +143,7 @@ const char* GetFilename(uint32_t dir, size_t index)
if ( index-- == 0 ) { return dirent->name; } if ( index-- == 0 ) { return dirent->name; }
offset += dirent->reclen; offset += dirent->reclen;
} }
Error::Set(EINVAL); errno = EINVAL;
return NULL; return NULL;
} }
@ -151,7 +151,7 @@ size_t GetNumFiles(uint32_t dir)
{ {
const initrd_inode_t* inode = GetInode(dir); const initrd_inode_t* inode = GetInode(dir);
if ( !inode ) { return 0; } if ( !inode ) { return 0; }
if ( !INITRD_S_ISDIR(inode->mode) ) { Error::Set(ENOTDIR); return 0; } if ( !INITRD_S_ISDIR(inode->mode) ) { errno = ENOTDIR; return 0; }
uint32_t offset = 0; uint32_t offset = 0;
size_t numentries = 0; size_t numentries = 0;
while ( offset < inode->size ) while ( offset < inode->size )

View file

@ -23,9 +23,9 @@
*******************************************************************************/ *******************************************************************************/
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "x86-family/idt.h" #include "x86-family/idt.h"
#include "interrupt.h" #include "interrupt.h"
#include "scheduler.h" #include "scheduler.h"

View file

@ -24,8 +24,8 @@
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <sortix/kernel/kthread.h> #include <sortix/kernel/kthread.h>
#include <libmaxsi/error.h>
#include <sortix/seek.h> #include <sortix/seek.h>
#include <errno.h>
#include "thread.h" #include "thread.h"
#include "process.h" #include "process.h"
#include "device.h" #include "device.h"
@ -56,14 +56,14 @@ namespace Sortix
if ( SSIZE_MAX < count ) { count = SSIZE_MAX; } if ( SSIZE_MAX < count ) { count = SSIZE_MAX; }
Process* process = CurrentProcess(); Process* process = CurrentProcess();
Device* dev = process->descriptors.Get(fd); Device* dev = process->descriptors.Get(fd);
if ( !dev ) { Error::Set(EBADF); return -1; } if ( !dev ) { errno = EBADF; return -1; }
if ( !dev->IsType(Device::STREAM) ) { Error::Set(EBADF); return -1; } if ( !dev->IsType(Device::STREAM) ) { errno = EBADF; return -1; }
DevStream* stream = (DevStream*) dev; DevStream* stream = (DevStream*) dev;
if ( !stream->IsWritable() ) { Error::Set(EBADF); return -1; } if ( !stream->IsWritable() ) { errno = EBADF; return -1; }
#ifdef GOT_FAKE_KTHREAD #ifdef GOT_FAKE_KTHREAD
ssize_t written = stream->Write(buffer, count); ssize_t written = stream->Write(buffer, count);
if ( 0 <= written ) { return written; } if ( 0 <= written ) { return written; }
if ( Error::Last() != EBLOCKING ) { return -1; } if ( errno != EBLOCKING ) { return -1; }
// The stream will resume our system call once progress has been // The stream will resume our system call once progress has been
// made. Our request is certainly not forgotten. // made. Our request is certainly not forgotten.
@ -88,7 +88,7 @@ namespace Sortix
// TODO: Not implemented yet due to stupid internal kernel design. // TODO: Not implemented yet due to stupid internal kernel design.
ssize_t SysPWrite(int fd, const uint8_t* buffer, size_t count, off_t off) ssize_t SysPWrite(int fd, const uint8_t* buffer, size_t count, off_t off)
{ {
Error::Set(ENOSYS); errno = ENOSYS;
return -1; return -1;
} }
@ -109,14 +109,14 @@ namespace Sortix
if ( SSIZE_MAX < count ) { count = SSIZE_MAX; } if ( SSIZE_MAX < count ) { count = SSIZE_MAX; }
Process* process = CurrentProcess(); Process* process = CurrentProcess();
Device* dev = process->descriptors.Get(fd); Device* dev = process->descriptors.Get(fd);
if ( !dev ) { Error::Set(EBADF); return -1; } if ( !dev ) { errno = EBADF; return -1; }
if ( !dev->IsType(Device::STREAM) ) { Error::Set(EBADF); return -1; } if ( !dev->IsType(Device::STREAM) ) { errno = EBADF; return -1; }
DevStream* stream = (DevStream*) dev; DevStream* stream = (DevStream*) dev;
if ( !stream->IsReadable() ) { Error::Set(EBADF); return -1;} if ( !stream->IsReadable() ) { errno = EBADF; return -1;}
#ifdef GOT_FAKE_KTHREAD #ifdef GOT_FAKE_KTHREAD
ssize_t bytesread = stream->Read(buffer, count); ssize_t bytesread = stream->Read(buffer, count);
if ( 0 <= bytesread ) { return bytesread; } if ( 0 <= bytesread ) { return bytesread; }
if ( Error::Last() != EBLOCKING ) { return -1; } if ( errno != EBLOCKING ) { return -1; }
// The stream will resume our system call once progress has been // The stream will resume our system call once progress has been
// made. Our request is certainly not forgotten. // made. Our request is certainly not forgotten.
@ -141,7 +141,7 @@ namespace Sortix
// TODO: Not implemented yet due to stupid internal kernel design. // TODO: Not implemented yet due to stupid internal kernel design.
ssize_t SysPRead(int fd, uint8_t* buffer, size_t count, off_t off) ssize_t SysPRead(int fd, uint8_t* buffer, size_t count, off_t off)
{ {
Error::Set(ENOSYS); errno = ENOSYS;
return -1; return -1;
} }
@ -150,8 +150,8 @@ namespace Sortix
// TODO: Validate that offset is a legal user-space off_t! // TODO: Validate that offset is a legal user-space off_t!
Process* process = CurrentProcess(); Process* process = CurrentProcess();
Device* dev = process->descriptors.Get(fd); Device* dev = process->descriptors.Get(fd);
if ( !dev ) { Error::Set(EBADF); *offset = -1; return; } if ( !dev ) { errno = EBADF; *offset = -1; return; }
if ( !dev->IsType(Device::BUFFER) ) { Error::Set(EBADF); *offset = -1; return; } if ( !dev->IsType(Device::BUFFER) ) { errno = EBADF; *offset = -1; return; }
DevBuffer* buffer = (DevBuffer*) dev; DevBuffer* buffer = (DevBuffer*) dev;
off_t origin; off_t origin;
switch ( whence ) switch ( whence )
@ -159,10 +159,10 @@ namespace Sortix
case SEEK_SET: origin = 0; break; case SEEK_SET: origin = 0; break;
case SEEK_CUR: origin = buffer->Position(); break; case SEEK_CUR: origin = buffer->Position(); break;
case SEEK_END: origin = buffer->Size(); break; case SEEK_END: origin = buffer->Size(); break;
default: Error::Set(EINVAL); *offset = -1; return; default: errno = EINVAL; *offset = -1; return;
} }
off_t newposition = origin + *offset; off_t newposition = origin + *offset;
if ( newposition < 0 ) { Error::Set(EINVAL); *offset = -1; return; } if ( newposition < 0 ) { errno = EINVAL; *offset = -1; return; }
if ( !buffer->Seek(newposition) ) { *offset = -1; return; } if ( !buffer->Seek(newposition) ) { *offset = -1; return; }
*offset = buffer->Position(); *offset = buffer->Position();
} }
@ -171,7 +171,7 @@ namespace Sortix
{ {
Process* process = CurrentProcess(); Process* process = CurrentProcess();
Device* dev = process->descriptors.Get(fd); Device* dev = process->descriptors.Get(fd);
if ( !dev ) { Error::Set(EBADF); return -1; } if ( !dev ) { errno = EBADF; return -1; }
process->descriptors.Free(fd); process->descriptors.Free(fd);
return 0; return 0;
} }
@ -180,7 +180,7 @@ namespace Sortix
{ {
Process* process = CurrentProcess(); Process* process = CurrentProcess();
Device* dev = process->descriptors.Get(fd); Device* dev = process->descriptors.Get(fd);
if ( !dev ) { Error::Set(EBADF); return -1; } if ( !dev ) { errno = EBADF; return -1; }
return process->descriptors.Allocate(dev); return process->descriptors.Allocate(dev);
} }

View file

@ -23,8 +23,8 @@
*******************************************************************************/ *******************************************************************************/
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <errno.h>
#include "syscall.h" #include "syscall.h"
#include "kernelinfo.h" #include "kernelinfo.h"
@ -49,11 +49,11 @@ const char* KernelInfo(const char* req)
ssize_t SysKernelInfo(const char* req, char* resp, size_t resplen) ssize_t SysKernelInfo(const char* req, char* resp, size_t resplen)
{ {
const char* str = KernelInfo(req); const char* str = KernelInfo(req);
if ( !str ) { Error::Set(EINVAL); return -1; } if ( !str ) { errno = EINVAL; return -1; }
size_t stringlen = String::Length(str); size_t stringlen = String::Length(str);
if ( resplen < stringlen + 1 ) if ( resplen < stringlen + 1 )
{ {
Error::Set(ERANGE); errno = ERANGE;
return (ssize_t) stringlen; return (ssize_t) stringlen;
} }
String::Copy(resp, str); String::Copy(resp, str);

View file

@ -25,8 +25,8 @@
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <sortix/keycodes.h> #include <sortix/keycodes.h>
#include <sortix/signal.h> #include <sortix/signal.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <errno.h>
#include "utf8.h" #include "utf8.h"
#include "keyboard.h" #include "keyboard.h"
#include "process.h" #include "process.h"
@ -74,7 +74,7 @@ namespace Sortix
{ {
ScopedLock lock(&termlock); ScopedLock lock(&termlock);
unsigned oldmode = mode; unsigned oldmode = mode;
if ( oldmode & ~SUPPORTED_MODES ) { Error::Set(ENOSYS); return false; } if ( oldmode & ~SUPPORTED_MODES ) { errno = ENOSYS; return false; }
bool oldutf8 = mode & TERMMODE_UTF8; bool oldutf8 = mode & TERMMODE_UTF8;
bool newutf8 = newmode & TERMMODE_UTF8; bool newutf8 = newmode & TERMMODE_UTF8;
if ( oldutf8 ^ newutf8 ) { partiallywritten = 0; } if ( oldutf8 ^ newutf8 ) { partiallywritten = 0; }
@ -87,14 +87,14 @@ namespace Sortix
bool LogTerminal::SetWidth(unsigned width) bool LogTerminal::SetWidth(unsigned width)
{ {
ScopedLock lock(&termlock); ScopedLock lock(&termlock);
if ( width != GetWidth() ) { Error::Set(ENOTSUP); return false; } if ( width != GetWidth() ) { errno = ENOTSUP; return false; }
return true; return true;
} }
bool LogTerminal::SetHeight(unsigned height) bool LogTerminal::SetHeight(unsigned height)
{ {
ScopedLock lock(&termlock); ScopedLock lock(&termlock);
if ( height != GetHeight() ) { Error::Set(ENOTSUP); return false; } if ( height != GetHeight() ) { errno = ENOTSUP; return false; }
return true; return true;
} }
@ -220,7 +220,7 @@ namespace Sortix
ssize_t LogTerminal::Read(uint8_t* dest, size_t count) ssize_t LogTerminal::Read(uint8_t* dest, size_t count)
{ {
ScopedLockSignal lock(&termlock); ScopedLockSignal lock(&termlock);
if ( !lock.IsAcquired() ) { Error::Set(EINTR); return -1; } if ( !lock.IsAcquired() ) { errno = EINTR; return -1; }
size_t sofar = 0; size_t sofar = 0;
size_t left = count; size_t left = count;
#ifdef GOT_ACTUAL_KTHREAD #ifdef GOT_ACTUAL_KTHREAD
@ -230,11 +230,11 @@ namespace Sortix
numwaiting++; numwaiting++;
bool abort = !kthread_cond_wait_signal(&datacond, &termlock); bool abort = !kthread_cond_wait_signal(&datacond, &termlock);
numwaiting--; numwaiting--;
if ( abort ) { Error::Set(EINTR); return -1; } if ( abort ) { errno = EINTR; return -1; }
} }
if ( left && !linebuffer.CanPop() && !blocking && !numeofs ) if ( left && !linebuffer.CanPop() && !blocking && !numeofs )
{ {
Error::Set(EWOULDBLOCK); errno = EWOULDBLOCK;
return -1; return -1;
} }
#endif #endif
@ -299,8 +299,8 @@ namespace Sortix
// Block if no data were ready. // Block if no data were ready.
if ( !sofar ) if ( !sofar )
{ {
if ( mode & TERMMODE_NONBLOCK ) { Error::Set(EWOULDBLOCK); } if ( mode & TERMMODE_NONBLOCK ) { errno = EWOULDBLOCK; }
else { queuecommitevent.Register(); Error::Set(EBLOCKING); } else { queuecommitevent.Register(); errno = EBLOCKING; }
return -1; return -1;
} }
#endif #endif

View file

@ -25,9 +25,9 @@
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <sortix/kernel/kthread.h> #include <sortix/kernel/kthread.h>
#include <sortix/signal.h> #include <sortix/signal.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#ifdef GOT_FAKE_KTHREAD #ifdef GOT_FAKE_KTHREAD
#include "event.h" #include "event.h"
#endif #endif
@ -103,12 +103,12 @@ namespace Sortix
if ( count == 0 ) { return 0; } if ( count == 0 ) { return 0; }
#ifdef GOT_ACTUAL_KTHREAD #ifdef GOT_ACTUAL_KTHREAD
ScopedLockSignal lock(&pipelock); ScopedLockSignal lock(&pipelock);
if ( !lock.IsAcquired() ) { Error::Set(EINTR); return -1; } if ( !lock.IsAcquired() ) { errno = EINTR; return -1; }
while ( anywriting && !bufferused ) while ( anywriting && !bufferused )
{ {
if ( !kthread_cond_wait_signal(&readcond, &pipelock) ) if ( !kthread_cond_wait_signal(&readcond, &pipelock) )
{ {
Error::Set(EINTR); errno = EINTR;
return -1; return -1;
} }
} }
@ -140,7 +140,7 @@ namespace Sortix
if ( !anywriting ) { return 0; } if ( !anywriting ) { return 0; }
Error::Set(EBLOCKING); errno = EBLOCKING;
readevent.Register(); readevent.Register();
return -1; return -1;
#endif #endif
@ -151,19 +151,19 @@ namespace Sortix
if ( count == 0 ) { return 0; } if ( count == 0 ) { return 0; }
#ifdef GOT_ACTUAL_KTHREAD #ifdef GOT_ACTUAL_KTHREAD
ScopedLockSignal lock(&pipelock); ScopedLockSignal lock(&pipelock);
if ( !lock.IsAcquired() ) { Error::Set(EINTR); return -1; } if ( !lock.IsAcquired() ) { errno = EINTR; return -1; }
while ( anyreading && bufferused == buffersize ) while ( anyreading && bufferused == buffersize )
{ {
if ( !kthread_cond_wait_signal(&writecond, &pipelock) ) if ( !kthread_cond_wait_signal(&writecond, &pipelock) )
{ {
Error::Set(EINTR); errno = EINTR;
return -1; return -1;
} }
} }
if ( !anyreading ) if ( !anyreading )
{ {
CurrentThread()->DeliverSignal(SIGPIPE); CurrentThread()->DeliverSignal(SIGPIPE);
Error::Set(EPIPE); errno = EPIPE;
return -1; return -1;
} }
if ( buffersize - bufferused < count ) { count = buffersize - bufferused; } if ( buffersize - bufferused < count ) { count = buffersize - bufferused; }
@ -191,7 +191,7 @@ namespace Sortix
return amount; return amount;
} }
Error::Set(EBLOCKING); errno = EBLOCKING;
writeevent.Register(); writeevent.Register();
return -1; return -1;
#endif #endif
@ -250,7 +250,7 @@ namespace Sortix
ssize_t DevPipeReading::Write(const uint8_t* /*src*/, size_t /*count*/) ssize_t DevPipeReading::Write(const uint8_t* /*src*/, size_t /*count*/)
{ {
Error::Set(EBADF); errno = EBADF;
return -1; return -1;
} }
@ -298,7 +298,7 @@ namespace Sortix
ssize_t DevPipeWriting::Read(uint8_t* /*dest*/, size_t /*count*/) ssize_t DevPipeWriting::Read(uint8_t* /*dest*/, size_t /*count*/)
{ {
Error::Set(EBADF); errno = EBADF;
return -1; return -1;
} }

View file

@ -31,11 +31,11 @@
#include <sortix/fork.h> #include <sortix/fork.h>
#include <sortix/mman.h> #include <sortix/mman.h>
#include <sortix/wait.h> #include <sortix/wait.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
#include <libmaxsi/sortedlist.h> #include <libmaxsi/sortedlist.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "thread.h" #include "thread.h"
#include "process.h" #include "process.h"
#include "device.h" #include "device.h"
@ -325,12 +325,12 @@ namespace Sortix
pid_t Process::Wait(pid_t thepid, int* status, int options) pid_t Process::Wait(pid_t thepid, int* status, int options)
{ {
// TODO: Process groups are not supported yet. // TODO: Process groups are not supported yet.
if ( thepid < -1 || thepid == 0 ) { Error::Set(ENOSYS); return -1; } if ( thepid < -1 || thepid == 0 ) { errno = ENOSYS; return -1; }
ScopedLock lock(&childlock); ScopedLock lock(&childlock);
// A process can only wait if it has children. // A process can only wait if it has children.
if ( !firstchild && !zombiechild ) { Error::Set(ECHILD); return -1; } if ( !firstchild && !zombiechild ) { errno = ECHILD; return -1; }
// Processes can only wait for their own children to exit. // Processes can only wait for their own children to exit.
if ( 0 < thepid ) if ( 0 < thepid )
@ -344,7 +344,7 @@ namespace Sortix
for ( Process* p = zombiechild; !found && p; p = p->nextsibling ) for ( Process* p = zombiechild; !found && p; p = p->nextsibling )
if ( p->pid == thepid ) if ( p->pid == thepid )
found = true; found = true;
if ( !found ) { Error::Set(ECHILD); return -1; } if ( !found ) { errno = ECHILD; return -1; }
} }
Process* zombie = NULL; Process* zombie = NULL;
@ -360,7 +360,7 @@ namespace Sortix
zombiewaiting++; zombiewaiting++;
unsigned long r = kthread_cond_wait_signal(&zombiecond, &childlock); unsigned long r = kthread_cond_wait_signal(&zombiecond, &childlock);
zombiewaiting--; zombiewaiting--;
if ( !r ) { Error::Set(EINTR); return -1; } if ( !r ) { errno = EINTR; return -1; }
} }
if ( zombie->prevsibling ) if ( zombie->prevsibling )
@ -418,7 +418,7 @@ namespace Sortix
// TODO: How to handle signals that kill the process? // TODO: How to handle signals that kill the process?
if ( firstthread ) if ( firstthread )
return firstthread->DeliverSignal(signum); return firstthread->DeliverSignal(signum);
Error::Set(EINIT); errno = EINIT;
return false; return false;
} }
@ -570,14 +570,14 @@ namespace Sortix
DevBuffer* OpenProgramImage(const char* progname, const char* wd, const char* path) DevBuffer* OpenProgramImage(const char* progname, const char* wd, const char* path)
{ {
char* abs = Directory::MakeAbsolute("/", progname); char* abs = Directory::MakeAbsolute("/", progname);
if ( !abs ) { Error::Set(ENOMEM); return NULL; } if ( !abs ) { errno = ENOMEM; return NULL; }
// TODO: Use O_EXEC here! // TODO: Use O_EXEC here!
Device* dev = FileSystem::Open(abs, O_RDONLY, 0); Device* dev = FileSystem::Open(abs, O_RDONLY, 0);
delete[] abs; delete[] abs;
if ( !dev ) { return NULL; } if ( !dev ) { return NULL; }
if ( !dev->IsType(Device::BUFFER) ) { Error::Set(EACCES); dev->Unref(); return NULL; } if ( !dev->IsType(Device::BUFFER) ) { errno = EACCES; dev->Unref(); return NULL; }
return (DevBuffer*) dev; return (DevBuffer*) dev;
} }
@ -630,9 +630,9 @@ namespace Sortix
dev->Refer(); // TODO: Rules of GC may change soon. dev->Refer(); // TODO: Rules of GC may change soon.
needed = dev->Size(); needed = dev->Size();
if ( SIZE_MAX < needed ) { Error::Set(ENOMEM); goto cleanup_dev; } if ( SIZE_MAX < needed ) { errno = ENOMEM; goto cleanup_dev; }
if ( !dev->IsReadable() ) { Error::Set(EBADF); goto cleanup_dev; } if ( !dev->IsReadable() ) { errno = EBADF; goto cleanup_dev; }
count = needed; count = needed;
buffer = new uint8_t[count]; buffer = new uint8_t[count];
@ -642,7 +642,7 @@ namespace Sortix
{ {
ssize_t bytesread = dev->Read(buffer + sofar, count - sofar); ssize_t bytesread = dev->Read(buffer + sofar, count - sofar);
if ( bytesread < 0 ) { goto cleanup_buffer; } if ( bytesread < 0 ) { goto cleanup_buffer; }
if ( bytesread == 0 ) { Error::Set(EEOF); return -1; } if ( bytesread == 0 ) { errno = EEOF; return -1; }
sofar += bytesread; sofar += bytesread;
} }
@ -668,10 +668,10 @@ namespace Sortix
pid_t SysTFork(int flags, tforkregs_t* regs) pid_t SysTFork(int flags, tforkregs_t* regs)
{ {
if ( Signal::IsPending() ) { Error::Set(EINTR); return -1; } if ( Signal::IsPending() ) { errno = EINTR; return -1; }
// TODO: Properly support tfork(2). // TODO: Properly support tfork(2).
if ( flags != SFFORK ) { Error::Set(ENOSYS); return -1; } if ( flags != SFFORK ) { errno = ENOSYS; return -1; }
CPU::InterruptRegisters cpuregs; CPU::InterruptRegisters cpuregs;
InitializeThreadRegisters(&cpuregs, regs); InitializeThreadRegisters(&cpuregs, regs);
@ -799,10 +799,10 @@ namespace Sortix
if ( dataseg && iter->position < dataseg->position ) { continue; } if ( dataseg && iter->position < dataseg->position ) { continue; }
dataseg = iter; dataseg = iter;
} }
if ( !dataseg ) { Error::Set(ENOMEM); return (void*) -1UL; } if ( !dataseg ) { errno = ENOMEM; return (void*) -1UL; }
addr_t currentend = dataseg->position + dataseg->size; addr_t currentend = dataseg->position + dataseg->size;
addr_t newend = currentend + increment; addr_t newend = currentend + increment;
if ( newend < dataseg->position ) { Error::Set(EINVAL); return (void*) -1UL; } if ( newend < dataseg->position ) { errno = EINVAL; return (void*) -1UL; }
if ( newend < currentend ) if ( newend < currentend )
{ {
addr_t unmapfrom = Page::AlignUp(newend); addr_t unmapfrom = Page::AlignUp(newend);

View file

@ -24,7 +24,6 @@
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <sortix/kernel/memorymanagement.h> #include <sortix/kernel/memorymanagement.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <assert.h> #include <assert.h>
#include "x86-family/gdt.h" #include "x86-family/gdt.h"

View file

@ -23,7 +23,6 @@
*******************************************************************************/ *******************************************************************************/
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <libmaxsi/error.h>
#include "syscall.h" #include "syscall.h"
#include <sortix/syscallnum.h> #include <sortix/syscallnum.h>
#include <sortix/kernel/panic.h> #include <sortix/kernel/panic.h>

View file

@ -24,7 +24,7 @@
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <sortix/termios.h> #include <sortix/termios.h>
#include <libmaxsi/error.h> #include <errno.h>
#include "syscall.h" #include "syscall.h"
#include "process.h" #include "process.h"
#include "terminal.h" #include "terminal.h"
@ -37,8 +37,8 @@ namespace Sortix
{ {
Process* process = CurrentProcess(); Process* process = CurrentProcess();
Device* dev = process->descriptors.Get(fd); Device* dev = process->descriptors.Get(fd);
if ( !dev ) { Error::Set(EBADF); return -1; } if ( !dev ) { errno = EBADF; return -1; }
if ( !dev->IsType(Device::TERMINAL) ) { Error::Set(ENOTTY); return -1; } if ( !dev->IsType(Device::TERMINAL) ) { errno = ENOTTY; return -1; }
DevTerminal* term = (DevTerminal*) dev; DevTerminal* term = (DevTerminal*) dev;
return term->SetMode(mode) ? 0 : -1; return term->SetMode(mode) ? 0 : -1;
} }
@ -47,8 +47,8 @@ namespace Sortix
{ {
Process* process = CurrentProcess(); Process* process = CurrentProcess();
Device* dev = process->descriptors.Get(fd); Device* dev = process->descriptors.Get(fd);
if ( !dev ) { Error::Set(EBADF); return -1; } if ( !dev ) { errno = EBADF; return -1; }
if ( !dev->IsType(Device::TERMINAL) ) { Error::Set(ENOTTY); return -1; } if ( !dev->IsType(Device::TERMINAL) ) { errno = ENOTTY; return -1; }
DevTerminal* term = (DevTerminal*) dev; DevTerminal* term = (DevTerminal*) dev;
// TODO: Check that mode is a valid user-space pointer. // TODO: Check that mode is a valid user-space pointer.
*mode = term->GetMode(); *mode = term->GetMode();
@ -59,8 +59,8 @@ namespace Sortix
{ {
Process* process = CurrentProcess(); Process* process = CurrentProcess();
Device* dev = process->descriptors.Get(fd); Device* dev = process->descriptors.Get(fd);
if ( !dev ) { Error::Set(EBADF); return 0; } if ( !dev ) { errno = EBADF; return 0; }
if ( !dev->IsType(Device::TERMINAL) ) { Error::Set(ENOTTY); return 0; } if ( !dev->IsType(Device::TERMINAL) ) { errno = ENOTTY; return 0; }
return 1; return 1;
} }
@ -68,8 +68,8 @@ namespace Sortix
{ {
Process* process = CurrentProcess(); Process* process = CurrentProcess();
Device* dev = process->descriptors.Get(fd); Device* dev = process->descriptors.Get(fd);
if ( !dev ) { Error::Set(EBADF); return -1; } if ( !dev ) { errno = EBADF; return -1; }
if ( !dev->IsType(Device::TERMINAL) ) { Error::Set(ENOTTY); return -1; } if ( !dev->IsType(Device::TERMINAL) ) { errno = ENOTTY; return -1; }
DevTerminal* term = (DevTerminal*) dev; DevTerminal* term = (DevTerminal*) dev;
struct winsize ret; struct winsize ret;
ret.ws_col = term->GetWidth(); ret.ws_col = term->GetWidth();

View file

@ -27,9 +27,9 @@
#include <sortix/kernel/memorymanagement.h> #include <sortix/kernel/memorymanagement.h>
#include <sortix/mman.h> #include <sortix/mman.h>
#include <sortix/signal.h> #include <sortix/signal.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "process.h" #include "process.h"
#include "thread.h" #include "thread.h"
#include "scheduler.h" #include "scheduler.h"
@ -258,7 +258,7 @@ namespace Sortix
bool Thread::DeliverSignal(int signum) bool Thread::DeliverSignal(int signum)
{ {
if ( signum <= 0 || 128 <= signum ) { Error::Set(EINVAL); return false; } if ( signum <= 0 || 128 <= signum ) { errno = EINVAL; return false; }
bool wasenabled = Interrupt::SetEnabled(false); bool wasenabled = Interrupt::SetEnabled(false);
signalqueue.Push(signum); signalqueue.Push(signum);
@ -271,7 +271,7 @@ namespace Sortix
int SysKill(pid_t pid, int signum) int SysKill(pid_t pid, int signum)
{ {
// Protect the system idle process. // Protect the system idle process.
if ( !pid ) { Error::Set(EPERM); return -1; } if ( !pid ) { errno = EPERM; return -1; }
// If we kill our own process, deliver the signal to this thread. // If we kill our own process, deliver the signal to this thread.
Thread* currentthread = CurrentThread(); Thread* currentthread = CurrentThread();
@ -280,7 +280,7 @@ namespace Sortix
// TODO: Race condition: The process could be deleted while we use it. // TODO: Race condition: The process could be deleted while we use it.
Process* process = Process::Get(pid); Process* process = Process::Get(pid);
if ( !process ) { Error::Set(ESRCH); return -1; } if ( !process ) { errno = ESRCH; return -1; }
// TODO: Protect init? // TODO: Protect init?
// TODO: Check for permission. // TODO: Check for permission.

View file

@ -23,7 +23,7 @@
******************************************************************************/ ******************************************************************************/
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <libmaxsi/error.h> #include <errno.h>
#include "utf8.h" #include "utf8.h"
using namespace Maxsi; using namespace Maxsi;
@ -42,7 +42,7 @@ namespace Sortix
if ( (1U<<16U) <= unicode ) { bytes = 4; bits = 21; } if ( (1U<<16U) <= unicode ) { bytes = 4; bits = 21; }
if ( (1U<<21U) <= unicode ) { bytes = 5; bits = 26; } if ( (1U<<21U) <= unicode ) { bytes = 5; bits = 26; }
if ( (1U<<26U) <= unicode ) { bytes = 6; bits = 31; } if ( (1U<<26U) <= unicode ) { bytes = 6; bits = 31; }
if ( (1U<<31U) <= unicode ) { Error::Set(EINVAL); return 0; } if ( (1U<<31U) <= unicode ) { errno = EINVAL; return 0; }
uint8_t prefix; uint8_t prefix;
unsigned prefixavai; unsigned prefixavai;

View file

@ -23,8 +23,8 @@
*******************************************************************************/ *******************************************************************************/
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <errno.h>
#include "fs/util.h" #include "fs/util.h"
#include "fs/devfs.h" #include "fs/devfs.h"
#include "vga.h" #include "vga.h"
@ -183,7 +183,7 @@ ssize_t DevVGA::Read(uint8_t* dest, size_t count)
ssize_t DevVGA::Write(const uint8_t* src, size_t count) ssize_t DevVGA::Write(const uint8_t* src, size_t count)
{ {
if ( offset == VGA::VGA_SIZE && count ) { Error::Set(ENOSPC); return -1; } if ( offset == VGA::VGA_SIZE && count ) { errno = ENOSPC; return -1; }
if ( VGA::VGA_SIZE - offset < count ) { count = VGA::VGA_SIZE - offset; } if ( VGA::VGA_SIZE - offset < count ) { count = VGA::VGA_SIZE - offset; }
Maxsi::Memory::Copy(VGA::VGA + offset, src, count); Maxsi::Memory::Copy(VGA::VGA + offset, src, count);
offset = (offset + count) % VGA::VGA_SIZE; offset = (offset + count) % VGA::VGA_SIZE;
@ -221,7 +221,7 @@ uintmax_t DevVGA::Position()
bool DevVGA::Seek(uintmax_t position) bool DevVGA::Seek(uintmax_t position)
{ {
if ( VGA::VGA_SIZE < position ) { Error::Set(EINVAL); return false; } if ( VGA::VGA_SIZE < position ) { errno = EINVAL; return false; }
offset = position; offset = position;
return true; return true;
} }
@ -229,7 +229,7 @@ bool DevVGA::Seek(uintmax_t position)
bool DevVGA::Resize(uintmax_t size) bool DevVGA::Resize(uintmax_t size)
{ {
if ( size == VGA::VGA_SIZE ) { return false; } if ( size == VGA::VGA_SIZE ) { return false; }
Error::Set(ENOSPC); errno = ENOSPC;
return false; return false;
} }

View file

@ -27,7 +27,7 @@
#include <sortix/kernel/textbuffer.h> #include <sortix/kernel/textbuffer.h>
#include <sortix/kernel/video.h> #include <sortix/kernel/video.h>
#include <stdarg.h> #include <stdarg.h>
#include <libmaxsi/error.h> #include <errno.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <libmaxsi/string.h> #include <libmaxsi/string.h>
@ -37,7 +37,7 @@ namespace Sortix {
bool ReadParamString(const char* str, ...) bool ReadParamString(const char* str, ...)
{ {
if ( String::Seek(str, '\n') ) { Error::Set(EINVAL); } if ( String::Seek(str, '\n') ) { errno = EINVAL; }
const char* keyname; const char* keyname;
va_list args; va_list args;
while ( *str ) while ( *str )
@ -45,9 +45,9 @@ bool ReadParamString(const char* str, ...)
size_t varlen = String::Reject(str, ","); size_t varlen = String::Reject(str, ",");
if ( !varlen ) { str++; continue; } if ( !varlen ) { str++; continue; }
size_t namelen = String::Reject(str, "="); size_t namelen = String::Reject(str, "=");
if ( !namelen ) { Error::Set(EINVAL); goto cleanup; } if ( !namelen ) { errno = EINVAL; goto cleanup; }
if ( !str[namelen] ) { Error::Set(EINVAL); goto cleanup; } if ( !str[namelen] ) { errno = EINVAL; goto cleanup; }
if ( varlen < namelen ) { Error::Set(EINVAL); goto cleanup; } if ( varlen < namelen ) { errno = EINVAL; goto cleanup; }
size_t valuelen = varlen - 1 /*=*/ - namelen; size_t valuelen = varlen - 1 /*=*/ - namelen;
char* name = String::Substring(str, 0, namelen); char* name = String::Substring(str, 0, namelen);
if ( !name ) { goto cleanup; } if ( !name ) { goto cleanup; }
@ -213,7 +213,7 @@ static DriverEntry* GetDriverEntry(const char* drivername)
return drivers + i; return drivers + i;
} }
} }
Error::Set(ENODRV); errno = ENODRV;
return NULL; return NULL;
} }
@ -221,10 +221,10 @@ static bool StartUpDriver(VideoDriver* driver, const char* drivername)
{ {
if ( !driver->StartUp() ) if ( !driver->StartUp() )
{ {
int errnum = Error::Last(); int errnum = errno;
Log::PrintF("Error: Video driver '%s' was unable to startup\n", Log::PrintF("Error: Video driver '%s' was unable to startup\n",
drivername); drivername);
Error::Set(errnum); errno = errnum;
return false; return false;
} }
return true; return true;
@ -235,10 +235,10 @@ static bool ShutDownDriver(VideoDriver* driver, const char* drivername)
textbufhandle->Replace(NULL); textbufhandle->Replace(NULL);
if ( !driver->ShutDown() ) if ( !driver->ShutDown() )
{ {
int errnum = Error::Last(); int errnum = errno;
Log::PrintF("Warning: Video driver '%s' did not shutdown cleanly\n", Log::PrintF("Warning: Video driver '%s' did not shutdown cleanly\n",
drivername); drivername);
Error::Set(errnum); errno = errnum;
return false; return false;
} }
return true; return true;
@ -250,10 +250,10 @@ static bool DriverModeAction(VideoDriver* driver, const char* drivername,
textbufhandle->Replace(NULL); textbufhandle->Replace(NULL);
if ( !driver->SwitchMode(mode) ) if ( !driver->SwitchMode(mode) )
{ {
int errnum = Error::Last(); int errnum = errno;
Log::PrintF("Error: Video driver '%s' could not %s mode '%s'\n", Log::PrintF("Error: Video driver '%s' could not %s mode '%s'\n",
drivername, action, mode); drivername, action, mode);
Error::Set(errnum); errno = errnum;
return false; return false;
} }
textbufhandle->Replace(driver->CreateTextBuffer()); textbufhandle->Replace(driver->CreateTextBuffer());
@ -309,7 +309,7 @@ static bool DoSwitchMode(DriverEntry* newdrvent, const char* newmode)
if ( !StartUpDriver(newdriver, newdrivername) ) if ( !StartUpDriver(newdriver, newdrivername) )
{ {
errnum = Error::Last(); errnum = errno;
goto restore_prev_driver; goto restore_prev_driver;
} }
@ -317,7 +317,7 @@ static bool DoSwitchMode(DriverEntry* newdrvent, const char* newmode)
if ( !SwitchDriverMode(newdriver, newdrivername, newmode) ) if ( !SwitchDriverMode(newdriver, newdrivername, newmode) )
{ {
errnum = Error::Last(); errnum = errno;
ShutDownDriver(newdriver, newdrivername); ShutDownDriver(newdriver, newdrivername);
currentdrvid = SIZE_MAX; currentdrvid = SIZE_MAX;
goto restore_prev_driver; goto restore_prev_driver;
@ -348,7 +348,7 @@ restore_prev_driver:
error_out: error_out:
if ( currentdrvid == SIZE_MAX ) if ( currentdrvid == SIZE_MAX )
Log::PrintF("Warning: Could not fall back upon a video driver\n"); Log::PrintF("Warning: Could not fall back upon a video driver\n");
Error::Set(errnum); // Return the original error, not the last one. errno = errnum; // Return the original error, not the last one.
return false; return false;
} }
@ -410,7 +410,7 @@ off_t FrameSize()
{ {
ScopedLock lock(&videolock); ScopedLock lock(&videolock);
DriverEntry* drvent = CurrentDriverEntry(); DriverEntry* drvent = CurrentDriverEntry();
if ( !drvent ) { Error::Set(EINVAL); return -1; } if ( !drvent ) { errno = EINVAL; return -1; }
return drvent->driver->FrameSize(); return drvent->driver->FrameSize();
} }
@ -418,7 +418,7 @@ ssize_t WriteAt(off_t off, const void* buf, size_t count)
{ {
ScopedLock lock(&videolock); ScopedLock lock(&videolock);
DriverEntry* drvent = CurrentDriverEntry(); DriverEntry* drvent = CurrentDriverEntry();
if ( !drvent ) { Error::Set(EINVAL); return -1; } if ( !drvent ) { errno = EINVAL; return -1; }
return drvent->driver->WriteAt(off, buf, count); return drvent->driver->WriteAt(off, buf, count);
} }
@ -426,7 +426,7 @@ ssize_t ReadAt(off_t off, void* buf, size_t count)
{ {
ScopedLock lock(&videolock); ScopedLock lock(&videolock);
DriverEntry* drvent = CurrentDriverEntry(); DriverEntry* drvent = CurrentDriverEntry();
if ( !drvent ) { Error::Set(EINVAL); return -1; } if ( !drvent ) { errno = EINVAL; return -1; }
return drvent->driver->ReadAt(off, buf, count); return drvent->driver->ReadAt(off, buf, count);
} }

View file

@ -27,9 +27,9 @@
#include <sortix/kernel/kthread.h> #include <sortix/kernel/kthread.h>
#include <sortix/kernel/memorymanagement.h> #include <sortix/kernel/memorymanagement.h>
#include <sortix/mman.h> #include <sortix/mman.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "multiboot.h" #include "multiboot.h"
#include "memorymanagement.h" #include "memorymanagement.h"
#include "syscall.h" #include "syscall.h"
@ -289,7 +289,7 @@ namespace Sortix
{ {
assert(least < ideal); assert(least < ideal);
size_t available = stackused - stackreserved; size_t available = stackused - stackreserved;
if ( least < available ) { Error::Set(ENOMEM); return false; } if ( least < available ) { errno = ENOMEM; return false; }
if ( available < ideal ) { ideal = available; } if ( available < ideal ) { ideal = available; }
stackreserved += ideal; stackreserved += ideal;
*counter += ideal; *counter += ideal;
@ -335,7 +335,7 @@ namespace Sortix
assert(stackreserved <= stackused); assert(stackreserved <= stackused);
if ( unlikely(stackreserved == stackused) ) if ( unlikely(stackreserved == stackused) )
{ {
Error::Set(ENOMEM); errno = ENOMEM;
return 0; return 0;
} }
addr_t result = STACK[--stackused]; addr_t result = STACK[--stackused];