forked from KolibriOS/kolibrios
kolibri-libc:
- Added shell_ping - Added shell_get_pid - Fixed malloc in stdlib.h - Added check during SHELL init (uses shell_ping) - getc is used like fgetc git-svn-id: svn://kolibrios.org@8635 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
cae5f61bc5
commit
c1e6562f35
@ -4,6 +4,7 @@
|
||||
|
||||
int main(int argc, char**argv)
|
||||
{
|
||||
debug_printf("%u\n", shell_get_pid());
|
||||
char string[256];
|
||||
shell_cls();
|
||||
shell_printf("Number of arguments %d\n",argc);
|
||||
|
@ -10,5 +10,6 @@ extern char _FUNC(shell_getc)();
|
||||
extern void _FUNC(shell_gets)(char *str);
|
||||
extern void _FUNC(shell_cls)();
|
||||
extern void _FUNC(shell_exit)();
|
||||
|
||||
extern unsigned _FUNC(shell_get_pid)();
|
||||
extern int _FUNC(shell_ping)();
|
||||
#endif
|
@ -98,6 +98,7 @@ extern size_t _FUNC(fread)(void *restrict, size_t size, size_t count, FILE *rest
|
||||
extern int _FUNC(fscanf)(FILE *restrict, const char *restrict, ...);
|
||||
extern size_t _FUNC(fwrite)(const void *restrict, size_t size, size_t count, FILE *restrict);
|
||||
extern int _FUNC(getc)(FILE *);
|
||||
#define getc _FUNC(fgetc)
|
||||
extern int _FUNC(getchar)(void);
|
||||
extern int _FUNC(printf)(const char *restrict, ...);
|
||||
extern int _FUNC(putc)(int, FILE *);
|
||||
|
@ -28,7 +28,7 @@ extern div_t _FUNC(div)(int, int);
|
||||
extern ldiv_t _FUNC(ldiv)(long, long);
|
||||
extern lldiv_t _FUNC(lldiv)(long long, long long);
|
||||
|
||||
extern void _FUNC(*malloc)(size_t size);
|
||||
extern void* _FUNC(malloc)(size_t size);
|
||||
extern void* _FUNC(calloc)(size_t num, size_t size);
|
||||
extern void* _FUNC(realloc)(void *ptr, size_t newsize);
|
||||
extern void _FUNC(free)(void *ptr);
|
||||
|
@ -8,13 +8,15 @@
|
||||
#define SHELL_GETC 4
|
||||
#define SHELL_GETS 5
|
||||
#define SHELL_CLS 6
|
||||
#define SHELL_PID 7
|
||||
#define SHELL_PING 8
|
||||
|
||||
#define SHELL_SHM_MAX 1024*16
|
||||
|
||||
extern char __shell_shm_name[32];
|
||||
extern char *__shell_shm;
|
||||
extern int __shell_is_init;
|
||||
extern int __shell_init();
|
||||
extern void __shell_init();
|
||||
|
||||
#define SHELL_WAIT() while (*__shell_shm) _ksys_delay(5)
|
||||
|
||||
|
12
contrib/kolibri-libc/source/shell_api/shell_get_pid.c
Normal file
12
contrib/kolibri-libc/source/shell_api/shell_get_pid.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include "shell.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
unsigned shell_get_pid()
|
||||
{
|
||||
unsigned pid;
|
||||
__shell_init();
|
||||
*__shell_shm = SHELL_PID;
|
||||
SHELL_WAIT();
|
||||
memcpy(&pid, __shell_shm+1, sizeof(unsigned));
|
||||
return pid;
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "shell.h"
|
||||
#include <shell_api.h>
|
||||
|
||||
char __shell_shm_name[32];
|
||||
char*__shell_shm=NULL;
|
||||
@ -25,14 +26,17 @@ int __shell_shm_init()
|
||||
return _ksys_shm_open(__shell_shm_name, KSYS_SHM_OPEN_ALWAYS | KSYS_SHM_WRITE, SHELL_SHM_MAX, &__shell_shm);
|
||||
}
|
||||
|
||||
int __shell_init()
|
||||
void __shell_init()
|
||||
{
|
||||
if(__shell_is_init){
|
||||
return 0;
|
||||
}
|
||||
if(!__shell_is_init){
|
||||
if(__shell_shm_init()){
|
||||
debug_printf("Shell problems detected!\n");
|
||||
return -1;
|
||||
debug_printf("SHELL problems detected!\n");
|
||||
_ksys_exit();
|
||||
}
|
||||
|
||||
if(!shell_ping()){
|
||||
debug_printf("No SHELL found!\n");
|
||||
_ksys_exit();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
14
contrib/kolibri-libc/source/shell_api/shell_ping.c
Normal file
14
contrib/kolibri-libc/source/shell_api/shell_ping.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include "shell.h"
|
||||
#include <stdlib.h>
|
||||
#include <ksys.h>
|
||||
|
||||
int shell_ping()
|
||||
{
|
||||
__shell_init();
|
||||
*__shell_shm = SHELL_PING;
|
||||
_ksys_delay(10);
|
||||
if(*__shell_shm==SHELL_OK){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user