1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00

errno & rc's & shell errors

This commit is contained in:
Julian Barathieu 2021-03-04 20:05:53 +01:00
parent 8296688060
commit 8d61c9b5e0
No known key found for this signature in database
GPG Key ID: 381DDCD8FF88E34F
15 changed files with 136 additions and 130 deletions

View File

@ -27,36 +27,37 @@
//----------------------------------------------------------------------------//
#ifndef _eentry
#define _estart enum {
#define _eentry(code, desc) code,
#define _eentry(code, desc) code,
#define _eend _EMAX };
#ifndef _EENTRY
#define _ESTART enum {
#define _EENTRY(code, num, desc) code = num,
#define _EEND };
#endif
_estart
_eentry(EOK, "No error")
_eentry(EPERM, "Operation not permitted")
_eentry(ENOENT, "No such entry, file, or directory")
_eentry(ESRCH, "No such process or thread")
_eentry(EINTR, "Operation interrupted")
_eentry(EIO, "I/O error")
_eentry(ENXIO, "No such device or address")
_eentry(E2BIG, "List too long")
_eentry(ENOEXEC, "Not an executable format")
_eentry(EBADF, "Bad file, fd, or stream")
_eentry(EAGAIN, "Try again")
_eentry(ENOMEM, "Not enough memory")
_eentry(EINVAL, "Invalid argument value")
_eentry(ENOSYS, "Functionality not implemented")
_eentry(EADDRINUSE, "Address in use")
_eentry(EFAILED, "Failure (unspecified reason)")
_eentry(EALIGN, "Alignment error or fault")
_eentry(EENDF, "End of file or stream")
_eend
_ESTART
_EENTRY(EOK, -0, "No error")
_EENTRY(EPERM, -1, "Operation not permitted")
_EENTRY(ENOENT, -2, "No such entry, file, or directory")
_EENTRY(ESRCH, -3, "No such process or thread")
_EENTRY(EINTR, -4, "Operation interrupted")
_EENTRY(EIO, -5, "I/O error")
_EENTRY(ENXIO, -6, "No such device or address")
_EENTRY(E2BIG, -7, "List too long")
_EENTRY(ENOEXEC, -8, "Not an executable format")
_EENTRY(EBADF, -9, "Bad file, fd, or stream")
_EENTRY(EAGAIN, -10, "Try again")
_EENTRY(ENOMEM, -11, "Not enough memory")
_EENTRY(EINVAL, -12, "Invalid argument value")
_EENTRY(ENOSYS, -13, "Functionality not implemented")
_EENTRY(EADDRINUSE, -14, "Address in use")
_EENTRY(EFAILED, -15, "Failure (unspecified reason)")
_EENTRY(EALIGN, -16, "Alignment error or fault")
_EENTRY(EENDF, -17, "End of file or stream")
_EENTRY(_EMAX, -18, "... min error id ...")
_EEND
#undef _estart
#undef _eentry
#undef _eend
#undef _ESTART
#undef _EENTRY
#undef _EEND
#endif

View File

@ -51,7 +51,7 @@ typedef unsigned long uintptr_t;
typedef signed long intmax_t;
typedef unsigned long uintmax_t;
typedef uint error_t;
typedef int error_t;
typedef __builtin_va_list va_list;
//----------------------------------------------------------------------------//

View File

@ -114,7 +114,7 @@ void IoCreateInputBuffer(void)
rc = BOpenPureBuf(&BStdIn, BS_RDWR, 4 * KB);
if (rc) KeStartPanic("[Keyb] Couldn't create BStdIn");
if (rc < EOK) KeStartPanic("[Keyb] Couldn't create BStdIn");
//BEnableLineBuffering(BStdIn);
BStdIn->flusher = bemptybuf;

View File

