diff --git a/programs/develop/ktcc/trunk/bin/lib/libc.def b/programs/develop/ktcc/trunk/bin/lib/libc.def index 733b62559..624e6e823 100644 --- a/programs/develop/ktcc/trunk/bin/lib/libc.def +++ b/programs/develop/ktcc/trunk/bin/lib/libc.def @@ -90,7 +90,7 @@ strrev strspn strstr strtok -strtok_s +strtok_r strxfrm __errno ;____SYS____ diff --git a/programs/develop/ktcc/trunk/libc.obj/include/string.h b/programs/develop/ktcc/trunk/libc.obj/include/string.h index f404e36fe..348bef82b 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/string.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/string.h @@ -32,10 +32,7 @@ DLLAPI char* strrchr(const char* s, int c); DLLAPI size_t strspn(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_s(char* s1, const char* s2, char** saveptr); -#ifndef strtok_r -#define strtok_r strtok_s -#endif +DLLAPI char* strtok_r(char* s1, const char* s2, char** saveptr); DLLAPI char* strerror(int errnum); DLLAPI size_t strlen(const char* s); diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/malloc_test.c b/programs/develop/ktcc/trunk/libc.obj/samples/malloc_test.c index 95c3c3442..154f5f6f4 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/malloc_test.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/malloc_test.c @@ -15,7 +15,7 @@ } \ } 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))) bool test_malloc_basic_allocation() diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/system_test.c b/programs/develop/ktcc/trunk/libc.obj/samples/system_test.c index 09f32f1d9..b49225be6 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/system_test.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/system_test.c @@ -1,11 +1,14 @@ #include #include +#include #define EXIT_CODE_FORMAT "Exit Code: %d\n" int main() { - printf(EXIT_CODE_FORMAT, system("ls")); + printf(EXIT_CODE_FORMAT, system("ls .")); + + _ksys_delay(500); printf(EXIT_CODE_FORMAT, system("/sys/sysmon")); return 0; diff --git a/programs/develop/ktcc/trunk/libc.obj/source/libc.c b/programs/develop/ktcc/trunk/libc.obj/source/libc.c index 17f05584c..531298444 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/libc.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/libc.c @@ -82,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" @@ -211,7 +212,7 @@ ksys_dll_t EXPORTS[] = { { "strspn", &strspn }, { "strstr", &strstr }, { "strtok", &strtok }, - { "strtok_s", &strtok_s}, + { "strtok_r", &strtok_r}, { "strxfrm", &strxfrm }, { "strpbrk", &strpbrk }, { "__errno", &__errno }, diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/_exit.h b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/_exit.h index ad7e4233c..0e0865a15 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/_exit.h +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/_exit.h @@ -2,13 +2,13 @@ #define __STDLIB_EXIT_H__ #include - +#include #include -#define __PATH_TO_STATUS_FILE "/tmp0/1/" +#define __PATH_TO_STATUS_FILE "/tmp0/1/.libc" #define __STATUS_FILE_EXTENSION ".status" #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)) 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 inline void WRITE_EXIT_CODE(int status) { + mkdir(__PATH_TO_STATUS_FILE); + char buff[__FULL_STATUS_FILE_NAME_SIZE]; ksys_thread_t t; @@ -35,14 +37,13 @@ inline void WRITE_EXIT_CODE(int status) } // 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]; int status = 0; bool free_t = false; - if(!t) - { + if (!t) { t = malloc(sizeof(ksys_thread_t)); _ksys_thread_info(t, -1); free_t = true; @@ -53,14 +54,12 @@ inline int READ_EXIT_CODE(int pid, ksys_thread_t *t) if (f) { fscanf(f, __STATUS_FILE_FORMAT, &status); 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; } - if(free_t) - { + if (free_t) { free(t); } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/system.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/system.c index dd96c42dd..93ca88ca8 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/system.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/system.c @@ -36,7 +36,6 @@ int system(const char* command) // wait of end of shell 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) { _ksys_thread_yield(); } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c index dbed8f4ae..7d2330951 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c @@ -1,8 +1,54 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include -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)); } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strtok_s.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strtok_s.c deleted file mode 100644 index 83c417aed..000000000 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strtok_s.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -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 */ -}