2011-08-05 08:25:00 -04:00
|
|
|
/******************************************************************************
|
|
|
|
|
2012-05-27 11:38:00 -04:00
|
|
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
2011-08-05 08:25:00 -04:00
|
|
|
|
|
|
|
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.cpp
|
|
|
|
Error reporting functions and utilities.
|
|
|
|
|
2012-05-27 11:38:00 -04:00
|
|
|
*******************************************************************************/
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2012-05-27 11:38:00 -04:00
|
|
|
#define __SORTIX_STDLIB_REDIRECTS 0
|
2012-02-11 20:03:34 -05:00
|
|
|
#include <libmaxsi/platform.h>
|
|
|
|
#include <libmaxsi/error.h>
|
2011-12-01 08:54:19 -05:00
|
|
|
#ifndef SORTIX_KERNEL
|
2012-02-11 20:03:34 -05:00
|
|
|
#include <libmaxsi/syscall.h>
|
2011-12-01 08:54:19 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2012-05-27 11:38:00 -04:00
|
|
|
namespace Maxsi {
|
|
|
|
namespace Error {
|
|
|
|
|
2012-03-26 16:22:59 -04:00
|
|
|
extern "C" { int global_errno = 0; }
|
|
|
|
extern "C" { errno_location_func_t errno_location_func = NULL; }
|
2011-11-22 11:26:47 -05:00
|
|
|
|
2011-12-01 08:54:19 -05:00
|
|
|
#ifndef SORTIX_KERNEL
|
2012-05-27 11:38:00 -04:00
|
|
|
DEFN_SYSCALL1(int, SysRegisterErrno, SYSCALL_REGISTER_ERRNO, int*);
|
2011-12-01 08:54:19 -05:00
|
|
|
|
2012-05-27 11:38:00 -04:00
|
|
|
extern "C" void init_error_functions()
|
|
|
|
{
|
2012-03-26 16:22:59 -04:00
|
|
|
global_errno = 0;
|
|
|
|
SysRegisterErrno(&global_errno);
|
2012-05-27 11:38:00 -04:00
|
|
|
}
|
2011-12-01 08:54:19 -05:00
|
|
|
#endif
|
2011-11-22 11:26:47 -05:00
|
|
|
|
2012-03-26 16:22:59 -04:00
|
|
|
extern "C" int* get_errno_location(void)
|
|
|
|
{
|
|
|
|
if ( errno_location_func ) { return errno_location_func(); }
|
|
|
|
return &global_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void set_errno_location_func(errno_location_func_t func)
|
|
|
|
{
|
|
|
|
errno_location_func = func;
|
|
|
|
}
|
|
|
|
|
2012-05-27 11:38:00 -04:00
|
|
|
extern "C" const char* sortix_strerror(int errnum)
|
|
|
|
{
|
|
|
|
switch ( errnum )
|
|
|
|
{
|
|
|
|
case ENOTBLK: return "Block device required";
|
|
|
|
case ENODEV: return "No such device";
|
|
|
|
case EWOULDBLOCK: return "Operation would block";
|
|
|
|
case EBADF: return "Bad file descriptor";
|
|
|
|
case EOVERFLOW: return "Value too large to be stored in data type";
|
|
|
|
case ENOENT: return "No such file or directory";
|
|
|
|
case ENOSPC: return "No space left on device";
|
|
|
|
case EEXIST: return "File exists";
|
|
|
|
case EROFS: return "Read-only file system";
|
|
|
|
case EINVAL: return "Invalid argument";
|
|
|
|
case ENOTDIR: return "Not a directory";
|
|
|
|
case ENOMEM: return "Not enough memory";
|
|
|
|
case ERANGE: return "Result too large";
|
|
|
|
case EISDIR: return "Is a directory";
|
|
|
|
case EPERM: return "Operation not permitted";
|
|
|
|
case EIO: return "Input/output error";
|
|
|
|
case ENOEXEC: return "Exec format error";
|
|
|
|
case EACCES: return "Permission denied";
|
|
|
|
case ESRCH: return "No such process";
|
|
|
|
case ENOTTY: return "Not a tty";
|
|
|
|
case ECHILD: return "No child processes";
|
|
|
|
case ENOSYS: return "Function not implemented";
|
|
|
|
case ENOTSUP: return "Operation not supported";
|
|
|
|
case EBLOCKING: return "Operation is blocking";
|
|
|
|
case EINTR: return "Interrupted function call";
|
|
|
|
case ENOTEMPTY: return "Directory not empty";
|
|
|
|
case EBUSY: return "Device or resource busy";
|
|
|
|
case EPIPE: return "Broken pipe";
|
|
|
|
case EILSEQ: return "Illegal byte sequence";
|
|
|
|
case ELAKE: return "Sit by a lake";
|
|
|
|
case EMFILE: return "Too many open files";
|
|
|
|
case EAGAIN: return "Resource temporarily unavailable";
|
|
|
|
case EEOF: return "End of file";
|
|
|
|
case EBOUND: return "Out of bounds";
|
|
|
|
case EINIT: return "Not initialized";
|
2012-05-27 08:28:33 -04:00
|
|
|
case ENODRV: return (char*) "No such driver";
|
2012-05-27 11:38:00 -04:00
|
|
|
default: return "Unknown error condition";
|
2011-08-05 08:25:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-27 11:38:00 -04:00
|
|
|
extern "C" char* strerror(int errnum)
|
|
|
|
{
|
|
|
|
return (char*) sortix_strerror(errnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Error
|
|
|
|
} // namespace Maxsi
|