Compare commits

..

5 Commits

35 changed files with 296 additions and 329 deletions

View File

@@ -47,11 +47,13 @@ vsscanf
ungetc
;____STDLIB____
abs
abort
atoi
atol
atoll
atof
calloc
_exit
exit
free
itoa

View File

@@ -1,8 +1,6 @@
CC = kos32-tcc
AR = ar
CFLAGS = -c -I$(LIBC_INCLUDE)
LIBC_INCLUDE = ../../libc.obj/include
CFLAGS = -c -I../../libc.obj/include
LIB = libshell.a
@@ -16,8 +14,7 @@ OBJS = \
shell_init.o \
shell_gets.o \
shell_printf.o \
shell_putc.o \
shell_write_string.o
shell_putc.o
$(LIB): $(OBJS)
$(AR) -crs $@ $(OBJS)
@@ -26,16 +23,4 @@ $(LIB): $(OBJS)
$(CC) $(CFLAGS) -o $@ $<
clean:
rm -rf $(OBJS) $(LIB)
shell_cls.o: shell_cls.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/sys/ksys.h
shell_get_pid.o: shell_get_pid.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/string.h
shell_getc.o: shell_getc.c $(LIBC_INCLUDE)/shell_api.h
shell_gets.o: shell_gets.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/string.h
shell_init.o: shell_init.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/sys/ksys.h $(LIBC_INCLUDE)/string.h $(LIBC_INCLUDE)/stdio.h $(LIBC_INCLUDE)/stdlib.h
shell_ping.o: shell_ping.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/sys/ksys.h
shell_printf.o: shell_printf.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/stdio.h
shell_putc.o: shell_putc.c $(LIBC_INCLUDE)/shell_api.h
shell_puts.o: shell_puts.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/string.h
shell_write_string.o: shell_write_string.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/string.h
rm -rf $(OBJS) $(LIB)

View File

@@ -3,9 +3,6 @@
void shell_cls()
{
__shell_init();
if(__shell_is_init == __SHELL_INIT_OK)
{
*__shell_shm = SHELL_CLS;
*__shell_shm = SHELL_CLS;
__SHELL_WAIT();
}
}

View File