@ -53,7 +53,7 @@ error_t KalAllocMemoryEx(void **ptr, size_t req, int flags, size_t align)
MmUnlockHeap();
if (rc) {
if (rc < EOK) {
if ((flags & M_CANFAIL) != 0)
return rc;
KeStartPanic("KalAllocMemory: Out of memory");

View File

@ -41,7 +41,7 @@ void MmInitMemoryMap(void)
rc = InitMemoryMap();
if (rc)
if (rc < EOK)
KeStartPanic("Failed to initialize the memory map\nError : %s",
strerror(rc) );
}

View File

@ -51,16 +51,20 @@ void ExecuteCommand(char *cmdbuf, Command_t *cmdtable)
memzero(*shargv, ARG_MAX);
rc = ShCmdLineToArgVec(cmdbuf, &shargc, argvbuf);
if (rc) KeStartPanic("Shell: Couldn't parse command line: %d", rc);
if (rc < EOK) KeStartPanic("Shell: Couldn't parse command line: %d", rc);
for (cmd = cmdtable; cmd->name != NULL; cmd++) {
if (!strcmp(cmd->name, shargv[0])) {
cmd->func(shargc, shargv, cmdbuf);
rc = cmd->func(shargc, shargv, cmdbuf);
found = true;
break;
}
}
if (found && rc < EOK) {
KernLog("\nerr: %s: return with error code %d: %s\n", cmd->name, rc, strerror(rc));
}
assert(shargv[0] == argvbuf + ARG_MAX);
if (found == false) {
@ -90,7 +94,6 @@ void ShStartShell(void)
int historyScroll = 0;
bool insertMode = 0;
size_t nLines;
argvbuf = malloc(ARG_MAX * 2);
memzero(argvbuf, ARG_MAX * 2);
@ -103,7 +106,7 @@ void ShStartShell(void)
KernLog("\n%C%s%C", VGA_COLOR_WHITE, shprompt, shcol);
BFlushBuf(BStdOut);
while ((rc = BGetFromBuf(BStdIn, &ch)) == EOK || rc == EENDF) {
while ((rc = BGetFromBuf(BStdIn, &ch)) >= EOK || rc == EENDF) {
// Reset BStdIn's content
if (rc == EENDF) {
if (!(BStdIn->flags & BF_ERR)) {

View File

@ -82,7 +82,7 @@ error_t bgetc(Buffer_t *buf, uchar *ch)
*ch = *buf->rp++;
}
if (rc != EOK) {
if (rc < EOK) {
// buf->flags |= BF_ERR;
}

View File

@ -111,7 +111,7 @@ error_t BOpenTermBufEx(Buffer_t **pbuf, char *source, int mode,
rc = BOpenPureBufEx(pbuf, source, mode, size, flusher);
if (!rc) {
if (!(rc < 0)) {
(*pbuf)->lastLF = 0;
(*pbuf)->nLines = nLines;
(*pbuf)->lineLen = lineLen;

View File

@ -111,7 +111,7 @@ size_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
}
// Progress in format string
while (*fmt && !rc) {
while (*fmt && !(rc < EOK)) {
// Deal with all non-'%' characters
if (*fmt != '%') {
@ -249,7 +249,7 @@ size_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
// Zero/nonspecified precision means unlimited amount
if (prec == 0) prec = INT_MAX;
for (; !rc && *s && prec-- ; s++) {
for (; !(rc < EOK) && *s && prec-- ; s++) {
rc = bputc(buf, (uchar)*s);
written++;
}
@ -353,7 +353,7 @@ size_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
// When padding with spaces, we pad before +/-'s etc
if (!minus && !zero && width > len) {
for (; !rc && width > len ; width--) {
for (; !(rc < EOK) && width > len ; width--) {
rc = bputc(buf, ' ');
written++;
}
@ -369,7 +369,7 @@ size_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
rc = bputc(buf, '0');
written++;
if (!rc && base != 8) {
if (!(rc < EOK) && base != 8) {
rc = bputc(buf, (base == 2 ? 'b' : (cap ? 'X' : 'x')));
written++;
}
@ -378,21 +378,21 @@ size_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
// Deal with padding by zeroes
// The 'minus' flag makes no sense with the 'zero' one
if (zero && width > len) {
for (; !rc && width > len ; width--) {
for (; !(rc < EOK) && width > len ; width--) {
rc = bputc(buf, '0');
written++;
}
}
// Output the actual number
for (; !rc && *s ; s++) {
for (; !(rc < EOK) && *s ; s++) {
rc = bputc(buf, (uchar)*s);
written++;
}
// 'minus' padding, only with spaces
if (minus && !zero && width > len) {
for (; !rc && width > len ; width--) {
for (; !(rc < EOK) && width > len ; width--) {
rc = bputc(buf, ' ');
written++;
}
@ -402,10 +402,10 @@ size_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
}
// For debugging purposes
assert(!rc && "vbprintf() error");
assert(!(rc < EOK) && "vbprintf() error");
seterrno(rc);
if (rc)
if (rc < EOK)
return written - 1; // "- 1" because last bputc() must have failed
else
return written;

View File

@ -137,7 +137,7 @@ error_t bputc(Buffer_t *buf, uchar ch)
}
}
if (rc != EOK) {
if (rc < EOK) {
// buf->flags |= BF_ERR;
}

View File

@ -85,7 +85,7 @@ size_t vbscanf(Buffer_t *buf, const char *fmt, va_list ap)
}
// Progress in format string
for (*fmt && !rc) {
for (*fmt && !(rc < EOK)) {
// Skip all kinds of whitespaces
if (isspace(*fmt)) {
@ -93,7 +93,7 @@ size_t vbscanf(Buffer_t *buf, const char *fmt, va_list ap)
another_space:
rc = bgetc(buf, &ch);
if (!rc) break;
if (!(rc < EOK)) break;
// Put back non-whitespaces and progress
if (!isspace(ch)) {
@ -110,7 +110,7 @@ size_t vbscanf(Buffer_t *buf, const char *fmt, va_list ap)
rc = bgetc(buf, &ch);
// Is it what we expected?
if (!rc && ch != *fmt) {
if (!(rc < EOK) && ch != *fmt) {
// No, so put it back
buf->rp--;
break;
@ -131,7 +131,7 @@ size_t vbscanf(Buffer_t *buf, const char *fmt, va_list ap)
if (*fmt == '%') {
rc = bgetc(buf, &ch);
if (!rc && ch != '%') {
if (!(rc < EOK) && ch != '%') {
buf->rp--;
break;
}
@ -183,7 +183,7 @@ size_t vbscanf(Buffer_t *buf, const char *fmt, va_list ap)
// then store them in successive argument pointers
for (; width; width--) {
rc = bgetc(buf, &ch);
if (!rc) break;
if (!(rc < EOK)) break;
char *chptr = va_arg(ap, char *);
*chptr = (char)ch;
@ -198,7 +198,7 @@ size_t vbscanf(Buffer_t *buf, const char *fmt, va_list ap)
}
// For debugging purposes
assert(!rc && "vbscanf() error");
assert(!(rc < EOK) && "vbscanf() error");
seterrno(rc);
return readcnt;
@ -208,4 +208,3 @@ size_t vbscanf(Buffer_t *buf, const char *fmt, va_list ap)
#endif

View File

@ -25,11 +25,11 @@
#include <libc.h>
#undef _ERRNO_H
#define _estart
#define _eentry(code, desc) [code] = desc,
#define _eend
#define _ESTART
#define _EENTRY(code, num, desc) [-code] = desc,
#define _EEND
char *__strerror[_EMAX] = {
char *__strerror[] = {
#include <errno.h>
@ -37,6 +37,9 @@ char *__strerror[_EMAX] = {
const char *strerror(error_t code)
{
return __strerror[code];
if (code > 0 || code <= _EMAX)
return NULL;
return __strerror[-code];
}

View File

@ -41,7 +41,7 @@ void *malloc(size_t n)
#else
rc = KalAllocMemoryEx(&ptr, n, M_ZEROED, 0);
#endif
if (rc > 0) seterrno(rc);
if (rc < EOK) seterrno(rc);
return ptr;
}
@ -56,7 +56,7 @@ void *memalign(size_t n, size_t align)
#else
rc = KalAllocMemoryEx(&ptr, n, M_ZEROED, align);
#endif
if (rc > 0) seterrno(rc);
if (rc < EOK) seterrno(rc);
return ptr;
}
@ -67,7 +67,7 @@ void *calloc(size_t n, size_t m)
error_t rc;
rc = KalAllocMemoryEx(&ptr, n * m, M_ZEROED, 0);
if (rc > 0) seterrno(rc);
if (rc < EOK) seterrno(rc);
return ptr;
}

View File

@ -92,7 +92,7 @@ size_t vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
rc = BOpenPureBuf(&buf, BS_WRONLY, n-1);
// n-1 to leave place for the '\0'
if (rc != EOK) {
if (rc < EOK) {
goto fail;
}