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.
#include <libmaxsi/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/string.h>
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;
va_list args;
while ( *str )
@ -1092,9 +1091,9 @@ bool ReadParamString(const char* str, ...)
size_t varlen = String::Reject(str, ",");
if ( !varlen ) { str++; continue; }
size_t namelen = String::Reject(str, "=");
if ( !namelen ) { Error::Set(EINVAL); goto cleanup; }
if ( !str[namelen] ) { Error::Set(EINVAL); goto cleanup; }
if ( varlen < namelen ) { Error::Set(EINVAL); goto cleanup; }
if ( !namelen ) { errno = EINVAL; goto cleanup; }
if ( !str[namelen] ) { errno = EINVAL; goto cleanup; }
if ( varlen < namelen ) { errno = EINVAL; goto cleanup; }
size_t valuelen = varlen - 1 /*=*/ - namelen;
char* name = String::Substring(str, 0, namelen);
if ( !name ) { goto cleanup; }

View File

@ -1,4 +1,4 @@
/******************************************************************************
/*******************************************************************************
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
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details.
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/>.
@ -23,15 +23,12 @@
*******************************************************************************/
#define __SORTIX_STDLIB_REDIRECTS 0
#include <libmaxsi/platform.h>
#include <libmaxsi/error.h>
#include <errno.h>
#include <stddef.h>
#ifndef SORTIX_KERNEL
#include <stdio.h>
#endif
namespace Maxsi {
namespace Error {
extern "C" { int global_errno = 0; }
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);
}
} // namespace Error
} // namespace Maxsi

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -31,11 +31,11 @@
#include <sortix/fork.h>
#include <sortix/mman.h>
#include <sortix/wait.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h>
#include <libmaxsi/string.h>
#include <libmaxsi/sortedlist.h>
#include <assert.h>
#include <errno.h>
#include "thread.h"
#include "process.h"
#include "device.h"
@ -325,12 +325,12 @@ namespace Sortix
pid_t Process::Wait(pid_t thepid, int* status, int options)
{
// 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);
// 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.
if ( 0 < thepid )
@ -344,7 +344,7 @@ namespace Sortix
for ( Process* p = zombiechild; !found && p; p = p->nextsibling )
if ( p->pid == thepid )
found = true;
if ( !found ) { Error::Set(ECHILD); return -1; }
if ( !found ) { errno = ECHILD; return -1; }
}
Process* zombie = NULL;
@ -360,7 +360,7 @@ namespace Sortix
zombiewaiting++;
unsigned long r = kthread_cond_wait_signal(&zombiecond, &childlock);
zombiewaiting--;
if ( !r ) { Error::Set(EINTR); return -1; }
if ( !r ) { errno = EINTR; return -1; }
}
if ( zombie->prevsibling )
@ -418,7 +418,7 @@ namespace Sortix
// TODO: How to handle signals that kill the process?
if ( firstthread )
return firstthread->DeliverSignal(signum);
Error::Set(EINIT);
errno = EINIT;
return false;
}
@ -570,14 +570,14 @@ namespace Sortix
DevBuffer* OpenProgramImage(const char* progname, const char* wd, const char* path)
{
char* abs = Directory::MakeAbsolute("/", progname);
if ( !abs ) { Error::Set(ENOMEM); return NULL; }
if ( !abs ) { errno = ENOMEM; return NULL; }
// TODO: Use O_EXEC here!
Device* dev = FileSystem::Open(abs, O_RDONLY, 0);
delete[] abs;
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;
}
@ -630,9 +630,9 @@ namespace Sortix
dev->Refer(); // TODO: Rules of GC may change soon.
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;
buffer = new uint8_t[count];
@ -642,7 +642,7 @@ namespace Sortix
{
ssize_t bytesread = dev->Read(buffer + sofar, count - sofar);
if ( bytesread < 0 ) { goto cleanup_buffer; }
if ( bytesread == 0 ) { Error::Set(EEOF); return -1; }
if ( bytesread == 0 ) { errno = EEOF; return -1; }
sofar += bytesread;
}
@ -668,10 +668,10 @@ namespace Sortix
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).
if ( flags != SFFORK ) { Error::Set(ENOSYS); return -1; }
if ( flags != SFFORK ) { errno = ENOSYS; return -1; }
CPU::InterruptRegisters cpuregs;
InitializeThreadRegisters(&cpuregs, regs);
@ -799,10 +799,10 @@ namespace Sortix
if ( dataseg && iter->position < dataseg->position ) { continue; }
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 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 )
{
addr_t unmapfrom = Page::AlignUp(newend);

View File

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

View File

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

View File

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

View File

@ -27,9 +27,9 @@
#include <sortix/kernel/memorymanagement.h>
#include <sortix/mman.h>
#include <sortix/signal.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h>
#include <assert.h>
#include <errno.h>
#include "process.h"
#include "thread.h"
#include "scheduler.h"
@ -258,7 +258,7 @@ namespace Sortix
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);
signalqueue.Push(signum);
@ -271,7 +271,7 @@ namespace Sortix
int SysKill(pid_t pid, int signum)
{
// 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.
Thread* currentthread = CurrentThread();
@ -280,7 +280,7 @@ namespace Sortix
// TODO: Race condition: The process could be deleted while we use it.
Process* process = Process::Get(pid);
if ( !process ) { Error::Set(ESRCH); return -1; }
if ( !process ) { errno = ESRCH; return -1; }
// TODO: Protect init?
// TODO: Check for permission.

View File

@ -23,7 +23,7 @@
******************************************************************************/
#include <sortix/kernel/platform.h>
#include <libmaxsi/error.h>
#include <errno.h>
#include "utf8.h"
using namespace Maxsi;
@ -42,7 +42,7 @@ namespace Sortix
if ( (1U<<16U) <= unicode ) { bytes = 4; bits = 21; }
if ( (1U<<21U) <= unicode ) { bytes = 5; bits = 26; }
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;
unsigned prefixavai;

View File

@ -23,8 +23,8 @@
*******************************************************************************/
#include <sortix/kernel/platform.h>
#include <libmaxsi/error.h>
#include <libmaxsi/memory.h>
#include <errno.h>
#include "fs/util.h"
#include "fs/devfs.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)
{
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; }
Maxsi::Memory::Copy(VGA::VGA + offset, src, count);
offset = (offset + count) % VGA::VGA_SIZE;
@ -221,7 +221,7 @@ uintmax_t DevVGA::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;
return true;
}
@ -229,7 +229,7 @@ bool DevVGA::Seek(uintmax_t position)
bool DevVGA::Resize(uintmax_t size)
{
if ( size == VGA::VGA_SIZE ) { return false; }
Error::Set(ENOSPC);
errno = ENOSPC;
return false;
}

View File

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

View File

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