@@ -3,7 +3,7 @@
void shell_exit()
{
if (__shell_is_init == __SHELL_INIT_OK) {
if(__shell_is_init){
*__shell_shm = SHELL_EXIT;
__SHELL_WAIT();
_ksys_shm_close(__shell_shm_name);

View File

@@ -4,14 +4,9 @@
unsigned shell_get_pid()
{
unsigned pid;
__shell_init();
if (__shell_is_init == __SHELL_INIT_OK)
{
*__shell_shm = SHELL_PID;
__SHELL_WAIT();
memcpy(&pid, __shell_shm + 1, sizeof(unsigned));
}
*__shell_shm = SHELL_PID;
__SHELL_WAIT();
memcpy(&pid, __shell_shm+1, sizeof(unsigned));
return pid;
}

View File

@@ -1,16 +1,9 @@
#include <shell_api.h>
#include "shell_api.h"
char shell_getc()
{
__shell_init();
if (__shell_is_init == __SHELL_INIT_OK) {
*__shell_shm = SHELL_GETC;
__SHELL_WAIT();
return *(__shell_shm + 1);
}
else {
return 0;
}
*__shell_shm = SHELL_GETC;
__SHELL_WAIT();
return *(__shell_shm+1);
}

View File

@@ -4,11 +4,7 @@
void shell_gets(char *str, int n)
{
__shell_init();
if (__shell_is_init == __SHELL_INIT_OK) {
*__shell_shm = SHELL_GETS;
*__shell_shm = SHELL_GETS;
__SHELL_WAIT();
strncpy(str, __shell_shm+1, n);
}
}

View File

@@ -5,57 +5,40 @@
#include <shell_api.h>
char app_name[13];
char __shell_shm_name[32];
char *__shell_shm = NULL;
enum __SHELL_INIT_STATE __shell_is_init = __SHELL_NOT_LOADED;
char __shell_shm_name[32];
char*__shell_shm=NULL;
int __shell_is_init=0;
int __shell_shm_init()
{
__shell_is_init = __SHELL_LOADING;
ksys_thread_t proc_info;
__shell_is_init=1;
ksys_thread_t *proc_info = (ksys_thread_t*)malloc(sizeof(ksys_thread_t));
if(proc_info == NULL){
return -1;
}
unsigned PID;
_ksys_thread_info(&proc_info, -1);
PID = proc_info.pid;
strncpy(app_name, (&proc_info)->name, 12);
_ksys_thread_info(proc_info, -1);
PID = proc_info->pid;
strncpy(app_name, proc_info->name, 12);
free(proc_info);
itoa(PID, __shell_shm_name);
strcat(__shell_shm_name, "-SHELL");
return _ksys_shm_open(__shell_shm_name, KSYS_SHM_OPEN_ALWAYS | KSYS_SHM_WRITE, SHELL_SHM_MAX, &__shell_shm);
return _ksys_shm_open(__shell_shm_name, KSYS_SHM_OPEN_ALWAYS | KSYS_SHM_WRITE, SHELL_SHM_MAX, &__shell_shm);
}
void __shell_init()
{
switch (__shell_is_init) {
case __SHELL_NOT_LOADED:
if (__shell_shm_init()) {
debug_printf("%s: shell problems detected!\n", app_name);
goto __shell_init_err;
if(!__shell_is_init){
if(__shell_shm_init()){
debug_printf("%s: shell problems detected!\n", app_name);
_ksys_exit();
}
if (!shell_ping()) {
goto __shell_init_err;
if(!shell_ping()){
debug_printf("%s: no shell found!\n", app_name);
_ksys_exit();
}
__shell_is_init = __SHELL_INIT_OK; // The shell is being pinged, so it's working.
break;
case __SHELL_LOADING:
while (__shell_is_init == __SHELL_LOADING) {
_ksys_thread_yield();
}
case __SHELL_INIT_OK:
if (!shell_ping()) {
goto __shell_init_err;
}
break;
default:
break;
}
return;
__shell_init_err:
__shell_is_init = __SHELL_INIT_FAILED;
shell_exit();
return;
}

View File

@@ -1,24 +1,13 @@
#include <shell_api.h>
#include <sys/ksys.h>
#include <sys/ksys.h>
#define SHELL_PING_TIMEOUT 10 // 0.1 sec
#define SHELL_PING_MIN_DELAY 1
int shell_ping()
{
__shell_init();
*__shell_shm = SHELL_PING;
_ksys_thread_yield(); // hope shell is fast enough
size_t i = 0;
while (*__shell_shm != SHELL_OK){
if (i > (SHELL_PING_TIMEOUT / SHELL_PING_MIN_DELAY)) {
return 0;
}
i++;
_ksys_delay(SHELL_PING_MIN_DELAY);
_ksys_delay(10);
if(*__shell_shm==SHELL_OK){
return 1;
}
return 1;
}
return 0;
}

View File

@@ -1,12 +1,12 @@
#include <shell_api.h>
#include <stdio.h>
void shell_printf(const char *format, ...)
void shell_printf(const char *format,...)
{
va_list ap;
va_start(ap, format);
vsnprintf(__shell_shm + 1, SHELL_SHM_MAX, format, ap);
*__shell_shm = SHELL_PUTS;
va_start (ap, format);
*__shell_shm=SHELL_PUTS;
vsnprintf(__shell_shm+1, SHELL_SHM_MAX, format, ap);
va_end(ap);
__SHELL_WAIT();
}

View File

@@ -3,11 +3,7 @@
void shell_putc(char c)
{
__shell_init();
if (__shell_is_init == __SHELL_INIT_OK)
{
*(__shell_shm + 1) = c;
*__shell_shm = SHELL_PUTC;
__SHELL_WAIT();
}
*__shell_shm = SHELL_PUTC;
*(__shell_shm+1) = c;
__SHELL_WAIT();
}

View File

@@ -3,5 +3,8 @@
void shell_puts(const char *str)
{
shell_write_string(str, strlen(str));
__shell_init();
*__shell_shm = SHELL_PUTS;
strcpy(__shell_shm+1, str);
__SHELL_WAIT();
}

View File

@@ -1,22 +0,0 @@
#include <shell_api.h>
#include <string.h>
void shell_write_string(const char *s, size_t len)
{
__shell_init();
if (__shell_is_init == __SHELL_INIT_OK)
{
if (len > SHELL_SHM_MAX - 1)
{
shell_write_string(s, SHELL_SHM_MAX - 1); // Outputs as much as it can.
shell_write_string(s + (SHELL_SHM_MAX - 1), len - (SHELL_SHM_MAX - 1)); // Outputs the rest.
}
else
{
memset(__shell_shm, 0, SHELL_SHM_MAX); // without int shell show \t, \n, lose chars and other trash
memcpy(__shell_shm + 1, s, len);
*__shell_shm = SHELL_PUTS;
__SHELL_WAIT();
}
}
}

View File

@@ -1,8 +1,4 @@
.vscode/*
.tup/*
.tup
*.o
*.kex
*.obj
*.a
*.tmp
*.kex

View File

@@ -3,12 +3,6 @@
#include <sys/ksys.h>
#ifdef _BUILD_LIBC
#define __EXTERN
#else
#define __EXTERN extern
#endif
#define SHELL_OK 0
#define SHELL_EXIT 1
#define SHELL_PUTC 2
@@ -21,35 +15,25 @@
#define SHELL_SHM_MAX 1024 * 16
enum __SHELL_INIT_STATE {
__SHELL_NOT_LOADED = 0, // not try init shell before
__SHELL_LOADING = 1, // in progress
__SHELL_INIT_OK = 2, // ok
__SHELL_INIT_FAILED = 3 // fail init shell
};
extern char __shell_shm_name[32];
extern char* __shell_shm;
extern int __shell_is_init;
extern void __shell_init();
__EXTERN char __shell_shm_name[32];
__EXTERN char* __shell_shm;
__EXTERN enum __SHELL_INIT_STATE __shell_is_init;
__EXTERN void __shell_init();
#define __SHELL_WAIT() \
while (*__shell_shm) \
_ksys_delay(5)
#define __SHELL_WAIT() \
while (*__shell_shm) { \
_ksys_thread_yield(); \
}
extern int shell_ping();
extern unsigned shell_get_pid();
extern void shell_exit();
__EXTERN int shell_ping();
__EXTERN unsigned shell_get_pid();
__EXTERN void shell_exit();
extern char shell_getc();
extern void shell_gets(char* str, int n);
__EXTERN char shell_getc();
__EXTERN void shell_gets(char* str, int n);
extern void shell_putc(char c);
extern void shell_puts(const char* str);
extern void shell_printf(const char* format, ...);
__EXTERN void shell_putc(char c);
__EXTERN void shell_puts(const char* str);
__EXTERN void shell_printf(const char* format, ...);
__EXTERN void shell_write_string(const char* s, size_t len);
__EXTERN void shell_cls();
extern void shell_cls();
#endif

View File

@@ -48,7 +48,13 @@ DLLAPI void free(void* ptr);
DLLAPI long int strtol(const char* str, char** endptr, int base);
DLLAPI void _exit(int status);
#ifndef _Exit
#define _Exit(status) _exit(status);
#endif
DLLAPI void exit(int status);
DLLAPI void abort();
DLLAPI void srand(unsigned s);
DLLAPI int rand(void);

View File

@@ -27,7 +27,8 @@ BIN = \
libc_test.kex \
pipe.kex \
defgen.kex \
futex.kex
futex.kex \
atexit_test.kex
all: $(BIN)

View File

@@ -0,0 +1,18 @@
#include <stdlib.h>
#include <stdio.h>
void f()
{
static int c = 1;
printf("exit #%d\n", c);
c++;
}
int main()
{
atexit(&f);
atexit(&f);
atexit(&f);
return 0;
}

View File

@@ -23,5 +23,6 @@ cp clayer/logo.png /tmp0/1/tcc_samples/logo.png
../tcc defgen.c -o /tmp0/1/tcc_samples/defgen
../tcc pipe.c -o /tmp0/1/tcc_samples/pipe
../tcc futex.c -o /tmp0/1/tcc_samples/futex
../tcc atexit_test.c -o /tmp0/1/tcc_samples/atexit_test
"/sys/File managers/Eolite" /tmp0/1/tcc_samples
exit

View File

@@ -14,6 +14,7 @@ public start
public start as '_start'
extrn main
extrn exit
include '../../../../../../proc32.inc'
include '../../../../../../macros.inc'
@@ -38,36 +39,36 @@ start:
call push_param
; retrieving parameters
mov esi, params
xor edx, edx ; dl - èä¸ò ïàðàìåòð(1) èëè ðàçäåëèòåëè(0)
; dh - ñèìâîë ñ êîòîðîãî íà÷àëñÿ ïàðàìåòð (1 êàâû÷êè, 0 îñòàëüíîå)
xor edx, edx ; dl - is it a parameter (1) or delimiters (0)
; dh - character with which the parameter started (1 quotes, 0 everything else)
mov ecx, 1 ; cl = 1
; ch = 0 ïðîñòî íîëü
; ch = 0 just zero
.parse:
lodsb
test al, al
jz .run
test dl, dl
jnz .findendparam
;{åñëè áûë ðàçäåëèòåëü
;{if it was a delimiter
cmp al, ' '
jz .parse ;çàãðóæåí ïðîáåë, ãðóçèì ñëåäóþùèé ñèìâîë
mov dl, cl ;íà÷èíàåòñÿ ïàðàìåòð
jz .parse ; space loaded, load next character
mov dl, cl ; parameter starts
cmp al, '"'
jz @f ;çàãðóæåíû êàâû÷êè
mov dh, ch ;ïàðàìåòð áåç êàâû÷åê
jz @f ; quotes loaded
mov dh, ch ; parameter without quotes
dec esi
call push_param
inc esi
jmp .parse
@@:
mov dh, cl ;ïàðàìåòð â êàâû÷åêàõ
call push_param ;åñëè íå ïðîáåë çíà÷èò íà÷èíàåòñÿ êàêîé òî ïàðàìåòð
jmp .parse ;åñëè áûë ðàçäåëèòåëü}
mov dh, cl ; parameter in quotes
call push_param ; if not a space, then some parameter starts
jmp .parse ; if it was a delimiter}
.findendparam:
test dh, dh
jz @f ; áåç êàâû÷åê
jz @f ; without quotes
cmp al, '"'
jz .clear
jmp .parse
@@ -86,10 +87,9 @@ start:
push [argc]
call main
.exit:
xor eax,eax
dec eax
int 0x40
dd -1
push eax
call dword [exit]
dd -1
.crash:
jmp .exit
;============================

View File

@@ -13,7 +13,6 @@
#include "sys/seekdir.c"
#include "sys/socket.c"
#include "sys/telldir.c"
#include "sys/conio.c"
#include "stdio/clearerr.c"
#include "stdio/conio.c"
@@ -83,6 +82,7 @@
#include "string/strstr.c"
#include "string/strtok.c"
#include "string/strxfrm.c"
#include "stdlib/abs.c"
#include "stdlib/assert.c"
#include "stdlib/atof.c"
@@ -90,7 +90,9 @@
#include "stdlib/atol.c"
#include "stdlib/atoll.c"
#include "stdlib/calloc.c"
#include "stdlib/atexit.c"
#include "stdlib/exit.c"
#include "stdlib/_exit.c"
#include "stdlib/free.c"
#include "stdlib/itoa.c"
#include "stdlib/labs.c"
@@ -101,6 +103,7 @@
#include "stdlib/realloc.c"
#include "stdlib/strtod.c"
#include "stdlib/strtol.c"
#include "stdlib/abort.c"
#include "math/acosh.c"
#include "math/asinh.c"
@@ -121,18 +124,6 @@
#include "misc/basename.c"
#include "misc/dirname.c"
#include "../../lib/libshell/shell_cls.c"
#include "../../lib/libshell/shell_exit.c"
#include "../../lib/libshell/shell_get_pid.c"
#include "../../lib/libshell/shell_getc.c"
#include "../../lib/libshell/shell_gets.c"
#include "../../lib/libshell/shell_init.c"
#include "../../lib/libshell/shell_ping.c"
#include "../../lib/libshell/shell_printf.c"
#include "../../lib/libshell/shell_putc.c"
#include "../../lib/libshell/shell_puts.c"
#include "../../lib/libshell/shell_write_string.c"
ksys_dll_t EXPORTS[] = {
{ "clearerr", &clearerr },
{ "debug_printf", &debug_printf },
@@ -183,7 +174,9 @@ ksys_dll_t EXPORTS[] = {
{ "atoll", &atoll },
{ "atof", &atof },
{ "calloc", &calloc },
{ "_exit", &_exit },
{ "exit", &exit },
{ "abort", &abort },
{ "free", &free },
{ "itoa", &itoa },
{ "labs", &labs },

View File

@@ -73,5 +73,3 @@ int con_init(void)
return con_init_opt(-1, -1, -1, -1, __con_caption);
}

View File

@@ -1,6 +1,6 @@
#include <stdio.h>
#include <errno.h>
#include "../sys/_conio.h"
#include "conio.h"
#include "sys/ksys.h"
size_t fread(void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream) {
@@ -19,7 +19,8 @@ size_t fread(void *restrict ptr, size_t size, size_t nmemb, FILE *restrict strea
}
if(stream==stdin){
console_gets((char*)ptr, bytes_count+1);
con_init();
con_gets((char*)ptr, bytes_count+1);
return nmemb;
}

View File

@@ -1,46 +1,45 @@
#include <stdio.h>
#include "../sys/_conio.h"
#include "conio.h"
#include <sys/ksys.h>
#include <errno.h>
#include <shell_api.h>
size_t fwrite(const void* restrict ptr, size_t size, size_t nmemb, FILE* restrict stream)
{
unsigned bytes_written = 0;
unsigned bytes_count = size * nmemb;
if (!stream) {
errno = EBADF;
return 0;
}
if (size <= 0 || nmemb <= 0) {
errno = EINVAL;
stream->error = errno;
return 0;
}
if (stream == stdout) {
console_write((char*)ptr, size);
return nmemb;
}
if (stream == stderr) {
for (size_t i = 0; i < bytes_count; i++) {
char c = *(char*)(ptr + i);
_ksys_debug_putc(c);
}
return nmemb;
}
if (stream->mode != _FILEMODE_R) {
unsigned status = _ksys_file_write_file(stream->name, stream->position, bytes_count, ptr, &bytes_written);
if (status != KSYS_FS_ERR_SUCCESS) {
errno = EIO;
stream->error = errno;
return 0;
}
stream->position += bytes_written;
}
return bytes_written / size;
size_t fwrite(const void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream) {
unsigned bytes_written = 0;
unsigned bytes_count = size * nmemb;
if(!stream){
errno = EBADF;
return 0;
}
if(size<=0 || nmemb<=0){
errno = EINVAL;
stream->error=errno;
return 0;
}
if(stream==stdout){
con_init();
con_write_string((char*)ptr, bytes_count);
return nmemb;
}
if(stream==stderr){
for (size_t i = 0; i < bytes_count; i++) {
char c = *(char*)(ptr+i);
_ksys_debug_putc(c);
}
return nmemb;
}
if(stream->mode != _FILEMODE_R){
unsigned status = _ksys_file_write_file(stream->name, stream->position, bytes_count, ptr, &bytes_written);
if (status != KSYS_FS_ERR_SUCCESS) {
errno = EIO;
stream->error = errno;
return 0;
}
stream->position+=bytes_written;
}
return bytes_written/size;
}

View File

@@ -1,10 +1,10 @@
#include <stdio.h>
#include "../sys/_conio.h"
#include <conio.h>
int getchar(void) {
con_init();
char c = 0;
console_gets(&c, 2);
con_gets(&c, 2);
if (c == 0) {
c = EOF;
}

View File

@@ -4,16 +4,17 @@
#include <errno.h>
#include <limits.h>
char* gets(char* str)
char *gets(char* str)
{
if (console_gets(str, STDIO_MAX_MEM) == NULL) {
con_init();
if(con_gets(str, STDIO_MAX_MEM)==NULL){
errno = EIO;
return NULL;
}
int str_len = strlen(str);
if (str[str_len - 1] == '\n') {
str[str_len - 1] = '\0';
if(str[str_len-1]=='\n'){
str[str_len-1]='\0';
}
return str;
}

View File

@@ -4,13 +4,11 @@
#include <stdio.h>
#include <stdlib.h>
// #include "format_print.h"
//#include "format_print.h"
int printf(const char* format, ...)
int printf(const char *format, ...)
{
va_list arg;
va_start(arg, format);
int ret = vprintf(format, arg);
va_end(arg);
return ret;
va_list arg;
va_start(arg, format);
return vprintf(format, arg);
}

View File

@@ -2,12 +2,13 @@
#include <stdio.h>
#include <string.h>
#include "../sys/_conio.h"
#include <sys/ksys.h>
#include "conio.h"
#include "sys/ksys.h"
int puts(const char *str)
{
size_t len = strlen(str);
console_write(str, len);
return len;
}
con_init();
con_write_asciiz(str);
con_write_asciiz("\n");
return strlen(str);
}

View File

@@ -4,7 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "../sys/_conio.h"
#include "conio.h"
#include <sys/ksys.h>
#include <errno.h>
#include <limits.h>
@@ -22,9 +22,9 @@ int vprintf(const char* format, va_list arg)
errno = ENOMEM;
return errno;
}
con_init();
len = vsnprintf(s, STDIO_MAX_MEM, format, arg);
console_write(s, len);
con_write_string(s, len);
free(s);
return (len);
}

View File

@@ -0,0 +1,26 @@
#include <conio.h>
#include <stdio.h>
#include <sys/ksys.h>
void _exit(int status)
{
__libc_exit(status, NULL);
}
void __libc_exit(int status, void (*before_exit)(int status))
{
// return error and this is not abort
if (status && status != 128) {
fprintf(stderr, "\nexit code: %d\n", status);
}
if (before_exit) {
before_exit(status);
}
if (__con_is_load) {
con_exit(0);
}
_ksys_exit();
}

View File

@@ -0,0 +1,17 @@
/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/ksys.h>
void abort()
{
ksys_thread_t t;
_ksys_thread_info(&t, -1);
fprintf(stderr, "\nAbort in %d\n", t.pid);
_exit(128);
}

View File

@@ -0,0 +1,40 @@
/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
*/
#include <stdlib.h>
struct atexit_n {
struct atexit_n* last;
void (*func)(void);
};
static struct atexit_n* __last_n = NULL;
int atexit(void (*func)(void))
{
struct atexit_n* n = malloc(sizeof(struct atexit_n));
if (n == NULL) {
return 1;
}
n->last = __last_n;
n->func = func;
__last_n = n;
return 0;
}
void __run_atexit()
{
struct atexit_n* n = __last_n;
while (n != NULL) {
n->func();
struct atexit_n* to_free = n;
n = n->last;
free(to_free);
}
}

View File

@@ -1,10 +1,32 @@
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2021 Logaev Maxim
* Copyright (C) 2026 KolibriOS team
*/
#include "../sys/_conio.h"
#include <stdlib.h>
#include <sys/ksys.h>
#include "_exit.h"
/*
TODO
static void __close_all()
{
}
static void __free_all_mem()
{
}
*/
void __normal_exit(int status)
{
__run_atexit();
__close_all();
__free_all_mem();
}
void exit(int status)
{
console_exit();
_ksys_exit();
__libc_exit(status, &__normal_exit);
}

View File

@@ -1,10 +0,0 @@
#ifndef __LIBC_SYS_CONIO_H_
#define __LIBC_SYS_CONIO_H
char* console_gets(char* buff, size_t len);
void console_write(const char* ptr, size_t len);
void console_exit();
#endif // __LIBC_SYS_CONIO_H

View File

@@ -1,42 +0,0 @@
#include <shell_api.h>
#include <conio.h>
#include "_conio.h"
char* console_gets(char* buff, size_t len)
{
char* ret = buff;
if (__shell_is_init < __SHELL_INIT_FAILED) {
shell_gets(buff, len);
}
if (__shell_is_init == __SHELL_INIT_FAILED) {
con_init();
ret = con_gets(buff, len);
}
return ret;
}
void console_write(const char* ptr, size_t len)
{
if (__shell_is_init < __SHELL_INIT_FAILED) {
shell_write_string(ptr, len);
}
if (__shell_is_init == __SHELL_INIT_FAILED) {
con_init();
con_write_string((char*)ptr, len);
}
}
void console_exit()
{
if (__shell_is_init < __SHELL_INIT_FAILED) {
shell_exit();
}
if (__shell_is_init == __SHELL_INIT_FAILED) {
if (__con_is_load) {
con_exit(0);
}
}
}