libc.obj: fix strtok && update change path to exit code
This commit is contained in:
@@ -90,7 +90,7 @@ strrev
|
|||||||
strspn
|
strspn
|
||||||
strstr
|
strstr
|
||||||
strtok
|
strtok
|
||||||
strtok_s
|
strtok_r
|
||||||
strxfrm
|
strxfrm
|
||||||
__errno
|
__errno
|
||||||
;____SYS____
|
;____SYS____
|
||||||
|
|||||||
@@ -32,10 +32,7 @@ DLLAPI char* strrchr(const char* s, int c);
|
|||||||
DLLAPI size_t strspn(const char* s1, const char* s2);
|
DLLAPI size_t strspn(const char* s1, const char* s2);
|
||||||
DLLAPI char* strstr(const char* s1, const char* s2);
|
DLLAPI char* strstr(const char* s1, const char* s2);
|
||||||
DLLAPI char* strtok(char* s1, const char* s2);
|
DLLAPI char* strtok(char* s1, const char* s2);
|
||||||
DLLAPI char* strtok_s(char* s1, const char* s2, char** saveptr);
|
DLLAPI char* strtok_r(char* s1, const char* s2, char** saveptr);
|
||||||
#ifndef strtok_r
|
|
||||||
#define strtok_r strtok_s
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DLLAPI char* strerror(int errnum);
|
DLLAPI char* strerror(int errnum);
|
||||||
DLLAPI size_t strlen(const char* s);
|
DLLAPI size_t strlen(const char* s);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// c behind a and b
|
// c between a and b
|
||||||
#define IN_RANGE(a, b, c, len) ((a > c && c > b) || ((a > c + len && c + len > b)))
|
#define IN_RANGE(a, b, c, len) ((a > c && c > b) || ((a > c + len && c + len > b)))
|
||||||
|
|
||||||
bool test_malloc_basic_allocation()
|
bool test_malloc_basic_allocation()
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sys/ksys.h>
|
||||||
|
|
||||||
#define EXIT_CODE_FORMAT "Exit Code: %d\n"
|
#define EXIT_CODE_FORMAT "Exit Code: %d\n"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
printf(EXIT_CODE_FORMAT, system("ls"));
|
printf(EXIT_CODE_FORMAT, system("ls ."));
|
||||||
|
|
||||||
|
_ksys_delay(500);
|
||||||
printf(EXIT_CODE_FORMAT, system("/sys/sysmon"));
|
printf(EXIT_CODE_FORMAT, system("/sys/sysmon"));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -82,6 +82,7 @@
|
|||||||
#include "string/strstr.c"
|
#include "string/strstr.c"
|
||||||
#include "string/strtok.c"
|
#include "string/strtok.c"
|
||||||
#include "string/strxfrm.c"
|
#include "string/strxfrm.c"
|
||||||
|
|
||||||
#include "stdlib/abs.c"
|
#include "stdlib/abs.c"
|
||||||
#include "stdlib/assert.c"
|
#include "stdlib/assert.c"
|
||||||
#include "stdlib/atof.c"
|
#include "stdlib/atof.c"
|
||||||
@@ -211,7 +212,7 @@ ksys_dll_t EXPORTS[] = {
|
|||||||
{ "strspn", &strspn },
|
{ "strspn", &strspn },
|
||||||
{ "strstr", &strstr },
|
{ "strstr", &strstr },
|
||||||
{ "strtok", &strtok },
|
{ "strtok", &strtok },
|
||||||
{ "strtok_s", &strtok_s},
|
{ "strtok_r", &strtok_r},
|
||||||
{ "strxfrm", &strxfrm },
|
{ "strxfrm", &strxfrm },
|
||||||
{ "strpbrk", &strpbrk },
|
{ "strpbrk", &strpbrk },
|
||||||
{ "__errno", &__errno },
|
{ "__errno", &__errno },
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
#define __STDLIB_EXIT_H__
|
#define __STDLIB_EXIT_H__
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sys/dir.h>
|
||||||
#include <sys/ksys.h>
|
#include <sys/ksys.h>
|
||||||
|
|
||||||
#define __PATH_TO_STATUS_FILE "/tmp0/1/"
|
#define __PATH_TO_STATUS_FILE "/tmp0/1/.libc"
|
||||||
#define __STATUS_FILE_EXTENSION ".status"
|
#define __STATUS_FILE_EXTENSION ".status"
|
||||||
#define __STATUS_FILE_FORMAT "%d"
|
#define __STATUS_FILE_FORMAT "%d"
|
||||||
#define __FULL_STATUS_FILE_NAME __PATH_TO_STATUS_FILE "%d" __STATUS_FILE_EXTENSION
|
#define __FULL_STATUS_FILE_NAME __PATH_TO_STATUS_FILE "/%d" __STATUS_FILE_EXTENSION
|
||||||
#define __FULL_STATUS_FILE_NAME_SIZE (sizeof(__PATH_TO_STATUS_FILE) + 32 + sizeof(__STATUS_FILE_EXTENSION))
|
#define __FULL_STATUS_FILE_NAME_SIZE (sizeof(__PATH_TO_STATUS_FILE) + 32 + sizeof(__STATUS_FILE_EXTENSION))
|
||||||
|
|
||||||
void __libc_exit(int status, void (*before_exit)(int status));
|
void __libc_exit(int status, void (*before_exit)(int status));
|
||||||
@@ -16,6 +16,8 @@ void __libc_exit(int status, void (*before_exit)(int status));
|
|||||||
// Save exit code
|
// Save exit code
|
||||||
inline void WRITE_EXIT_CODE(int status)
|
inline void WRITE_EXIT_CODE(int status)
|
||||||
{
|
{
|
||||||
|
mkdir(__PATH_TO_STATUS_FILE);
|
||||||
|
|
||||||
char buff[__FULL_STATUS_FILE_NAME_SIZE];
|
char buff[__FULL_STATUS_FILE_NAME_SIZE];
|
||||||
ksys_thread_t t;
|
ksys_thread_t t;
|
||||||
|
|
||||||
@@ -35,14 +37,13 @@ inline void WRITE_EXIT_CODE(int status)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read exit code
|
// Read exit code
|
||||||
inline int READ_EXIT_CODE(int pid, ksys_thread_t *t)
|
inline int READ_EXIT_CODE(int pid, ksys_thread_t* t)
|
||||||
{
|
{
|
||||||
char buff[__FULL_STATUS_FILE_NAME_SIZE];
|
char buff[__FULL_STATUS_FILE_NAME_SIZE];
|
||||||
int status = 0;
|
int status = 0;
|
||||||
bool free_t = false;
|
bool free_t = false;
|
||||||
|
|
||||||
if(!t)
|
if (!t) {
|
||||||
{
|
|
||||||
t = malloc(sizeof(ksys_thread_t));
|
t = malloc(sizeof(ksys_thread_t));
|
||||||
_ksys_thread_info(t, -1);
|
_ksys_thread_info(t, -1);
|
||||||
free_t = true;
|
free_t = true;
|
||||||
@@ -53,14 +54,12 @@ inline int READ_EXIT_CODE(int pid, ksys_thread_t *t)
|
|||||||
if (f) {
|
if (f) {
|
||||||
fscanf(f, __STATUS_FILE_FORMAT, &status);
|
fscanf(f, __STATUS_FILE_FORMAT, &status);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
} else if (t && t->slot_state == 4) // it was stopped before it created status file
|
||||||
else if(t && t->slot_state == 4) // it was stopped before it created status file
|
|
||||||
{
|
{
|
||||||
status = -1;
|
status = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(free_t)
|
if (free_t) {
|
||||||
{
|
|
||||||
free(t);
|
free(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ int system(const char* command)
|
|||||||
// wait of end of shell
|
// wait of end of shell
|
||||||
|
|
||||||
ksys_thread_t t;
|
ksys_thread_t t;
|
||||||
int slot = _ksys_get_thread_slot(pid);
|
|
||||||
while (_ksys_thread_info(&t, pid) != -1 && t.slot_state != 3 && t.slot_state != 4 && t.slot_state != 9) {
|
while (_ksys_thread_info(&t, pid) != -1 && t.slot_state != 3 && t.slot_state != 4 && t.slot_state != 9) {
|
||||||
_ksys_thread_yield();
|
_ksys_thread_yield();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,54 @@
|
|||||||
|
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
char* strtok(char* s, const char* delim)
|
char* strtok_r(char* s, const char* delim, char** last)
|
||||||
{
|
{
|
||||||
static char *saveptr;
|
char *spanp, *tok;
|
||||||
|
int c, sc;
|
||||||
|
|
||||||
return strtok_s(s, delim, &saveptr);
|
if (s == NULL && (s = *last) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
|
||||||
|
*/
|
||||||
|
cont:
|
||||||
|
c = *s++;
|
||||||
|
for (spanp = (char*)delim; (sc = *spanp++) != 0;) {
|
||||||
|
if (c == sc)
|
||||||
|
goto cont;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == 0) { /* no non-delimiter characters */
|
||||||
|
*last = NULL;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
tok = s - 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
|
||||||
|
* Note that delim must have one NUL; we stop if we see that, too.
|
||||||
|
*/
|
||||||
|
for (;;) {
|
||||||
|
c = *s++;
|
||||||
|
spanp = (char*)delim;
|
||||||
|
do {
|
||||||
|
if ((sc = *spanp++) == c) {
|
||||||
|
if (c == 0)
|
||||||
|
s = NULL;
|
||||||
|
else
|
||||||
|
s[-1] = '\0';
|
||||||
|
*last = s;
|
||||||
|
return (tok);
|
||||||
|
}
|
||||||
|
} while (sc != 0);
|
||||||
|
}
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
char *strtok(char *s, const char *delim)
|
||||||
|
{
|
||||||
|
static char *last;
|
||||||
|
|
||||||
|
return (strtok_r(s, delim, &last));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
char* strtok_s(char* s, const char* delim, char** saveptr)
|
|
||||||
{
|
|
||||||
const char* spanp;
|
|
||||||
int c, sc;
|
|
||||||
char* tok;
|
|
||||||
|
|
||||||
if (s == NULL && (s = *saveptr) == NULL)
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
|
|
||||||
*/
|
|
||||||
cont:
|
|
||||||
c = *s++;
|
|
||||||
for (spanp = delim; (sc = *spanp++) != 0;) {
|
|
||||||
if (c == sc)
|
|
||||||
goto cont;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == 0) { /* no non-delimiter characters */
|
|
||||||
*saveptr = NULL;
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
tok = s - 1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
|
|
||||||
* Note that delim must have one NUL; we stop if we see that, too.
|
|
||||||
*/
|
|
||||||
for (;;) {
|
|
||||||
c = *s++;
|
|
||||||
spanp = delim;
|
|
||||||
do {
|
|
||||||
if ((sc = *spanp++) == c) {
|
|
||||||
if (c == 0)
|
|
||||||
s = NULL;
|
|
||||||
else
|
|
||||||
s[-1] = 0;
|
|
||||||
*saveptr = s;
|
|
||||||
return (tok);
|
|
||||||
}
|
|
||||||
} while (sc != 0);
|
|
||||||
}
|
|
||||||
/* NOTREACHED */
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user