From cde4fa851d635a14d972bd5e897bbdae67bdfa41 Mon Sep 17 00:00:00 2001 From: turbocat Date: Fri, 15 Apr 2022 09:00:55 +0000 Subject: [PATCH] libc.obj: - Formatted by clang-format (WebKit-style). - Removed unnecessary errno linux. - Added KOS error codes. - String functions have been replaced with more optimal ones for x86. - Changed wrappers for 70 sysfunction. git-svn-id: svn://kolibrios.org@9765 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../ktcc/trunk/libc.obj/source/ctype/is.c | 36 +- .../trunk/libc.obj/source/ctype/tolower.c | 5 +- .../trunk/libc.obj/source/ctype/toupper.c | 5 +- .../develop/ktcc/trunk/libc.obj/source/libc.c | 499 ++++++++-------- .../trunk/libc.obj/source/libtcc1/libtcc1.c | 557 +++++++++--------- .../ktcc/trunk/libc.obj/source/math/acosh.c | 7 +- .../ktcc/trunk/libc.obj/source/math/asinh.c | 6 +- .../ktcc/trunk/libc.obj/source/math/atan2.s | 2 +- .../ktcc/trunk/libc.obj/source/math/atanh.c | 5 +- .../ktcc/trunk/libc.obj/source/math/cosh.c | 4 +- .../ktcc/trunk/libc.obj/source/math/frexp.c | 39 +- .../ktcc/trunk/libc.obj/source/math/hypot.c | 130 ++-- .../ktcc/trunk/libc.obj/source/math/ldexp.c | 44 +- .../ktcc/trunk/libc.obj/source/math/sinh.c | 17 +- .../ktcc/trunk/libc.obj/source/math/tanh.c | 20 +- .../trunk/libc.obj/source/misc/basename.c | 18 +- .../ktcc/trunk/libc.obj/source/misc/dirname.c | 25 +- .../libc.obj/source/stdlib/___chkstk_ms.c | 2 +- .../ktcc/trunk/libc.obj/source/stdlib/abs.c | 2 +- .../trunk/libc.obj/source/stdlib/assert.c | 7 +- .../ktcc/trunk/libc.obj/source/stdlib/atof.c | 4 +- .../ktcc/trunk/libc.obj/source/stdlib/atoi.c | 22 +- .../ktcc/trunk/libc.obj/source/stdlib/atol.c | 29 +- .../ktcc/trunk/libc.obj/source/stdlib/atoll.c | 29 +- .../trunk/libc.obj/source/stdlib/calloc.c | 13 +- .../ktcc/trunk/libc.obj/source/stdlib/exit.c | 2 +- .../ktcc/trunk/libc.obj/source/stdlib/free.c | 3 +- .../ktcc/trunk/libc.obj/source/stdlib/itoa.c | 40 +- .../ktcc/trunk/libc.obj/source/stdlib/labs.c | 2 +- .../ktcc/trunk/libc.obj/source/stdlib/llabs.c | 2 +- .../trunk/libc.obj/source/stdlib/malloc.c | 3 +- .../ktcc/trunk/libc.obj/source/stdlib/qsort.c | 320 +++++----- .../ktcc/trunk/libc.obj/source/stdlib/rand.c | 8 +- .../trunk/libc.obj/source/stdlib/realloc.c | 3 +- .../trunk/libc.obj/source/stdlib/strtod.c | 59 +- .../trunk/libc.obj/source/stdlib/strtol.c | 105 ++-- .../trunk/libc.obj/source/string/memchr.c | 42 +- .../trunk/libc.obj/source/string/memcmp.c | 41 +- .../trunk/libc.obj/source/string/memcpy.c | 37 +- .../trunk/libc.obj/source/string/memmove.c | 33 -- .../trunk/libc.obj/source/string/memmove.s | 34 ++ .../trunk/libc.obj/source/string/memset.c | 20 - .../trunk/libc.obj/source/string/memset.s | 51 ++ .../trunk/libc.obj/source/string/strcat.c | 43 +- .../trunk/libc.obj/source/string/strchr.c | 39 +- .../trunk/libc.obj/source/string/strcmp.c | 35 +- .../trunk/libc.obj/source/string/strcoll.c | 20 +- .../trunk/libc.obj/source/string/strcpy.c | 35 +- .../trunk/libc.obj/source/string/strcspn.c | 47 +- .../trunk/libc.obj/source/string/strdup.c | 6 +- .../trunk/libc.obj/source/string/strerror.c | 70 +-- .../trunk/libc.obj/source/string/strlen.c | 35 +- .../trunk/libc.obj/source/string/strncat.c | 50 +- .../trunk/libc.obj/source/string/strncmp.c | 50 +- .../trunk/libc.obj/source/string/strncpy.c | 48 +- .../trunk/libc.obj/source/string/strpbrk.c | 46 +- .../trunk/libc.obj/source/string/strrchr.c | 45 +- .../trunk/libc.obj/source/string/strspn.c | 52 +- .../trunk/libc.obj/source/string/strstr.c | 55 +- .../trunk/libc.obj/source/string/strtok.c | 79 ++- .../trunk/libc.obj/source/string/strxfrm.c | 46 +- .../trunk/libc.obj/source/string/unconst.h | 8 + .../ktcc/trunk/libc.obj/source/sys/opendir.c | 2 +- .../ktcc/trunk/libc.obj/source/time/asctime.c | 20 +- .../trunk/libc.obj/source/time/difftime.c | 6 +- .../trunk/libc.obj/source/time/localtime.c | 166 +++--- .../ktcc/trunk/libc.obj/source/time/mktime.c | 24 +- .../ktcc/trunk/libc.obj/source/time/time.c | 31 +- 68 files changed, 1628 insertions(+), 1762 deletions(-) delete mode 100644 programs/develop/ktcc/trunk/libc.obj/source/string/memmove.c create mode 100755 programs/develop/ktcc/trunk/libc.obj/source/string/memmove.s delete mode 100644 programs/develop/ktcc/trunk/libc.obj/source/string/memset.c create mode 100755 programs/develop/ktcc/trunk/libc.obj/source/string/memset.s create mode 100755 programs/develop/ktcc/trunk/libc.obj/source/string/unconst.h diff --git a/programs/develop/ktcc/trunk/libc.obj/source/ctype/is.c b/programs/develop/ktcc/trunk/libc.obj/source/ctype/is.c index fc160bec22..24574ecdb7 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/ctype/is.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/ctype/is.c @@ -1,21 +1,21 @@ #include unsigned short __is[129] = { - 0, /* EOF */ - 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, - 0x004, 0x104, 0x104, 0x104, 0x104, 0x104, 0x004, 0x004, - 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, - 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, - 0x140, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, - 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, - 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, - 0x459, 0x459, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, - 0x0D0, 0x653, 0x653, 0x653, 0x653, 0x653, 0x653, 0x253, - 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, - 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, - 0x253, 0x253, 0x253, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, - 0x0D0, 0x473, 0x473, 0x473, 0x473, 0x473, 0x473, 0x073, - 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, - 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, - 0x073, 0x073, 0x073, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x004 - }; + 0, /* EOF */ + 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, + 0x004, 0x104, 0x104, 0x104, 0x104, 0x104, 0x004, 0x004, + 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, + 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, + 0x140, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, + 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, + 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, + 0x459, 0x459, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, + 0x0D0, 0x653, 0x653, 0x653, 0x653, 0x653, 0x653, 0x253, + 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, + 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, + 0x253, 0x253, 0x253, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, + 0x0D0, 0x473, 0x473, 0x473, 0x473, 0x473, 0x473, 0x073, + 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, + 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, + 0x073, 0x073, 0x073, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x004 +}; diff --git a/programs/develop/ktcc/trunk/libc.obj/source/ctype/tolower.c b/programs/develop/ktcc/trunk/libc.obj/source/ctype/tolower.c index b56f3c5094..def9ad760e 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/ctype/tolower.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/ctype/tolower.c @@ -2,6 +2,7 @@ int tolower(int c) { - if (isupper(c)) return c | 32; - return c; + if (isupper(c)) + return c | 32; + return c; } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/ctype/toupper.c b/programs/develop/ktcc/trunk/libc.obj/source/ctype/toupper.c index 1799f03077..b01df98849 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/ctype/toupper.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/ctype/toupper.c @@ -2,6 +2,7 @@ int toupper(int c) { - if (islower(c)) return c & 0x5f; - return c; + if (islower(c)) + return c & 0x5f; + return c; } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/libc.c b/programs/develop/ktcc/trunk/libc.obj/source/libc.c index 40c288cb95..293fe5f1c0 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/libc.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/libc.c @@ -1,106 +1,104 @@ #include #include "ctype/is.c" -#include "ctype/tolower.c" +#include "ctype/tolower.c" #include "ctype/toupper.c" -#include "sys/rewinddir.c" -#include "sys/readdir.c" -#include "sys/seekdir.c" -#include "sys/opendir.c" -#include "sys/telldir.c" #include "sys/closedir.c" #include "sys/dir.c" +#include "sys/opendir.c" +#include "sys/readdir.c" +#include "sys/rewinddir.c" +#include "sys/seekdir.c" #include "sys/socket.c" +#include "sys/telldir.c" #include "stdio/clearerr.c" -#include "stdio/gets.c" -#include "stdio/setbuf.c" +#include "stdio/conio.c" +#include "stdio/debug_printf.c" +#include "stdio/fclose.c" +#include "stdio/feof.c" +#include "stdio/ferror.c" +#include "stdio/fflush.c" #include "stdio/fgetc.c" +#include "stdio/fgetpos.c" +#include "stdio/fgets.c" #include "stdio/fopen.c" #include "stdio/format_print.c" -#include "stdio/vprintf.c" -#include "stdio/feof.c" -#include "stdio/fwrite.c" -#include "stdio/fread.c" -#include "stdio/fseek.c" -#include "stdio/fgetpos.c" -#include "stdio/fclose.c" -#include "stdio/snprintf.c" -#include "stdio/rename.c" -#include "stdio/getchar.c" -#include "stdio/remove.c" -#include "stdio/ferror.c" -#include "stdio/tmpfile.c" -#include "stdio/fputs.c" -#include "stdio/fputc.c" -#include "stdio/fgets.c" -#include "stdio/fflush.c" #include "stdio/format_scan.c" -#include "stdio/printf.c" -#include "stdio/fscanf.c" -#include "stdio/debug_printf.c" -#include "stdio/fsetpos.c" -#include "stdio/setvbuf.c" -#include "stdio/sscanf.c" -#include "stdio/scanf.c" -#include "stdio/freopen.c" -#include "stdio/puts.c" -#include "stdio/sprintf.c" -#include "stdio/vsnprintf.c" -#include "stdio/conio.c" -#include "stdio/perror.c" -#include "stdio/ftell.c" -#include "stdio/tmpnam.c" -#include "stdio/rewind.c" -#include "stdio/vfprintf.c" #include "stdio/fprintf.c" +#include "stdio/fputc.c" +#include "stdio/fputs.c" +#include "stdio/fread.c" +#include "stdio/freopen.c" +#include "stdio/fscanf.c" +#include "stdio/fseek.c" +#include "stdio/fsetpos.c" +#include "stdio/ftell.c" +#include "stdio/fwrite.c" +#include "stdio/getchar.c" +#include "stdio/gets.c" +#include "stdio/perror.c" +#include "stdio/printf.c" +#include "stdio/puts.c" +#include "stdio/remove.c" +#include "stdio/rename.c" +#include "stdio/rewind.c" +#include "stdio/scanf.c" +#include "stdio/setbuf.c" +#include "stdio/setvbuf.c" +#include "stdio/snprintf.c" +#include "stdio/sprintf.c" +#include "stdio/sscanf.c" +#include "stdio/tmpfile.c" +#include "stdio/tmpnam.c" #include "stdio/ungetc.c" +#include "stdio/vfprintf.c" +#include "stdio/vprintf.c" +#include "stdio/vsnprintf.c" -#include "string/strerror.c" -#include "string/strxfrm.c" -#include "string/strrchr.c" -#include "string/strcspn.c" -#include "string/strlen.c" -#include "string/strrev.c" #include "string/memccpy.c" -#include "string/strchr.c" -#include "string/strcoll.c" -#include "string/strpbrk.c" -#include "string/strstr.c" -#include "string/memcmp.c" -#include "string/strspn.c" -#include "string/strcpy.c" -#include "string/strncpy.c" -#include "string/strdup.c" -#include "string/strcat.c" #include "string/memchr.c" -#include "string/strncmp.c" -#include "string/strncat.c" -#include "string/strtok.c" -#include "string/strcmp.c" -#include "string/memset.c" +#include "string/memcmp.c" #include "string/memcpy.c" -#include "string/memmove.c" +#include "string/strcat.c" +#include "string/strchr.c" +#include "string/strcmp.c" +#include "string/strcoll.c" +#include "string/strcpy.c" +#include "string/strcspn.c" +#include "string/strdup.c" +#include "string/strerror.c" +#include "string/strlen.c" +#include "string/strncat.c" +#include "string/strncmp.c" +#include "string/strncpy.c" +#include "string/strpbrk.c" +#include "string/strrchr.c" +#include "string/strrev.c" +#include "string/strspn.c" +#include "string/strstr.c" +#include "string/strtok.c" +#include "string/strxfrm.c" -#include "stdlib/calloc.c" -#include "stdlib/malloc.c" -#include "stdlib/atoll.c" -#include "stdlib/free.c" -#include "stdlib/llabs.c" -#include "stdlib/exit.c" -#include "stdlib/atoi.c" -#include "stdlib/labs.c" -#include "stdlib/realloc.c" #include "stdlib/abs.c" -#include "stdlib/atol.c" -#include "stdlib/itoa.c" -#include "stdlib/strtol.c" -#include "stdlib/rand.c" -#include "stdlib/qsort.c" #include "stdlib/assert.c" -#include "stdlib/strtod.c" #include "stdlib/atof.c" +#include "stdlib/atoi.c" +#include "stdlib/atol.c" +#include "stdlib/atoll.c" +#include "stdlib/calloc.c" +#include "stdlib/exit.c" +#include "stdlib/free.c" +#include "stdlib/itoa.c" +#include "stdlib/labs.c" +#include "stdlib/llabs.c" +#include "stdlib/malloc.c" +#include "stdlib/qsort.c" +#include "stdlib/rand.c" +#include "stdlib/realloc.c" +#include "stdlib/strtod.c" +#include "stdlib/strtol.c" #include "math/acosh.c" #include "math/asinh.c" @@ -112,11 +110,11 @@ #include "math/sinh.c" #include "math/tanh.c" +#include "time/asctime.c" #include "time/difftime.c" #include "time/localtime.c" #include "time/mktime.c" #include "time/time.c" -#include "time/asctime.c" #include "misc/basename.c" #include "misc/dirname.c" @@ -140,184 +138,183 @@ __asm__( ".include \"math/pow10.s\"\n\t" ".include \"math/sqrt.s\"\n\t" ".include \"math/sin.s\"\n\t" - ".include \"math/tan.s\"\n\t" -); + ".include \"math/tan.s\"\n\t"); __asm__( + ".include \"string/memmove.s\"\n\t" + ".include \"string/memset.s\"\n\t" ".include \"setjmp/longjmp.s\"\n\t" - ".include \"setjmp/setjmp.s\"" -); + ".include \"setjmp/setjmp.s\""); #include "libtcc1/libtcc1.c" #include "stdlib/___chkstk_ms.c" - ksys_dll_t EXPORTS[] = { - {"clearerr", &clearerr}, - {"debug_printf", &debug_printf}, - {"fclose", &fclose}, - {"feof", &feof}, - {"ferror", &ferror}, - {"fflush", &fflush}, - {"fgetc", &fgetc}, - {"fgetpos", &fgetpos}, - {"fgets", &fgets}, - {"fopen", &fopen}, - {"fprintf", &fprintf}, - {"fputc", &fputc}, - {"fputs", &fputs}, - {"fread", &fread}, - {"freopen", &freopen}, - {"fscanf", &fscanf}, - {"fseek", &fseek}, - {"fsetpos", &fsetpos}, - {"ftell", &ftell}, - {"fwrite", &fwrite}, - {"getchar", &getchar}, - {"gets", &gets}, - {"perror", &perror}, - {"printf", &printf}, - {"puts", &puts}, - {"remove", &remove}, - {"rename", &rename}, - {"rewind", &rewind}, - {"scanf", &scanf}, - {"setbuf", &setbuf}, - {"setvbuf", &setvbuf}, - {"snprintf", &snprintf}, - {"sprintf", &sprintf}, - {"sscanf", &sscanf}, - {"tmpfile", &tmpfile}, - {"tmpnam", &tmpnam}, - {"vfscanf", &vfscanf}, - {"vprintf", &vprintf}, - {"vfscanf", &vfscanf}, - {"vsprintf", &vsprintf}, - {"vsnprintf", &vsnprintf}, - {"vsscanf", &vsscanf}, - {"ungetc", &ungetc}, - {"abs", &abs}, - {"atoi", &atoi}, - {"atol", &atol}, - {"atoll", &atoll}, - {"atof", &atof}, - {"calloc", &calloc}, - {"exit", &exit}, - {"free", &free}, - {"itoa", &itoa}, - {"labs", &labs}, - {"llabs", &llabs}, - {"malloc", &malloc}, - {"realloc", &realloc}, - {"strtol", &strtol}, - {"srand", &srand}, - {"rand", &rand}, - {"qsort", &qsort}, - {"strtod", &strtod}, - {"__assert_fail", &__assert_fail}, - {"memchr", &memchr}, - {"memcmp", &memcmp}, - {"strncat", &strncat}, - {"strchr", &strchr}, - {"strcat", &strcat}, - {"strcmp", &strcmp}, - {"strcoll", &strcoll}, - {"strcpy", &strcpy}, - {"strcspn", &strcspn}, - {"strdup", &strdup}, - {"strerror", &strerror}, - {"strlen", &strlen}, - {"strncat", &strncat}, - {"strncmp", &strncmp}, - {"strncpy", &strncpy}, - {"strrchr", &strrchr}, - {"strrev", &strrev}, - {"strspn", &strspn}, - {"strstr", &strstr}, - {"strtok", &strtok}, - {"strxfrm", &strxfrm}, - {"_errno", &_errno}, - {"closedir", &closedir}, - {"opendir", &opendir}, - {"readdir", &readdir}, - {"rewinddir", &rewinddir}, - {"seekdir", &seekdir}, - {"telldir", &telldir}, - {"getcwd", &getcwd}, - {"mkdir", &mkdir}, - {"rmdir", &rmdir}, - {"setcwd", &setcwd}, - {"getcwd", &getcwd}, - {"socket", &socket}, - {"close", &close}, - {"bind", &bind}, - {"listen", &listen}, - {"connect", &connect}, - {"accept", &accept}, - {"send", &send}, - {"recv", &recv}, - {"setsockopt", &setsockopt}, - {"socketpair", &socketpair}, - {"acosh", &acosh}, - {"asinh", &asinh}, - {"atanh", &atanh}, - {"acosh", &acosh}, - {"frexp", &frexp}, - {"hypot", &hypot}, - {"ldexp", &ldexp}, - {"cosh", &cosh}, - {"sinh", &sinh}, - {"tanh", &tanh}, - {"acos", &acos}, - {"asin", &asin}, - {"atan", &atan}, - {"atan2", &atan2}, - {"ceil", &ceil}, - {"cos", &cos}, - {"sin", &sin}, - {"tan", &tan}, - {"sqrt", &sqrt}, - {"exp", &exp}, - {"fabs", &fabs}, - {"floor", &floor}, - {"fmod", &fmod}, - {"log", &log}, - {"modf", &modf}, - {"modfl", &modfl}, - {"pow", &pow}, - {"pow2", &pow2}, - {"pow10", &pow10}, - {"longjmp", &longjmp}, - {"setjmp", &setjmp}, - {"__is", &__is}, - {"tolower", &tolower}, - {"toupper", &toupper}, - {"con_set_title", &con_set_title}, - {"con_init", &con_init}, - {"con_init_opt", &con_init_opt}, - {"con_write_asciiz", &con_write_asciiz}, - {"con_write_string", &con_write_string}, - {"con_printf", &con_printf}, - {"con_exit", &con_exit}, - {"con_get_flags", &con_get_flags}, - {"con_set_flags", &con_set_flags}, - {"con_kbhit", &con_kbhit}, - {"con_getch", &con_getch}, - {"con_getch2", &con_getch2}, - {"con_gets", &con_gets}, - {"con_gets2", &con_gets2}, - {"con_get_font_height", &con_get_font_height}, - {"con_get_cursor_height", &con_get_cursor_height}, - {"con_set_cursor_height", &con_set_cursor_height}, - {"con_cls", &con_cls}, - {"con_get_cursor_pos", &con_get_cursor_pos}, - {"con_set_cursor_pos", &con_set_cursor_pos}, - {"mktime", &mktime}, - {"time", &time}, - {"localtime", &localtime}, - {"asctime", &asctime}, - {"difftime", &difftime}, - {"basename", &basename}, - {"dirname", &dirname}, + { "clearerr", &clearerr }, + { "debug_printf", &debug_printf }, + { "fclose", &fclose }, + { "feof", &feof }, + { "ferror", &ferror }, + { "fflush", &fflush }, + { "fgetc", &fgetc }, + { "fgetpos", &fgetpos }, + { "fgets", &fgets }, + { "fopen", &fopen }, + { "fprintf", &fprintf }, + { "fputc", &fputc }, + { "fputs", &fputs }, + { "fread", &fread }, + { "freopen", &freopen }, + { "fscanf", &fscanf }, + { "fseek", &fseek }, + { "fsetpos", &fsetpos }, + { "ftell", &ftell }, + { "fwrite", &fwrite }, + { "getchar", &getchar }, + { "gets", &gets }, + { "perror", &perror }, + { "printf", &printf }, + { "puts", &puts }, + { "remove", &remove }, + { "rename", &rename }, + { "rewind", &rewind }, + { "scanf", &scanf }, + { "setbuf", &setbuf }, + { "setvbuf", &setvbuf }, + { "snprintf", &snprintf }, + { "sprintf", &sprintf }, + { "sscanf", &sscanf }, + { "tmpfile", &tmpfile }, + { "tmpnam", &tmpnam }, + { "vfscanf", &vfscanf }, + { "vprintf", &vprintf }, + { "vfscanf", &vfscanf }, + { "vsprintf", &vsprintf }, + { "vsnprintf", &vsnprintf }, + { "vsscanf", &vsscanf }, + { "ungetc", &ungetc }, + { "abs", &abs }, + { "atoi", &atoi }, + { "atol", &atol }, + { "atoll", &atoll }, + { "atof", &atof }, + { "calloc", &calloc }, + { "exit", &exit }, + { "free", &free }, + { "itoa", &itoa }, + { "labs", &labs }, + { "llabs", &llabs }, + { "malloc", &malloc }, + { "realloc", &realloc }, + { "strtol", &strtol }, + { "srand", &srand }, + { "rand", &rand }, + { "qsort", &qsort }, + { "strtod", &strtod }, + { "__assert_fail", &__assert_fail }, + { "memchr", &memchr }, + { "memcmp", &memcmp }, + { "strncat", &strncat }, + { "strchr", &strchr }, + { "strcat", &strcat }, + { "strcmp", &strcmp }, + { "strcoll", &strcoll }, + { "strcpy", &strcpy }, + { "strcspn", &strcspn }, + { "strdup", &strdup }, + { "strerror", &strerror }, + { "strlen", &strlen }, + { "strncat", &strncat }, + { "strncmp", &strncmp }, + { "strncpy", &strncpy }, + { "strrchr", &strrchr }, + { "strrev", &strrev }, + { "strspn", &strspn }, + { "strstr", &strstr }, + { "strtok", &strtok }, + { "strxfrm", &strxfrm }, + { "__errno", &__errno }, + { "closedir", &closedir }, + { "opendir", &opendir }, + { "readdir", &readdir }, + { "rewinddir", &rewinddir }, + { "seekdir", &seekdir }, + { "telldir", &telldir }, + { "getcwd", &getcwd }, + { "mkdir", &mkdir }, + { "rmdir", &rmdir }, + { "setcwd", &setcwd }, + { "getcwd", &getcwd }, + { "socket", &socket }, + { "close", &close }, + { "bind", &bind }, + { "listen", &listen }, + { "connect", &connect }, + { "accept", &accept }, + { "send", &send }, + { "recv", &recv }, + { "setsockopt", &setsockopt }, + { "socketpair", &socketpair }, + { "acosh", &acosh }, + { "asinh", &asinh }, + { "atanh", &atanh }, + { "acosh", &acosh }, + { "frexp", &frexp }, + { "hypot", &hypot }, + { "ldexp", &ldexp }, + { "cosh", &cosh }, + { "sinh", &sinh }, + { "tanh", &tanh }, + { "acos", &acos }, + { "asin", &asin }, + { "atan", &atan }, + { "atan2", &atan2 }, + { "ceil", &ceil }, + { "cos", &cos }, + { "sin", &sin }, + { "tan", &tan }, + { "sqrt", &sqrt }, + { "exp", &exp }, + { "fabs", &fabs }, + { "floor", &floor }, + { "fmod", &fmod }, + { "log", &log }, + { "modf", &modf }, + { "modfl", &modfl }, + { "pow", &pow }, + { "pow2", &pow2 }, + { "pow10", &pow10 }, + { "longjmp", &longjmp }, + { "setjmp", &setjmp }, + { "__is", &__is }, + { "tolower", &tolower }, + { "toupper", &toupper }, + { "con_set_title", &con_set_title }, + { "con_init", &con_init }, + { "con_init_opt", &con_init_opt }, + { "con_write_asciiz", &con_write_asciiz }, + { "con_write_string", &con_write_string }, + { "con_printf", &con_printf }, + { "con_exit", &con_exit }, + { "con_get_flags", &con_get_flags }, + { "con_set_flags", &con_set_flags }, + { "con_kbhit", &con_kbhit }, + { "con_getch", &con_getch }, + { "con_getch2", &con_getch2 }, + { "con_gets", &con_gets }, + { "con_gets2", &con_gets2 }, + { "con_get_font_height", &con_get_font_height }, + { "con_get_cursor_height", &con_get_cursor_height }, + { "con_set_cursor_height", &con_set_cursor_height }, + { "con_cls", &con_cls }, + { "con_get_cursor_pos", &con_get_cursor_pos }, + { "con_set_cursor_pos", &con_set_cursor_pos }, + { "mktime", &mktime }, + { "time", &time }, + { "localtime", &localtime }, + { "asctime", &asctime }, + { "difftime", &difftime }, + { "basename", &basename }, + { "dirname", &dirname }, NULL, }; diff --git a/programs/develop/ktcc/trunk/libc.obj/source/libtcc1/libtcc1.c b/programs/develop/ktcc/trunk/libc.obj/source/libtcc1/libtcc1.c index e67ea59ea5..9a7d96a7a5 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/libtcc1/libtcc1.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/libtcc1/libtcc1.c @@ -1,5 +1,5 @@ -/* TCC runtime library. - Parts of this code are (c) 2002 Fabrice Bellard +/* TCC runtime library. + Parts of this code are (c) 2002 Fabrice Bellard Copyright (C) 1987, 1988, 1992, 1994, 1995 Free Software Foundation, Inc. @@ -25,13 +25,13 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. +Boston, MA 02111-1307, USA. */ //#include #define TCC_TARGET_I386 -#define W_TYPE_SIZE 32 +#define W_TYPE_SIZE 32 #define BITS_PER_UNIT 8 typedef int Wtype; @@ -44,40 +44,38 @@ struct DWstruct { Wtype low, high; }; -typedef union -{ - struct DWstruct s; - DWtype ll; +typedef union { + struct DWstruct s; + DWtype ll; } DWunion; typedef long double XFtype; -#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) -#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) +#define WORD_SIZE (sizeof(Wtype) * BITS_PER_UNIT) +#define HIGH_WORD_COEFF (((UDWtype)1) << WORD_SIZE) /* the following deal with IEEE single-precision numbers */ -#define EXCESS 126 -#define SIGNBIT 0x80000000 -#define HIDDEN (1 << 23) -#define SIGN(fp) ((fp) & SIGNBIT) -#define EXP(fp) (((fp) >> 23) & 0xFF) -#define MANT(fp) (((fp) & 0x7FFFFF) | HIDDEN) -#define PACK(s,e,m) ((s) | ((e) << 23) | (m)) +#define EXCESS 126 +#define SIGNBIT 0x80000000 +#define HIDDEN (1 << 23) +#define SIGN(fp) ((fp)&SIGNBIT) +#define EXP(fp) (((fp) >> 23) & 0xFF) +#define MANT(fp) (((fp)&0x7FFFFF) | HIDDEN) +#define PACK(s, e, m) ((s) | ((e) << 23) | (m)) /* the following deal with IEEE double-precision numbers */ -#define EXCESSD 1022 -#define HIDDEND (1 << 20) -#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) -#define SIGND(fp) ((fp.l.upper) & SIGNBIT) -#define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | \ - (fp.l.lower >> 22)) -#define HIDDEND_LL ((long long)1 << 52) -#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL) -#define PACKD_LL(s,e,m) (((long long)((s)+((e)<<20))<<32)|(m)) +#define EXCESSD 1022 +#define HIDDEND (1 << 20) +#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) +#define SIGND(fp) ((fp.l.upper) & SIGNBIT) +#define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | (fp.l.lower >> 22)) +#define HIDDEND_LL ((long long)1 << 52) +#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL - 1)) | HIDDEND_LL) +#define PACKD_LL(s, e, m) (((long long)((s) + ((e) << 20)) << 32) | (m)) /* the following deal with x86 long double-precision numbers */ -#define EXCESSLD 16382 -#define EXPLD(fp) (fp.l.upper & 0x7fff) -#define SIGNLD(fp) ((fp.l.upper) & 0x8000) +#define EXCESSLD 16382 +#define EXPLD(fp) (fp.l.upper & 0x7fff) +#define SIGNLD(fp) ((fp.l.upper) & 0x8000) /* only for x86 */ union ldouble_long { @@ -115,252 +113,226 @@ union float_long { /* XXX: use gcc/tcc intrinsic ? */ #if defined(TCC_TARGET_I386) #define sub_ddmmss(sh, sl, ah, al, bh, bl) \ - __asm__ ("subl %5,%1\n\tsbbl %3,%0" \ - : "=r" ((USItype) (sh)), \ - "=&r" ((USItype) (sl)) \ - : "0" ((USItype) (ah)), \ - "g" ((USItype) (bh)), \ - "1" ((USItype) (al)), \ - "g" ((USItype) (bl))) -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("mull %3" \ - : "=a" ((USItype) (w0)), \ - "=d" ((USItype) (w1)) \ - : "%0" ((USItype) (u)), \ - "rm" ((USItype) (v))) + __asm__("subl %5,%1\n\tsbbl %3,%0" \ + : "=r"((USItype)(sh)), \ + "=&r"((USItype)(sl)) \ + : "0"((USItype)(ah)), \ + "g"((USItype)(bh)), \ + "1"((USItype)(al)), \ + "g"((USItype)(bl))) +#define umul_ppmm(w1, w0, u, v) \ + __asm__("mull %3" \ + : "=a"((USItype)(w0)), \ + "=d"((USItype)(w1)) \ + : "%0"((USItype)(u)), \ + "rm"((USItype)(v))) #define udiv_qrnnd(q, r, n1, n0, dv) \ - __asm__ ("divl %4" \ - : "=a" ((USItype) (q)), \ - "=d" ((USItype) (r)) \ - : "0" ((USItype) (n0)), \ - "1" ((USItype) (n1)), \ - "rm" ((USItype) (dv))) -#define count_leading_zeros(count, x) \ - do { \ - USItype __cbtmp; \ - __asm__ ("bsrl %1,%0" \ - : "=r" (__cbtmp) : "rm" ((USItype) (x))); \ - (count) = __cbtmp ^ 31; \ - } while (0) + __asm__("divl %4" \ + : "=a"((USItype)(q)), \ + "=d"((USItype)(r)) \ + : "0"((USItype)(n0)), \ + "1"((USItype)(n1)), \ + "rm"((USItype)(dv))) +#define count_leading_zeros(count, x) \ + do { \ + USItype __cbtmp; \ + __asm__("bsrl %1,%0" \ + : "=r"(__cbtmp) \ + : "rm"((USItype)(x))); \ + (count) = __cbtmp ^ 31; \ + } while (0) #else #error unsupported CPU type #endif /* most of this code is taken from libgcc2.c from gcc */ -UDWtype __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp) +UDWtype __udivmoddi4(UDWtype n, UDWtype d, UDWtype* rp) { - DWunion ww; - DWunion nn, dd; - DWunion rr; - UWtype d0, d1, n0, n1, n2; - UWtype q0, q1; - UWtype b, bm; + DWunion ww; + DWunion nn, dd; + DWunion rr; + UWtype d0, d1, n0, n1, n2; + UWtype q0, q1; + UWtype b, bm; - nn.ll = n; - dd.ll = d; + nn.ll = n; + dd.ll = d; - d0 = dd.s.low; - d1 = dd.s.high; - n0 = nn.s.low; - n1 = nn.s.high; + d0 = dd.s.low; + d1 = dd.s.high; + n0 = nn.s.low; + n1 = nn.s.high; #if !defined(UDIV_NEEDS_NORMALIZATION) - if (d1 == 0) - { - if (d0 > n1) - { - /* 0q = nn / 0D */ + if (d1 == 0) { + if (d0 > n1) { + /* 0q = nn / 0D */ - udiv_qrnnd (q0, n0, n1, n0, d0); - q1 = 0; + udiv_qrnnd(q0, n0, n1, n0, d0); + q1 = 0; - /* Remainder in n0. */ - } - else - { - /* qq = NN / 0d */ + /* Remainder in n0. */ + } else { + /* qq = NN / 0d */ - if (d0 == 0) - d0 = 1 / d0; /* Divide intentionally by zero. */ + if (d0 == 0) + d0 = 1 / d0; /* Divide intentionally by zero. */ - udiv_qrnnd (q1, n1, 0, n1, d0); - udiv_qrnnd (q0, n0, n1, n0, d0); + udiv_qrnnd(q1, n1, 0, n1, d0); + udiv_qrnnd(q0, n0, n1, n0, d0); - /* Remainder in n0. */ - } + /* Remainder in n0. */ + } - if (rp != 0) - { - rr.s.low = n0; - rr.s.high = 0; - *rp = rr.ll; - } + if (rp != 0) { + rr.s.low = n0; + rr.s.high = 0; + *rp = rr.ll; + } } #else /* UDIV_NEEDS_NORMALIZATION */ - if (d1 == 0) - { - if (d0 > n1) - { - /* 0q = nn / 0D */ + if (d1 == 0) { + if (d0 > n1) { + /* 0q = nn / 0D */ - count_leading_zeros (bm, d0); + count_leading_zeros(bm, d0); - if (bm != 0) - { - /* Normalize, i.e. make the most significant bit of the - denominator set. */ + if (bm != 0) { + /* Normalize, i.e. make the most significant bit of the + denominator set. */ - d0 = d0 << bm; - n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm)); - n0 = n0 << bm; - } + d0 = d0 << bm; + n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm)); + n0 = n0 << bm; + } - udiv_qrnnd (q0, n0, n1, n0, d0); - q1 = 0; + udiv_qrnnd(q0, n0, n1, n0, d0); + q1 = 0; - /* Remainder in n0 >> bm. */ - } - else - { - /* qq = NN / 0d */ + /* Remainder in n0 >> bm. */ + } else { + /* qq = NN / 0d */ - if (d0 == 0) - d0 = 1 / d0; /* Divide intentionally by zero. */ + if (d0 == 0) + d0 = 1 / d0; /* Divide intentionally by zero. */ - count_leading_zeros (bm, d0); + count_leading_zeros(bm, d0); - if (bm == 0) - { - /* From (n1 >= d0) /\ (the most significant bit of d0 is set), - conclude (the most significant bit of n1 is set) /\ (the - leading quotient digit q1 = 1). + if (bm == 0) { + /* From (n1 >= d0) /\ (the most significant bit of d0 is set), + conclude (the most significant bit of n1 is set) /\ (the + leading quotient digit q1 = 1). - This special case is necessary, not an optimization. - (Shifts counts of W_TYPE_SIZE are undefined.) */ + This special case is necessary, not an optimization. + (Shifts counts of W_TYPE_SIZE are undefined.) */ - n1 -= d0; - q1 = 1; - } - else - { - /* Normalize. */ + n1 -= d0; + q1 = 1; + } else { + /* Normalize. */ - b = W_TYPE_SIZE - bm; + b = W_TYPE_SIZE - bm; - d0 = d0 << bm; - n2 = n1 >> b; - n1 = (n1 << bm) | (n0 >> b); - n0 = n0 << bm; + d0 = d0 << bm; + n2 = n1 >> b; + n1 = (n1 << bm) | (n0 >> b); + n0 = n0 << bm; - udiv_qrnnd (q1, n1, n2, n1, d0); - } + udiv_qrnnd(q1, n1, n2, n1, d0); + } - /* n1 != d0... */ + /* n1 != d0... */ - udiv_qrnnd (q0, n0, n1, n0, d0); + udiv_qrnnd(q0, n0, n1, n0, d0); - /* Remainder in n0 >> bm. */ - } + /* Remainder in n0 >> bm. */ + } - if (rp != 0) - { - rr.s.low = n0 >> bm; - rr.s.high = 0; - *rp = rr.ll; - } + if (rp != 0) { + rr.s.low = n0 >> bm; + rr.s.high = 0; + *rp = rr.ll; + } } #endif /* UDIV_NEEDS_NORMALIZATION */ - else - { - if (d1 > n1) - { - /* 00 = nn / DD */ + else { + if (d1 > n1) { + /* 00 = nn / DD */ - q0 = 0; - q1 = 0; + q0 = 0; + q1 = 0; - /* Remainder in n1n0. */ - if (rp != 0) - { - rr.s.low = n0; - rr.s.high = n1; - *rp = rr.ll; - } - } - else - { - /* 0q = NN / dd */ + /* Remainder in n1n0. */ + if (rp != 0) { + rr.s.low = n0; + rr.s.high = n1; + *rp = rr.ll; + } + } else { + /* 0q = NN / dd */ - count_leading_zeros (bm, d1); - if (bm == 0) - { - /* From (n1 >= d1) /\ (the most significant bit of d1 is set), - conclude (the most significant bit of n1 is set) /\ (the - quotient digit q0 = 0 or 1). + count_leading_zeros(bm, d1); + if (bm == 0) { + /* From (n1 >= d1) /\ (the most significant bit of d1 is set), + conclude (the most significant bit of n1 is set) /\ (the + quotient digit q0 = 0 or 1). - This special case is necessary, not an optimization. */ + This special case is necessary, not an optimization. */ - /* The condition on the next line takes advantage of that - n1 >= d1 (true due to program flow). */ - if (n1 > d1 || n0 >= d0) - { - q0 = 1; - sub_ddmmss (n1, n0, n1, n0, d1, d0); - } - else - q0 = 0; + /* The condition on the next line takes advantage of that + n1 >= d1 (true due to program flow). */ + if (n1 > d1 || n0 >= d0) { + q0 = 1; + sub_ddmmss(n1, n0, n1, n0, d1, d0); + } else + q0 = 0; - q1 = 0; + q1 = 0; - if (rp != 0) - { - rr.s.low = n0; - rr.s.high = n1; - *rp = rr.ll; - } - } - else - { - UWtype m1, m0; - /* Normalize. */ + if (rp != 0) { + rr.s.low = n0; + rr.s.high = n1; + *rp = rr.ll; + } + } else { + UWtype m1, m0; + /* Normalize. */ - b = W_TYPE_SIZE - bm; + b = W_TYPE_SIZE - bm; - d1 = (d1 << bm) | (d0 >> b); - d0 = d0 << bm; - n2 = n1 >> b; - n1 = (n1 << bm) | (n0 >> b); - n0 = n0 << bm; + d1 = (d1 << bm) | (d0 >> b); + d0 = d0 << bm; + n2 = n1 >> b; + n1 = (n1 << bm) | (n0 >> b); + n0 = n0 << bm; - udiv_qrnnd (q0, n1, n2, n1, d1); - umul_ppmm (m1, m0, q0, d0); + udiv_qrnnd(q0, n1, n2, n1, d1); + umul_ppmm(m1, m0, q0, d0); - if (m1 > n1 || (m1 == n1 && m0 > n0)) - { - q0--; - sub_ddmmss (m1, m0, m1, m0, d1, d0); - } + if (m1 > n1 || (m1 == n1 && m0 > n0)) { + q0--; + sub_ddmmss(m1, m0, m1, m0, d1, d0); + } - q1 = 0; + q1 = 0; - /* Remainder in (n1n0 - m1m0) >> bm. */ - if (rp != 0) - { - sub_ddmmss (n1, n0, n1, n0, m1, m0); - rr.s.low = (n1 << b) | (n0 >> bm); - rr.s.high = n1 >> bm; - *rp = rr.ll; - } - } - } + /* Remainder in (n1n0 - m1m0) >> bm. */ + if (rp != 0) { + sub_ddmmss(n1, n0, n1, n0, m1, m0); + rr.s.low = (n1 << b) | (n0 >> bm); + rr.s.high = n1 >> bm; + *rp = rr.ll; + } + } + } } - ww.s.low = q0; - ww.s.high = q1; - return ww.ll; + ww.s.low = q0; + ww.s.high = q1; + return ww.ll; } #define __negdi2(a) (-(a)) @@ -370,21 +342,21 @@ long long __divdi3(long long u, long long v) int c = 0; DWunion uu, vv; DWtype w; - + uu.ll = u; vv.ll = v; - + if (uu.s.high < 0) { c = ~c; - uu.ll = __negdi2 (uu.ll); + uu.ll = __negdi2(uu.ll); } if (vv.s.high < 0) { c = ~c; - vv.ll = __negdi2 (vv.ll); + vv.ll = __negdi2(vv.ll); } - w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0); + w = __udivmoddi4(uu.ll, vv.ll, (UDWtype*)0); if (c) - w = __negdi2 (w); + w = __negdi2(w); return w; } @@ -403,33 +375,33 @@ long long __moddi3(long long u, long long v) int c = 0; DWunion uu, vv; DWtype w; - + uu.ll = u; vv.ll = v; - + if (uu.s.high < 0) { c = ~c; - uu.ll = __negdi2 (uu.ll); + uu.ll = __negdi2(uu.ll); } if (vv.s.high < 0) - vv.ll = __negdi2 (vv.ll); - - __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) &w); + vv.ll = __negdi2(vv.ll); + + __udivmoddi4(uu.ll, vv.ll, (UDWtype*)&w); if (c) - w = __negdi2 (w); + w = __negdi2(w); return w; } unsigned long long __udivdi3(unsigned long long u, unsigned long long v) { - return __udivmoddi4 (u, v, (UDWtype *) 0); + return __udivmoddi4(u, v, (UDWtype*)0); } unsigned long long __umoddi3(unsigned long long u, unsigned long long v) { UDWtype w; - - __udivmoddi4 (u, v, &w); + + __udivmoddi4(u, v, &w); return w; } @@ -495,11 +467,17 @@ long long __tcc_cvt_ftol(long double x) { unsigned c0, c1; long long ret; - __asm__ __volatile__ ("fnstcw %0" : "=m" (c0)); + __asm__ __volatile__("fnstcw %0" + : "=m"(c0)); c1 = c0 | 0x0C00; - __asm__ __volatile__ ("fldcw %0" : : "m" (c1)); - __asm__ __volatile__ ("fistpll %0" : "=m" (ret)); - __asm__ __volatile__ ("fldcw %0" : : "m" (c0)); + __asm__ __volatile__("fldcw %0" + : + : "m"(c1)); + __asm__ __volatile__("fistpll %0" + : "=m"(ret)); + __asm__ __volatile__("fldcw %0" + : + : "m"(c0)); return ret; } #endif @@ -509,7 +487,7 @@ long long __tcc_cvt_ftol(long double x) /* XXX: fix tcc's code generator to do this instead */ float __floatundisf(unsigned long long a) { - DWunion uu; + DWunion uu; XFtype r; uu.ll = a; @@ -524,7 +502,7 @@ float __floatundisf(unsigned long long a) double __floatundidf(unsigned long long a) { - DWunion uu; + DWunion uu; XFtype r; uu.ll = a; @@ -539,7 +517,7 @@ double __floatundidf(unsigned long long a) long double __floatundixf(unsigned long long a) { - DWunion uu; + DWunion uu; XFtype r; uu.ll = a; @@ -552,7 +530,7 @@ long double __floatundixf(unsigned long long a) } } -unsigned long long __fixunssfdi (float a1) +unsigned long long __fixunssfdi(float a1) { register union float_long fl1; register int exp; @@ -561,13 +539,13 @@ unsigned long long __fixunssfdi (float a1) fl1.f = a1; if (fl1.l == 0) - return (0); + return (0); - exp = EXP (fl1.l) - EXCESS - 24; + exp = EXP(fl1.l) - EXCESS - 24; l = MANT(fl1.l); if (exp >= 41) - return (unsigned long long)-1; + return (unsigned long long)-1; else if (exp >= 0) return (unsigned long long)l << exp; else if (exp >= -23) @@ -576,7 +554,7 @@ unsigned long long __fixunssfdi (float a1) return 0; } -unsigned long long __fixunsdfdi (double a1) +unsigned long long __fixunsdfdi(double a1) { register union double_long dl1; register int exp; @@ -585,14 +563,14 @@ unsigned long long __fixunsdfdi (double a1) dl1.d = a1; if (dl1.ll == 0) - return (0); + return (0); - exp = EXPD (dl1) - EXCESSD - 53; + exp = EXPD(dl1) - EXCESSD - 53; l = MANTD_LL(dl1); if (exp >= 12) - return (unsigned long long)-1; + return (unsigned long long)-1; else if (exp >= 0) return l << exp; else if (exp >= -52) @@ -601,7 +579,7 @@ unsigned long long __fixunsdfdi (double a1) return 0; } -unsigned long long __fixunsxfdi (long double a1) +unsigned long long __fixunsxfdi(long double a1) { register union ldouble_long dl1; register int exp; @@ -610,37 +588,40 @@ unsigned long long __fixunsxfdi (long double a1) dl1.ld = a1; if (dl1.l.lower == 0 && dl1.l.upper == 0) - return (0); + return (0); - exp = EXPLD (dl1) - EXCESSLD - 64; + exp = EXPLD(dl1) - EXCESSLD - 64; l = dl1.l.lower; if (exp > 0) - return (unsigned long long)-1; - else if (exp >= -63) + return (unsigned long long)-1; + else if (exp >= -63) return l >> -exp; else return 0; } -long long __fixsfdi (float a1) +long long __fixsfdi(float a1) { - long long ret; int s; + long long ret; + int s; ret = __fixunssfdi((s = a1 >= 0) ? a1 : -a1); return s ? ret : -ret; } -long long __fixdfdi (double a1) +long long __fixdfdi(double a1) { - long long ret; int s; + long long ret; + int s; ret = __fixunsdfdi((s = a1 >= 0) ? a1 : -a1); return s ? ret : -ret; } -long long __fixxfdi (long double a1) +long long __fixxfdi(long double a1) { - long long ret; int s; + long long ret; + int s; ret = __fixunsxfdi((s = a1 >= 0) ? a1 : -a1); return s ? ret : -ret; } @@ -648,33 +629,35 @@ long long __fixxfdi (long double a1) #if defined(TCC_TARGET_X86_64) && !defined(_WIN64) #ifndef __TINYC__ -#include #include +#include #include #else /* Avoid including stdlib.h because it is not easily available when cross compiling */ #include /* size_t definition is needed for a x86_64-tcc to parse memset() */ - void *malloc(unsigned long long); - void *memset(void *s, int c, size_t n); - void free(void*); - void abort(void); +void* malloc(unsigned long long); +void* memset(void* s, int c, size_t n); +void free(void*); +void abort(void); #endif enum __va_arg_type { - __va_gen_reg, __va_float_reg, __va_stack + __va_gen_reg, + __va_float_reg, + __va_stack }; -//This should be in sync with the declaration on our include/stdarg.h +// This should be in sync with the declaration on our include/stdarg.h /* GCC compatible definition of va_list. */ typedef struct { unsigned int gp_offset; unsigned int fp_offset; union { unsigned int overflow_offset; - char *overflow_arg_area; + char* overflow_arg_area; }; - char *reg_save_area; + char* reg_save_area; } __va_list_struct; #undef __va_start @@ -682,17 +665,17 @@ typedef struct { #undef __va_copy #undef __va_end -void __va_start(__va_list_struct *ap, void *fp) +void __va_start(__va_list_struct* ap, void* fp) { memset(ap, 0, sizeof(__va_list_struct)); - *ap = *(__va_list_struct *)((char *)fp - 16); - ap->overflow_arg_area = (char *)fp + ap->overflow_offset; - ap->reg_save_area = (char *)fp - 176 - 16; + *ap = *(__va_list_struct*)((char*)fp - 16); + ap->overflow_arg_area = (char*)fp + ap->overflow_offset; + ap->reg_save_area = (char*)fp - 176 - 16; } -void *__va_arg(__va_list_struct *ap, - enum __va_arg_type arg_type, - int size, int align) +void* __va_arg(__va_list_struct* ap, + enum __va_arg_type arg_type, + int size, int align) { size = (size + 7) & ~7; align = (align + 7) & ~7; @@ -731,30 +714,30 @@ void *__va_arg(__va_list_struct *ap, /* Flushing for tccrun */ #if defined(TCC_TARGET_X86_64) || defined(TCC_TARGET_I386) -void __clear_cache(void *beginning, void *end) +void __clear_cache(void* beginning, void* end) { } #elif defined(TCC_TARGET_ARM) #define _GNU_SOURCE -#include -#include #include +#include +#include -void __clear_cache(void *beginning, void *end) +void __clear_cache(void* beginning, void* end) { /* __ARM_NR_cacheflush is kernel private and should not be used in user space. * However, there is no ARM asm parser in tcc so we use it for now */ #if 1 syscall(__ARM_NR_cacheflush, beginning, end, 0); #else - __asm__ ("push {r7}\n\t" - "mov r7, #0xf0002\n\t" - "mov r2, #0\n\t" - "swi 0\n\t" - "pop {r7}\n\t" - "ret"); + __asm__("push {r7}\n\t" + "mov r7, #0xf0002\n\t" + "mov r2, #0\n\t" + "swi 0\n\t" + "pop {r7}\n\t" + "ret"); #endif } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/math/acosh.c b/programs/develop/ktcc/trunk/libc.obj/source/math/acosh.c index 6e13bbe6ec..287ecac165 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/math/acosh.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/math/acosh.c @@ -1,8 +1,7 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include -double -acosh(double x) +double acosh(double x) { - return log(x + sqrt(x*x - 1)); -} + return log(x + sqrt(x * x - 1)); +} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/math/asinh.c b/programs/develop/ktcc/trunk/libc.obj/source/math/asinh.c index e27e20da7e..ab22866009 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/math/asinh.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/math/asinh.c @@ -1,9 +1,7 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include -double -asinh(double x) +double asinh(double x) { - return x>0 ? log(x + sqrt(x*x + 1)) : -log(sqrt(x*x+1)-x); + return x > 0 ? log(x + sqrt(x * x + 1)) : -log(sqrt(x * x + 1) - x); } - diff --git a/programs/develop/ktcc/trunk/libc.obj/source/math/atan2.s b/programs/develop/ktcc/trunk/libc.obj/source/math/atan2.s index 0e58aa7654..cc60044a72 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/math/atan2.s +++ b/programs/develop/ktcc/trunk/libc.obj/source/math/atan2.s @@ -30,7 +30,7 @@ doit: fpatan ret isanan: - movl $1, _errno + movl $1, __errno fstp %st(0) fstp %st(0) fldl nan diff --git a/programs/develop/ktcc/trunk/libc.obj/source/math/atanh.c b/programs/develop/ktcc/trunk/libc.obj/source/math/atanh.c index 8335dc78b3..dd581cce7a 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/math/atanh.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/math/atanh.c @@ -1,8 +1,7 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include -double -atanh(double x) +double atanh(double x) { - return log((1+x)/(1-x)) / 2.0; + return log((1 + x) / (1 - x)) / 2.0; } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/math/cosh.c b/programs/develop/ktcc/trunk/libc.obj/source/math/cosh.c index c2cca978ac..f01bb26c50 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/math/cosh.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/math/cosh.c @@ -3,6 +3,6 @@ double cosh(double x) { - const double ebig = exp(fabs(x)); - return (ebig + 1.0/ebig) / 2.0; + const double ebig = exp(fabs(x)); + return (ebig + 1.0 / ebig) / 2.0; } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/math/frexp.c b/programs/develop/ktcc/trunk/libc.obj/source/math/frexp.c index 913f16f06b..fc9f26a315 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/math/frexp.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/math/frexp.c @@ -1,26 +1,25 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include -double -frexp(double x, int *exptr) +double frexp(double x, int* exptr) { - union { - double d; - unsigned char c[8]; - } u; + union { + double d; + unsigned char c[8]; + } u; - u.d = x; - /* - * The format of the number is: - * Sign, 12 exponent bits, 51 mantissa bits - * The exponent is 1023 biased and there is an implicit zero. - * We get the exponent from the upper bits and set the exponent - * to 0x3fe (1022). - */ - *exptr = (int)(((u.c[7] & 0x7f) << 4) | (u.c[6] >> 4)) - 1022; - u.c[7] &= 0x80; - u.c[7] |= 0x3f; - u.c[6] &= 0x0f; - u.c[6] |= 0xe0; - return u.d; + u.d = x; + /* + * The format of the number is: + * Sign, 12 exponent bits, 51 mantissa bits + * The exponent is 1023 biased and there is an implicit zero. + * We get the exponent from the upper bits and set the exponent + * to 0x3fe (1022). + */ + *exptr = (int)(((u.c[7] & 0x7f) << 4) | (u.c[6] >> 4)) - 1022; + u.c[7] &= 0x80; + u.c[7] |= 0x3f; + u.c[6] &= 0x0f; + u.c[6] |= 0xe0; + return u.d; } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/math/hypot.c b/programs/develop/ktcc/trunk/libc.obj/source/math/hypot.c index 00b81691b4..18bffb907e 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/math/hypot.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/math/hypot.c @@ -17,84 +17,80 @@ */ /// #include -#include #include - +#include + /* Approximate square roots of DBL_MAX and DBL_MIN. Numbers between these two shouldn't neither overflow nor underflow when squared. */ #define __SQRT_DBL_MAX 1.3e+154 #define __SQRT_DBL_MIN 2.3e-162 - -double -hypot(double x, double y) + +double hypot(double x, double y) { - double abig = fabs(x), asmall = fabs(y); - double ratio; - - /* Make abig = max(|x|, |y|), asmall = min(|x|, |y|). */ - if (abig < asmall) - { - double temp = abig; - - abig = asmall; - asmall = temp; + double abig = fabs(x), asmall = fabs(y); + double ratio; + + /* Make abig = max(|x|, |y|), asmall = min(|x|, |y|). */ + if (abig < asmall) { + double temp = abig; + + abig = asmall; + asmall = temp; } - - /* Trivial case. */ - if (asmall == 0.) - return abig; - - /* Scale the numbers as much as possible by using its ratio. - For example, if both ABIG and ASMALL are VERY small, then - X^2 + Y^2 might be VERY inaccurate due to loss of - significant digits. Dividing ASMALL by ABIG scales them - to a certain degree, so that accuracy is better. */ - - if ((ratio = asmall / abig) > __SQRT_DBL_MIN && abig < __SQRT_DBL_MAX) - return abig * sqrt(1.0 + ratio*ratio); - else - { - /* Slower but safer algorithm due to Moler and Morrison. Never - produces any intermediate result greater than roughly the - larger of X and Y. Should converge to machine-precision - accuracy in 3 iterations. */ - - double r = ratio*ratio, t, s, p = abig, q = asmall; - - do { - t = 4. + r; - if (t == 4.) - break; - s = r / t; - p += 2. * s * p; - q *= s; - r = (q / p) * (q / p); - } while (1); - - return p; + + /* Trivial case. */ + if (asmall == 0.) + return abig; + + /* Scale the numbers as much as possible by using its ratio. + For example, if both ABIG and ASMALL are VERY small, then + X^2 + Y^2 might be VERY inaccurate due to loss of + significant digits. Dividing ASMALL by ABIG scales them + to a certain degree, so that accuracy is better. */ + + if ((ratio = asmall / abig) > __SQRT_DBL_MIN && abig < __SQRT_DBL_MAX) + return abig * sqrt(1.0 + ratio * ratio); + else { + /* Slower but safer algorithm due to Moler and Morrison. Never + produces any intermediate result greater than roughly the + larger of X and Y. Should converge to machine-precision + accuracy in 3 iterations. */ + + double r = ratio * ratio, t, s, p = abig, q = asmall; + + do { + t = 4. + r; + if (t == 4.) + break; + s = r / t; + p += 2. * s * p; + q *= s; + r = (q / p) * (q / p); + } while (1); + + return p; } } - -#ifdef TEST - + +#ifdef TEST + #include - -int -main(void) + +int main(void) { - printf("hypot(3, 4) =\t\t\t %25.17e\n", hypot(3., 4.)); - printf("hypot(3*10^150, 4*10^150) =\t %25.17g\n", hypot(3.e+150, 4.e+150)); - printf("hypot(3*10^306, 4*10^306) =\t %25.17g\n", hypot(3.e+306, 4.e+306)); - printf("hypot(3*10^-320, 4*10^-320) =\t %25.17g\n", - hypot(3.e-320, 4.e-320)); - printf("hypot(0.7*DBL_MAX, 0.7*DBL_MAX) =%25.17g\n", - hypot(0.7*DBL_MAX, 0.7*DBL_MAX)); - printf("hypot(DBL_MAX, 1.0) =\t\t %25.17g\n", hypot(DBL_MAX, 1.0)); - printf("hypot(1.0, DBL_MAX) =\t\t %25.17g\n", hypot(1.0, DBL_MAX)); - printf("hypot(0.0, DBL_MAX) =\t\t %25.17g\n", hypot(0.0, DBL_MAX)); - - return 0; + printf("hypot(3, 4) =\t\t\t %25.17e\n", hypot(3., 4.)); + printf("hypot(3*10^150, 4*10^150) =\t %25.17g\n", hypot(3.e+150, 4.e+150)); + printf("hypot(3*10^306, 4*10^306) =\t %25.17g\n", hypot(3.e+306, 4.e+306)); + printf("hypot(3*10^-320, 4*10^-320) =\t %25.17g\n", + hypot(3.e-320, 4.e-320)); + printf("hypot(0.7*DBL_MAX, 0.7*DBL_MAX) =%25.17g\n", + hypot(0.7 * DBL_MAX, 0.7 * DBL_MAX)); + printf("hypot(DBL_MAX, 1.0) =\t\t %25.17g\n", hypot(DBL_MAX, 1.0)); + printf("hypot(1.0, DBL_MAX) =\t\t %25.17g\n", hypot(1.0, DBL_MAX)); + printf("hypot(0.0, DBL_MAX) =\t\t %25.17g\n", hypot(0.0, DBL_MAX)); + + return 0; } - + #endif diff --git a/programs/develop/ktcc/trunk/libc.obj/source/math/ldexp.c b/programs/develop/ktcc/trunk/libc.obj/source/math/ldexp.c index 818cab7578..e76a13fdd5 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/math/ldexp.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/math/ldexp.c @@ -2,31 +2,27 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include -double -ldexp(double v, int e) +double ldexp(double v, int e) { - double two = 2.0; + double two = 2.0; - if (e < 0) - { - e = -e; /* This just might overflow on two-complement machines. */ - if (e < 0) return 0.0; - while (e > 0) - { - if (e & 1) v /= two; - two *= two; - e >>= 1; + if (e < 0) { + e = -e; /* This just might overflow on two-complement machines. */ + if (e < 0) + return 0.0; + while (e > 0) { + if (e & 1) + v /= two; + two *= two; + e >>= 1; + } + } else if (e > 0) { + while (e > 0) { + if (e & 1) + v *= two; + two *= two; + e >>= 1; + } } - } - else if (e > 0) - { - while (e > 0) - { - if (e & 1) v *= two; - two *= two; - e >>= 1; - } - } - return v; + return v; } - diff --git a/programs/develop/ktcc/trunk/libc.obj/source/math/sinh.c b/programs/develop/ktcc/trunk/libc.obj/source/math/sinh.c index d00e2803e1..cd58a9bc18 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/math/sinh.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/math/sinh.c @@ -3,14 +3,11 @@ double sinh(double x) { - if(x >= 0.0) - { - const double epos = exp(x); - return (epos - 1.0/epos) / 2.0; - } - else - { - const double eneg = exp(-x); - return (1.0/eneg - eneg) / 2.0; - } + if (x >= 0.0) { + const double epos = exp(x); + return (epos - 1.0 / epos) / 2.0; + } else { + const double eneg = exp(-x); + return (1.0 / eneg - eneg) / 2.0; + } } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/math/tanh.c b/programs/develop/ktcc/trunk/libc.obj/source/math/tanh.c index c2eb966319..0449a2dbd1 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/math/tanh.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/math/tanh.c @@ -3,15 +3,13 @@ double tanh(double x) { - if (x > 50) - return 1; - else if (x < -50) - return -1; - else - { - const double ebig = exp(x); - const double esmall = 1.0/ebig; - return (ebig - esmall) / (ebig + esmall); - } + if (x > 50) + return 1; + else if (x < -50) + return -1; + else { + const double ebig = exp(x); + const double esmall = 1.0 / ebig; + return (ebig - esmall) / (ebig + esmall); + } } - diff --git a/programs/develop/ktcc/trunk/libc.obj/source/misc/basename.c b/programs/develop/ktcc/trunk/libc.obj/source/misc/basename.c index 99b37d7b50..ad60f84799 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/misc/basename.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/misc/basename.c @@ -1,13 +1,15 @@ -#include #include +#include -char *basename(char *s) +char* basename(char* s) { size_t i; - if (!s || !*s) return "."; - i = strlen(s)-1; - for (; i&&s[i]=='/'; i--) s[i] = 0; - for (; i&&s[i-1]!='/'; i--); - return s+i; + if (!s || !*s) + return "."; + i = strlen(s) - 1; + for (; i && s[i] == '/'; i--) + s[i] = 0; + for (; i && s[i - 1] != '/'; i--) + ; + return s + i; } - diff --git a/programs/develop/ktcc/trunk/libc.obj/source/misc/dirname.c b/programs/develop/ktcc/trunk/libc.obj/source/misc/dirname.c index 1dc6c08241..2a52ddef0f 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/misc/dirname.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/misc/dirname.c @@ -1,14 +1,21 @@ -#include #include +#include -char *dirname(char *s) +char* dirname(char* s) { size_t i; - if (!s || !*s) return "."; - i = strlen(s)-1; - for (; s[i]=='/'; i--) if (!i) return "/"; - for (; s[i]!='/'; i--) if (!i) return "."; - for (; s[i]=='/'; i--) if (!i) return "/"; - s[i+1] = 0; + if (!s || !*s) + return "."; + i = strlen(s) - 1; + for (; s[i] == '/'; i--) + if (!i) + return "/"; + for (; s[i] != '/'; i--) + if (!i) + return "."; + for (; s[i] == '/'; i--) + if (!i) + return "/"; + s[i + 1] = 0; return s; -} +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/___chkstk_ms.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/___chkstk_ms.c index c446841ab4..8b07e38951 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/___chkstk_ms.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/___chkstk_ms.c @@ -1 +1 @@ -void ___chkstk_ms() {} \ No newline at end of file +void ___chkstk_ms() { } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/abs.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/abs.c index 0e7cebef28..57a28b0dde 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/abs.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/abs.c @@ -2,5 +2,5 @@ int abs(int a) { - return a>0 ? a : -a; + return a > 0 ? a : -a; } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/assert.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/assert.c index 553b90465b..7efb8001c4 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/assert.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/assert.c @@ -1,14 +1,13 @@ #include #include - #pragma GCC push_options #pragma GCC optimize("O0") -void __assert_fail(const char *expr, const char *file, int line, const char *func) +void __assert_fail(const char* expr, const char* file, int line, const char* func) { - fprintf(stdout, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line); - exit(0); + fprintf(stdout, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line); + exit(0); } #pragma GCC pop_options \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atof.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atof.c index 0db314b442..30d7c7401a 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atof.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atof.c @@ -1,7 +1,7 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include -double atof(const char *ascii) +double atof(const char* ascii) { - return strtod(ascii, 0); + return strtod(ascii, 0); } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atoi.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atoi.c index 5252fc8a20..a150d5c225 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atoi.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atoi.c @@ -1,21 +1,25 @@ -#include #include +#include /* ** atoi(s) - convert s to integer. */ -int atoi(const char *s) +int atoi(const char* s) { int sign, n; - while(isspace(*s)) ++s; + while (isspace(*s)) + ++s; sign = 1; - - switch(*s) { - case '-': sign = -1; - case '+': ++s; + + switch (*s) { + case '-': + sign = -1; + case '+': + ++s; } - + n = 0; - while(isdigit(*s)) n = 10 * n + *s++ - '0'; + while (isdigit(*s)) + n = 10 * n + *s++ - '0'; return (sign * n); } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atol.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atol.c index fc6251e6a9..484734c7f6 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atol.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atol.c @@ -1,17 +1,20 @@ -#include #include +#include -long atol(const char *s) +long atol(const char* s) { - long n=0; - int neg=0; - while (isspace(*s)) s++; - switch (*s) { - case '-': neg=1; - case '+': s++; - } - /* Compute n as a negative number to avoid overflow on LONG_MIN */ - while (isdigit(*s)) - n = 10*n - (*s++ - '0'); - return neg ? n : -n; + long n = 0; + int neg = 0; + while (isspace(*s)) + s++; + switch (*s) { + case '-': + neg = 1; + case '+': + s++; + } + /* Compute n as a negative number to avoid overflow on LONG_MIN */ + while (isdigit(*s)) + n = 10 * n - (*s++ - '0'); + return neg ? n : -n; } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atoll.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atoll.c index f8060d7546..f0fd778416 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atoll.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atoll.c @@ -1,17 +1,20 @@ -#include #include +#include -long long atoll(const char *s) +long long atoll(const char* s) { - long long n=0; - int neg=0; - while (isspace(*s)) s++; - switch (*s) { - case '-': neg=1; - case '+': s++; - } - /* Compute n as a negative number to avoid overflow on LLONG_MIN */ - while (isdigit(*s)) - n = 10*n - (*s++ - '0'); - return neg ? n : -n; + long long n = 0; + int neg = 0; + while (isspace(*s)) + s++; + switch (*s) { + case '-': + neg = 1; + case '+': + s++; + } + /* Compute n as a negative number to avoid overflow on LLONG_MIN */ + while (isdigit(*s)) + n = 10 * n - (*s++ - '0'); + return neg ? n : -n; } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/calloc.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/calloc.c index 0fd70a627c..48f20eec1e 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/calloc.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/calloc.c @@ -1,13 +1,14 @@ -#include #include +#include #include -void *calloc(size_t num, size_t size) { - void *ptr = _ksys_alloc(num*size); - if(!ptr){ - errno = ENOMEM; +void* calloc(size_t num, size_t size) +{ + void* ptr = _ksys_alloc(num * size); + if (!ptr) { + __errno = ENOMEM; return NULL; } - memset(ptr, 0, num*size); + memset(ptr, 0, num * size); return ptr; } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/exit.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/exit.c index 7827b88af9..1e3bebdc01 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/exit.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/exit.c @@ -5,7 +5,7 @@ void exit(int status) { - if(__con_is_load){ + if (__con_is_load) { con_exit(status); } _ksys_exit(); diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/free.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/free.c index b87df191b4..afce966cc5 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/free.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/free.c @@ -1,6 +1,7 @@ #include #include -void free(void *ptr) { +void free(void* ptr) +{ _ksys_free(ptr); } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/itoa.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/itoa.c index f82140faab..aa2003d698 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/itoa.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/itoa.c @@ -1,23 +1,23 @@ #include #include -char *__reverse(char *str) +char* __reverse(char* str) { - char tmp, *src, *dst; - size_t len; - if (str != NULL){ - len = strlen (str); - if (len > 1) { - src = str; - dst = src + len - 1; - while (src < dst) { - tmp = *src; - *src++ = *dst; - *dst-- = tmp; - } - } - } - return str; + char tmp, *src, *dst; + size_t len; + if (str != NULL) { + len = strlen(str); + if (len > 1) { + src = str; + dst = src + len - 1; + while (src < dst) { + tmp = *src; + *src++ = *dst; + *dst-- = tmp; + } + } + } + return str; } /* itoa from K&R */ @@ -25,13 +25,13 @@ void itoa(int n, char s[]) { int i, sign; - if ((sign = n) < 0) /* record sign */ - n = -n; /* make n positive */ + if ((sign = n) < 0) /* record sign */ + n = -n; /* make n positive */ i = 0; - do { /* generate digits in reverse order */ + do { /* generate digits in reverse order */ s[i++] = n % 10 + '0'; /* get next digit */ - } while ((n /= 10) > 0); /* delete it */ + } while ((n /= 10) > 0); /* delete it */ if (sign < 0) s[i++] = '-'; diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/labs.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/labs.c index 2aca5fc182..56d6592e5d 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/labs.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/labs.c @@ -2,5 +2,5 @@ long labs(long a) { - return a>0 ? a : -a; + return a > 0 ? a : -a; } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/llabs.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/llabs.c index 87a10037f2..780123c99e 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/llabs.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/llabs.c @@ -2,5 +2,5 @@ long long llabs(long long a) { - return a>0 ? a : -a; + return a > 0 ? a : -a; } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/malloc.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/malloc.c index e8d6a43984..c96d5a521d 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/malloc.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/malloc.c @@ -1,6 +1,7 @@ #include #include -void *malloc(size_t size) { +void* malloc(size_t size) +{ return _ksys_alloc(size); } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/qsort.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/qsort.c index 456834ffe7..2c78ced12f 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/qsort.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/qsort.c @@ -29,13 +29,13 @@ * The MTHREShold is where we stop finding a better median. */ -#define THRESH 4 /* threshold for insertion */ -#define MTHRESH 6 /* threshold for median */ +#define THRESH 4 /* threshold for insertion */ +#define MTHRESH 6 /* threshold for median */ -static int (*qcmp)(const void *, const void *); /* the comparison routine */ -static int qsz; /* size of each record */ -static int thresh; /* THRESHold in chars */ -static int mthresh; /* MTHRESHold in chars */ +static int (*qcmp)(const void*, const void*); /* the comparison routine */ +static int qsz; /* size of each record */ +static int thresh; /* THRESHold in chars */ +static int mthresh; /* MTHRESHold in chars */ /* * qst: @@ -52,117 +52,101 @@ static int mthresh; /* MTHRESHold in chars */ * (And there are only three places where this is done). */ -static void -qst(char *base, char *max) +static void qst(char* base, char* max) { - char c, *i, *j, *jj; - int ii; - char *mid, *tmp; - int lo, hi; + char c, *i, *j, *jj; + int ii; + char *mid, *tmp; + int lo, hi; - /* - * At the top here, lo is the number of characters of elements in the - * current partition. (Which should be max - base). - * Find the median of the first, last, and middle element and make - * that the middle element. Set j to largest of first and middle. - * If max is larger than that guy, then it's that guy, else compare - * max with loser of first and take larger. Things are set up to - * prefer the middle, then the first in case of ties. - */ - lo = max - base; /* number of elements as chars */ - do { - mid = i = base + qsz * ((lo / qsz) >> 1); - if (lo >= mthresh) - { - j = (qcmp((jj = base), i) > 0 ? jj : i); - if (qcmp(j, (tmp = max - qsz)) > 0) - { - /* switch to first loser */ - j = (j == jj ? i : jj); - if (qcmp(j, tmp) < 0) - j = tmp; - } - if (j != i) - { - ii = qsz; - do { - c = *i; - *i++ = *j; - *j++ = c; - } while (--ii); - } - } /* - * Semi-standard quicksort partitioning/swapping + * At the top here, lo is the number of characters of elements in the + * current partition. (Which should be max - base). + * Find the median of the first, last, and middle element and make + * that the middle element. Set j to largest of first and middle. + * If max is larger than that guy, then it's that guy, else compare + * max with loser of first and take larger. Things are set up to + * prefer the middle, then the first in case of ties. */ - for (i = base, j = max - qsz; ; ) - { - while (i < mid && qcmp(i, mid) <= 0) - i += qsz; - while (j > mid) - { - if (qcmp(mid, j) <= 0) - { - j -= qsz; - continue; - } - tmp = i + qsz; /* value of i after swap */ - if (i == mid) - { - /* j <-> mid, new mid is j */ - mid = jj = j; - } - else - { - /* i <-> j */ - jj = j; - j -= qsz; - } - goto swap; - } - if (i == mid) - { - break; - } - else - { - /* i <-> mid, new mid is i */ - jj = mid; - tmp = mid = i; /* value of i after swap */ - j -= qsz; - } - swap: - ii = qsz; - do { - c = *i; - *i++ = *jj; - *jj++ = c; - } while (--ii); - i = tmp; - } - /* - * Look at sizes of the two partitions, do the smaller - * one first by recursion, then do the larger one by - * making sure lo is its size, base and max are update - * correctly, and branching back. But only repeat - * (recursively or by branching) if the partition is - * of at least size THRESH. - */ - i = (j = mid) + qsz; - if ((lo = j - base) <= (hi = max - i)) - { - if (lo >= thresh) - qst(base, j); - base = i; - lo = hi; - } - else - { - if (hi >= thresh) - qst(i, max); - max = j; - } - } while (lo >= thresh); + lo = max - base; /* number of elements as chars */ + do { + mid = i = base + qsz * ((lo / qsz) >> 1); + if (lo >= mthresh) { + j = (qcmp((jj = base), i) > 0 ? jj : i); + if (qcmp(j, (tmp = max - qsz)) > 0) { + /* switch to first loser */ + j = (j == jj ? i : jj); + if (qcmp(j, tmp) < 0) + j = tmp; + } + if (j != i) { + ii = qsz; + do { + c = *i; + *i++ = *j; + *j++ = c; + } while (--ii); + } + } + /* + * Semi-standard quicksort partitioning/swapping + */ + for (i = base, j = max - qsz;;) { + while (i < mid && qcmp(i, mid) <= 0) + i += qsz; + while (j > mid) { + if (qcmp(mid, j) <= 0) { + j -= qsz; + continue; + } + tmp = i + qsz; /* value of i after swap */ + if (i == mid) { + /* j <-> mid, new mid is j */ + mid = jj = j; + } else { + /* i <-> j */ + jj = j; + j -= qsz; + } + goto swap; + } + if (i == mid) { + break; + } else { + /* i <-> mid, new mid is i */ + jj = mid; + tmp = mid = i; /* value of i after swap */ + j -= qsz; + } + swap: + ii = qsz; + do { + c = *i; + *i++ = *jj; + *jj++ = c; + } while (--ii); + i = tmp; + } + /* + * Look at sizes of the two partitions, do the smaller + * one first by recursion, then do the larger one by + * making sure lo is its size, base and max are update + * correctly, and branching back. But only repeat + * (recursively or by branching) if the partition is + * of at least size THRESH. + */ + i = (j = mid) + qsz; + if ((lo = j - base) <= (hi = max - i)) { + if (lo >= thresh) + qst(base, j); + base = i; + lo = hi; + } else { + if (hi >= thresh) + qst(i, max); + max = j; + } + } while (lo >= thresh); } /* @@ -172,67 +156,59 @@ qst(char *base, char *max) * It's not... */ -void -qsort(void *base0, size_t n, size_t size, int (*compar)(const void *, const void *)) +void qsort(void* base0, size_t n, size_t size, int (*compar)(const void*, const void*)) { - char *base = (char *)base0; - char c, *i, *j, *lo, *hi; - char *min, *max; + char* base = (char*)base0; + char c, *i, *j, *lo, *hi; + char *min, *max; - if (n <= 1) - return; - qsz = size; - qcmp = compar; - thresh = qsz * THRESH; - mthresh = qsz * MTHRESH; - max = base + n * qsz; - if (n >= THRESH) - { - qst(base, max); - hi = base + thresh; - } - else - { - hi = max; - } - /* - * First put smallest element, which must be in the first THRESH, in - * the first position as a sentinel. This is done just by searching - * the first THRESH elements (or the first n if n < THRESH), finding - * the min, and swapping it into the first position. - */ - for (j = lo = base; (lo += qsz) < hi; ) - if (qcmp(j, lo) > 0) - j = lo; - if (j != base) - { - /* swap j into place */ - for (i = base, hi = base + qsz; i < hi; ) - { - c = *j; - *j++ = *i; - *i++ = c; + if (n <= 1) + return; + qsz = size; + qcmp = compar; + thresh = qsz * THRESH; + mthresh = qsz * MTHRESH; + max = base + n * qsz; + if (n >= THRESH) { + qst(base, max); + hi = base + thresh; + } else { + hi = max; } - } - /* - * With our sentinel in place, we now run the following hyper-fast - * insertion sort. For each remaining element, min, from [1] to [n-1], - * set hi to the index of the element AFTER which this one goes. - * Then, do the standard insertion sort shift on a character at a time - * basis for each element in the frob. - */ - for (min = base; (hi = min += qsz) < max; ) - { - while (qcmp(hi -= qsz, min) > 0) - /* void */; - if ((hi += qsz) != min) { - for (lo = min + qsz; --lo >= min; ) - { - c = *lo; - for (i = j = lo; (j -= qsz) >= hi; i = j) - *i = *j; - *i = c; - } + /* + * First put smallest element, which must be in the first THRESH, in + * the first position as a sentinel. This is done just by searching + * the first THRESH elements (or the first n if n < THRESH), finding + * the min, and swapping it into the first position. + */ + for (j = lo = base; (lo += qsz) < hi;) + if (qcmp(j, lo) > 0) + j = lo; + if (j != base) { + /* swap j into place */ + for (i = base, hi = base + qsz; i < hi;) { + c = *j; + *j++ = *i; + *i++ = c; + } + } + /* + * With our sentinel in place, we now run the following hyper-fast + * insertion sort. For each remaining element, min, from [1] to [n-1], + * set hi to the index of the element AFTER which this one goes. + * Then, do the standard insertion sort shift on a character at a time + * basis for each element in the frob. + */ + for (min = base; (hi = min += qsz) < max;) { + while (qcmp(hi -= qsz, min) > 0) + /* void */; + if ((hi += qsz) != min) { + for (lo = min + qsz; --lo >= min;) { + c = *lo; + for (i = j = lo; (j -= qsz) >= hi; i = j) + *i = *j; + *i = c; + } + } } - } } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/rand.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/rand.c index c000cd248c..e88a59f6e4 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/rand.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/rand.c @@ -1,15 +1,15 @@ -#include #include +#include static uint64_t seed; void srand(unsigned s) { - seed = s-1; + seed = s - 1; } int rand(void) { - seed = 6364136223846793005ULL*seed + 1; - return seed>>33; + seed = 6364136223846793005ULL * seed + 1; + return seed >> 33; } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/realloc.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/realloc.c index 0eb04767ac..6278a91999 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/realloc.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/realloc.c @@ -1,6 +1,7 @@ #include #include -void *realloc(void *ptr, size_t newsize) { +void* realloc(void* ptr, size_t newsize) +{ return _ksys_realloc(ptr, newsize); } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/strtod.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/strtod.c index f095b36902..725c854897 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/strtod.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/strtod.c @@ -1,17 +1,19 @@ - /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include -#define unconst(__v, __t) __extension__ ({union { const __t __cp; __t __p; } __q; __q.__cp = __v; __q.__p;}) +#ifndef unconst +#define unconst(__v, __t) __extension__({union { const __t __cp; __t __p; } __q; __q.__cp = __v; __q.__p; }) +#endif -double strtod(const char *s, char **sret) +double strtod(const char* s, char** sret) { - long double r; /* result */ - int e; /* exponent */ - long double d; /* scale */ - int sign; /* +- 1.0 */ + long double r; /* result */ + int e; /* exponent */ + long double d; /* scale */ + int sign; /* +- 1.0 */ int esign; int i; - int flags=0; + int flags = 0; r = 0.0; sign = 1.0; @@ -20,30 +22,26 @@ double strtod(const char *s, char **sret) while ((*s == ' ') || (*s == '\t')) s++; - + if (*s == '+') s++; - else if (*s == '-') - { + else if (*s == '-') { sign = -1; s++; } - while ((*s >= '0') && (*s <= '9')) - { + while ((*s >= '0') && (*s <= '9')) { flags |= 1; r *= 10.0; r += *s - '0'; s++; } - if (*s == '.') - { + if (*s == '.') { d = 0.1L; s++; - - while ((*s >= '0') && (*s <= '9')) - { + + while ((*s >= '0') && (*s <= '9')) { flags |= 2; r += d * (*s - '0'); s++; @@ -51,33 +49,28 @@ double strtod(const char *s, char **sret) } } - if (flags == 0) - { + if (flags == 0) { if (sret) - *sret = unconst(s, char *); + *sret = unconst(s, char*); return 0; } - if ((*s == 'e') || (*s == 'E')) - { + if ((*s == 'e') || (*s == 'E')) { s++; if (*s == '+') s++; - else if (*s == '-') - { + else if (*s == '-') { s++; esign = -1; } - - if ((*s < '0') || (*s > '9')) - { + + if ((*s < '0') || (*s > '9')) { if (sret) - *sret = unconst(s, char *); + *sret = unconst(s, char*); return r; } - while ((*s >= '0') && (*s <= '9')) - { + while ((*s >= '0') && (*s <= '9')) { e *= 10; e += *s - '0'; s++; @@ -91,6 +84,6 @@ double strtod(const char *s, char **sret) r *= 10.0; if (sret) - *sret = unconst(s, char *); + *sret = unconst(s, char*); return r * sign; -} \ No newline at end of file +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/strtol.c b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/strtol.c index eb6738e79b..91392c1a0e 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdlib/strtol.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdlib/strtol.c @@ -1,73 +1,72 @@ -#include -#include #include +#include +#include int getdigit(char ch, int base) { - if (isdigit(ch)) ch-= '0'; - else - if (isalpha(ch) && ch <= 'Z') ch = 10 + ch - 'A'; - else - if (isalpha(ch)) ch = 10 + ch - 'a'; - else - return -1; - - if (ch / base != 0) return -1; + if (isdigit(ch)) + ch -= '0'; + else if (isalpha(ch) && ch <= 'Z') + ch = 10 + ch - 'A'; + else if (isalpha(ch)) + ch = 10 + ch - 'a'; + else + return -1; - return ch; + if (ch / base != 0) + return -1; + + return ch; } - -long int strtol (const char* str, char** endptr, int base) +long int strtol(const char* str, char** endptr, int base) { long int res = 0; - int sign = 1; + int sign = 1; - if (base > 36) - { - errno = EINVAL; - goto bye; - } + if (base > 36) { + errno = EINVAL; + goto bye; + } - while (isspace(*str)) str++; + while (isspace(*str)) + str++; - if (*str == '-') { sign = -1; str++; } - else - if (*str == '+') str++; + if (*str == '-') { + sign = -1; + str++; + } else if (*str == '+') + str++; - if (base == 0 || base == 16) - { - if (*str == '0' && (str[1] == 'x' || str[1] == 'X')) - { - base = 16; - str += 2; - } - } + if (base == 0 || base == 16) { + if (*str == '0' && (str[1] == 'x' || str[1] == 'X')) { + base = 16; + str += 2; + } + } - if (base == 0 && *str == '0') base = 8; + if (base == 0 && *str == '0') + base = 8; - if (base == 0) base = 10; + if (base == 0) + base = 10; - - int digit; - while ((digit = getdigit(*str, base)) >= 0) - { - res = base * res + digit; - str++; - if (res < 0) - { - errno = ERANGE; - if (sign > 0) - res = LONG_MAX; - else - res = LONG_MIN; - } - } + int digit; + while ((digit = getdigit(*str, base)) >= 0) { + res = base * res + digit; + str++; + if (res < 0) { + errno = ERANGE; + if (sign > 0) + res = LONG_MAX; + else + res = LONG_MIN; + } + } bye: - if (endptr) - *endptr = (char*)str; + if (endptr) + *endptr = (char*)str; - return res * sign; + return res * sign; } - diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/memchr.c b/programs/develop/ktcc/trunk/libc.obj/source/string/memchr.c index 348db6bece..c43a486514 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/memchr.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/memchr.c @@ -1,24 +1,20 @@ -/* memchr( const void *, int, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -void * memchr( const void * s, int c, size_t n ) -{ - const unsigned char * p = ( const unsigned char * ) s; - - while ( n-- ) - { - if ( *p == ( unsigned char ) c ) - { - return ( void * ) p; - } - - ++p; - } - - return NULL; +#include +#include "unconst.h" +#include + +void* memchr(const void* s, int c, size_t n) +{ + int d0; + register void* __res; + if (!n) + return NULL; + __asm__ __volatile__( + "repne\n\t" + "scasb\n\t" + "je 1f\n\t" + "movl $1,%0\n" + "1:\tdecl %0" + : "=D"(__res), "=&c"(d0) + : "a"(c), "0"(s), "1"(n)); + return __res; } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/memcmp.c b/programs/develop/ktcc/trunk/libc.obj/source/string/memcmp.c index de156091b1..efd2aa4daf 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/memcmp.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/memcmp.c @@ -1,26 +1,15 @@ -/* memcmp( const void *, const void *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -int memcmp( const void * s1, const void * s2, size_t n ) -{ - const unsigned char * p1 = ( const unsigned char * ) s1; - const unsigned char * p2 = ( const unsigned char * ) s2; - - while ( n-- ) - { - if ( *p1 != *p2 ) - { - return *p1 - *p2; - } - - ++p1; - ++p2; - } - - return 0; -} +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include +#include + +int memcmp(const void* s1, const void* s2, size_t n) +{ + if (n != 0) { + const unsigned char *p1 = s1, *p2 = s2; + do { + if (*p1++ != *p2++) + return (*--p1 - *--p2); + } while (--n != 0); + } + return 0; +} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/memcpy.c b/programs/develop/ktcc/trunk/libc.obj/source/string/memcpy.c index 0d707df047..4bb0674d1e 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/memcpy.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/memcpy.c @@ -1,20 +1,19 @@ -/* memcpy( void *, const void *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -void * memcpy( void * s1, const void * s2, size_t n ) -{ - char * dest = ( char * ) s1; - const char * src = ( const char * ) s2; - - while ( n-- ) - { - *dest++ = *src++; - } - - return s1; +#include + +void* memcpy(void* _dest, const void* _src, size_t _n) +{ + int d0, d1, d2; + __asm__ __volatile__( + "rep ; movsl\n\t" + "testb $2,%b4\n\t" + "je 1f\n\t" + "movsw\n" + "1:\ttestb $1,%b4\n\t" + "je 2f\n\t" + "movsb\n" + "2:" + : "=&c"(d0), "=&D"(d1), "=&S"(d2) + : "0"(_n / 4), "q"(_n), "1"((long)_dest), "2"((long)_src) + : "memory"); + return (_dest); } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/memmove.c b/programs/develop/ktcc/trunk/libc.obj/source/string/memmove.c deleted file mode 100644 index e4dc719288..0000000000 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/memmove.c +++ /dev/null @@ -1,33 +0,0 @@ -/* memmove( void *, const void *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -void * memmove( void * s1, const void * s2, size_t n ) -{ - char * dest = ( char * ) s1; - const char * src = ( const char * ) s2; - - if ( dest <= src ) - { - while ( n-- ) - { - *dest++ = *src++; - } - } - else - { - src += n; - dest += n; - - while ( n-- ) - { - *--dest = *--src; - } - } - - return s1; -} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/memmove.s b/programs/develop/ktcc/trunk/libc.obj/source/string/memmove.s new file mode 100755 index 0000000000..d9536628a5 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/memmove.s @@ -0,0 +1,34 @@ +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ + +.global memmove + +memmove: + pushl %ebp + movl %esp,%ebp + pushl %esi + pushl %edi + movl 8(%ebp),%edi + movl 12(%ebp),%esi + movl 16(%ebp),%ecx + jecxz memmove.L2 + cld + cmpl %esi,%edi + jb memmove.L3 + + std + addl %ecx,%esi + addl %ecx,%edi + decl %esi + decl %edi +memmove.L3: + rep + movsb + +memmove.L2: + cld + popl %edi + popl %esi + movl 8(%ebp),%eax + leave + ret + diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/memset.c b/programs/develop/ktcc/trunk/libc.obj/source/string/memset.c deleted file mode 100644 index 225f349d87..0000000000 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/memset.c +++ /dev/null @@ -1,20 +0,0 @@ -/* memset( void *, int, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -void * memset( void * s, int c, size_t n ) -{ - unsigned char * p = ( unsigned char * ) s; - - while ( n-- ) - { - *p++ = ( unsigned char ) c; - } - - return s; -} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/memset.s b/programs/develop/ktcc/trunk/libc.obj/source/string/memset.s new file mode 100755 index 0000000000..1a9f123323 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/memset.s @@ -0,0 +1,51 @@ +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ + .text + .align 4 + .global memset + +memset: + pushl %ebp + movl %esp,%ebp + pushl %edi + movl 8(%ebp),%edi + movl 12(%ebp),%eax + movl 16(%ebp),%ecx + cld + + # We will handle memsets of <= 15 bytes one byte at a time. + # This avoids some extra overhead for small memsets, and + # knowing we are setting > 15 bytes eliminates some annoying + # checks in the "long move" case. + cmpl $15,%ecx + jle memset.L3 + + # Otherwise, tile the byte value out into %eax. + # 0x41 -> 0x41414141, etc. + movb %al,%ah + movl %eax,%edx + sall $16,%eax + movw %dx,%ax + jmp memset.L2 + + # Handle any cruft necessary to get %edi long-aligned. +memset.L1: stosb + decl %ecx +memset.L2: testl $3,%edi + jnz memset.L1 + + # Now slam out all of the longs. + movl %ecx,%edx + shrl $2,%ecx + rep + stosl + + # Finally, handle any trailing cruft. We know the high three bytes + # of %ecx must be zero, so just put the "slop count" in the low byte. + movb %dl,%cl + andb $3,%cl +memset.L3: rep + stosb + popl %edi + movl 8(%ebp),%eax + leave + ret diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strcat.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strcat.c index bd90c10c33..18d450b6a4 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strcat.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strcat.c @@ -1,27 +1,18 @@ -/* strcat( char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -char * strcat( char * s1, const char * s2 ) -{ - char * rc = s1; - - if ( *s1 ) - { - while ( *++s1 ) - { - /* EMPTY */ - } - } - - while ( ( *s1++ = *s2++ ) ) - { - /* EMPTY */ - } - - return rc; +#include + +char* strcat(char* s, const char* append) +{ + int d0, d1, d2, d3; + __asm__ __volatile__( + "repne\n\t" + "scasb\n\t" + "decl %1\n" + "1:\tlodsb\n\t" + "stosb\n\t" + "testb %%al,%%al\n\t" + "jne 1b" + : "=&S"(d0), "=&D"(d1), "=&a"(d2), "=&c"(d3) + : "0"(append), "1"(s), "2"(0), "3"(0xffffffff) + : "memory"); + return s; } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strchr.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strchr.c index 98bc094a93..4d1092b738 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strchr.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strchr.c @@ -1,20 +1,21 @@ -/* strchr( const char *, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -char * strchr( const char * s, int c ) -{ - do - { - if ( *s == ( char ) c ) - { - return ( char * ) s; - } - } while ( *s++ ); - - return NULL; +#include "unconst.h" +#include + +char* strchr(const char* s, int c) +{ + int d0; + register char* __res; + __asm__ __volatile__( + "movb %%al,%%ah\n" + "1:\tlodsb\n\t" + "cmpb %%ah,%%al\n\t" + "je 2f\n\t" + "testb %%al,%%al\n\t" + "jne 1b\n\t" + "movl $1,%1\n" + "2:\tmovl %1,%0\n\t" + "decl %0" + : "=a"(__res), "=&S"(d0) + : "1"((unsigned)s), "0"(c)); + return __res; } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strcmp.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strcmp.c index 80cf412437..91a52cb6a4 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strcmp.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strcmp.c @@ -1,14 +1,21 @@ -/* strcmp( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -int strcmp(const char * s1, const char * s2) -{ - return __strcmp(s1, s2); -} \ No newline at end of file +#include + +int strcmp(const char* s1, const char* s2) +{ + int d0, d1; + register int __res; + __asm__ __volatile__( + "1:\tlodsb\n\t" + "scasb\n\t" + "jne 2f\n\t" + "testb %%al,%%al\n\t" + "jne 1b\n\t" + "xorl %%eax,%%eax\n\t" + "jmp 3f\n" + "2:\tsbbl %%eax,%%eax\n\t" + "orb $1,%%al\n" + "3:" + : "=a"(__res), "=&S"(d0), "=&D"(d1) + : "1"(s1), "2"(s2)); + return __res; +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strcoll.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strcoll.c index 1ea0837f01..8c88c32485 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strcoll.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strcoll.c @@ -1,13 +1,7 @@ -/* strcoll( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -int strcoll( const char * s1, const char * s2 ) -{ - /* FIXME: This should access _PDCLIB_lc_collate. */ - return strcmp( s1, s2 ); -} +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +int strcoll(const char* s1, const char* s2) +{ + return strcmp(s1, s2); +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strcpy.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strcpy.c index ce9176b85e..a336e3de71 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strcpy.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strcpy.c @@ -1,19 +1,16 @@ -/* strcpy( char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -char * strcpy( char * s1, const char * s2 ) -{ - char * rc = s1; - - while ( ( *s1++ = *s2++ ) ) - { - /* EMPTY */ - } - - return rc; -} \ No newline at end of file +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +char* strcpy(char* to, const char* from) +{ + int d0, d1, d2; + __asm__ __volatile__( + "1:\tlodsb\n\t" + "stosb\n\t" + "testb %%al,%%al\n\t" + "jne 1b" + : "=&S"(d0), "=&D"(d1), "=&a"(d2) + : "0"(from), "1"(to) + : "memory"); + return to; +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strcspn.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strcspn.c index 074d800560..0d14e5f1d3 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strcspn.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strcspn.c @@ -1,30 +1,17 @@ -/* strcspn( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -size_t strcspn( const char * s1, const char * s2 ) -{ - size_t len = 0; - const char * p; - - while ( s1[len] ) - { - p = s2; - - while ( *p ) - { - if ( s1[len] == *p++ ) - { - return len; - } - } - - ++len; - } - - return len; -} \ No newline at end of file +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +size_t strcspn(const char* s1, const char* s2) +{ + const char *p, *spanp; + char c, sc; + + for (p = s1;;) { + c = *p++; + spanp = s2; + do { + if ((sc = *spanp++) == c) + return p - 1 - s1; + } while (sc != 0); + } +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strdup.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strdup.c index 73e3ac9efc..4e1b41a752 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strdup.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strdup.c @@ -1,9 +1,9 @@ -#include #include +#include -char* strdup(const char *str) +char* strdup(const char* str) { - char *buf = malloc(strlen(str) + 1); + char* buf = malloc(strlen(str) + 1); buf[strlen(str)] = '\0'; strcpy(buf, str); return buf; diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strerror.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strerror.c index d4cbbe2937..b44cc325ae 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strerror.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strerror.c @@ -3,66 +3,34 @@ #include #include -int _errno; +int __errno; char* strerror(int err) { char *msg; switch(err){ case 0: msg = "No errors"; break; - case EPERM: msg = "Operation not permitted"; break; - case ENOENT: msg = "No such file or directory"; break; - case ESRCH: msg = "No such process"; break; - case EINTR: msg = "Interrupted system call"; break; - case EIO: msg = "Input/output error"; break; - case ENXIO: msg = "Device not configured"; break; - case E2BIG: msg = "Argument list too long"; break; - case ENOEXEC: msg = "Exec format error"; break; - case EBADF: msg = "Bad file descriptor"; break; - case ECHILD: msg = "No child processes"; break; - case EDEADLK: msg = "Resource deadlock avoided"; break; - case ENOMEM: msg = "Cannot allocate memory"; break; - case EACCES: msg = "Permission denied"; break; - case EFAULT: msg = "Bad address"; break; - case ENOTBLK: msg = "Block device required"; break; - case EBUSY: msg = "Device / Resource busy"; break; - case EEXIST: msg = "File exists"; break; - case EXDEV: msg = "Cross-device link"; break; - case ENODEV: msg = "Operation not supported by device"; break; - case ENOTDIR: msg = "Not a directory"; break; - case EISDIR: msg = "Is a directory"; break; - case EINVAL: msg = "Invalid argument"; break; - case ENFILE: msg = "Too many open files in system"; break; - case EMFILE: msg = "Too many open files"; break; - case ENOTTY: msg = "Inappropriate ioctl for device"; break; - case ETXTBSY: msg = "Text file busy"; break; - case EFBIG: msg = "File too large"; break; - case ENOSPC: msg = "No space left on device"; break; - case ESPIPE: msg = "Illegal seek"; break; - case EROFS: msg = "Read-only file system"; break; - case EMLINK: msg = "Too many links"; break; - case EPIPE: msg = "Broken pipe"; break; - // math software + case ENOTSUP: msg = "Function is not supported"; break; + case EUNKNFS: msg = "Unknown file system"; break; + case ENOTFOUND: msg = "File not found"; break; + case EEOF: msg = "End of file"; break; + case EFAULT: msg = "Bad address"; break; + case EDQUOT: msg = "Disc quota exceeded"; break; + case EFS: msg = "File system error"; break; + case EACCES: msg = "Permission denied"; break; + case EDEV: msg = "Device error"; break; + case ENOMEMFS: msg = "File system requires more memory"; break; + + case ENOMEM: msg = "Not enough memory"; break; + case ENOEXEC: msg = "Exec format error"; break; + case EPROCLIM: msg = "Too many processes"; break; + case EINVAL: msg = "Invalid argument"; break; + case EDOM: msg = "Numerical argument out of domain"; break; case ERANGE: msg = "Result too large"; break; - - // should be rearranged - case EHOSTDOWN: msg = "Host is down"; break; - case EHOSTUNREACH: msg = "No route to host"; break; - case ENOTEMPTY: msg = "Directory not empty"; break; - - // quotas & mush - case EPROCLIM: msg = "Too many processes"; break; - case EUSERS: msg = "Too many users"; break; - case EDQUOT: msg = "Disc quota exceeded"; break; - - // Intelligent device errors - case EPWROFF: msg = "Device power is off"; break; - case EDEVERR: msg = "Device error, e.g. paper out"; break; - case EOVERFLOW: msg = "Value too large to be stored in data type"; break; - - // Socket errors + case EILSEQ: msg = "Illegal byte sequence"; break; + case ENOBUFS: msg = "Broken buffer"; break; case EINPROGRESS: msg = "Operation now in progress"; break; case EOPNOTSUPP: msg = "Operation not supported on transport endpoint"; break; diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strlen.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strlen.c index fc3a1b6baa..2ca92b8d21 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strlen.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strlen.c @@ -1,19 +1,16 @@ -/* strlen( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -size_t strlen( const char * s ) -{ - size_t rc = 0; - - while ( s[rc] ) - { - ++rc; - } - - return rc; -} \ No newline at end of file +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ +#include + +size_t strlen(const char* str) +{ + int d0; + register int __res; + __asm__ __volatile__( + "repne\n\t" + "scasb\n\t" + "notl %0\n\t" + "decl %0" + : "=c"(__res), "=&D"(d0) + : "1"(str), "a"(0), "0"(0xffffffff)); + return __res; +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strncat.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strncat.c index 5ec655e561..b050f8c3b7 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strncat.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strncat.c @@ -1,29 +1,23 @@ -/* strncat( char *, const char *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -char * strncat( char * s1, const char * s2, size_t n ) -{ - char * rc = s1; - - while ( *s1 ) - { - ++s1; - } - - while ( n && ( *s1++ = *s2++ ) ) - { - --n; - } - - if ( n == 0 ) - { - *s1 = '\0'; - } - - return rc; +#include + +char* strncat(char* dst, const char* src, size_t n) +{ + int d0, d1, d2, d3; + __asm__ __volatile__( + "repne\n\t" + "scasb\n\t" + "decl %1\n\t" + "movl %8,%3\n" + "1:\tdecl %3\n\t" + "js 2f\n\t" + "lodsb\n\t" + "stosb\n\t" + "testb %%al,%%al\n\t" + "jne 1b\n" + "2:\txorl %2,%2\n\t" + "stosb" + : "=&S"(d0), "=&D"(d1), "=&a"(d2), "=&c"(d3) + : "0"(src), "1"(dst), "2"(0), "3"(0xffffffff), "g"(n) + : "memory"); + return dst; } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strncmp.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strncmp.c index 72b54b4184..6bf1199c88 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strncmp.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strncmp.c @@ -1,26 +1,24 @@ -/* strncmp( const char *, const char *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -int strncmp( const char * s1, const char * s2, size_t n ) -{ - while ( n && *s1 && ( *s1 == *s2 ) ) - { - ++s1; - ++s2; - --n; - } - - if ( n == 0 ) - { - return 0; - } - else - { - return ( *( unsigned char * )s1 - * ( unsigned char * )s2 ); - } -} \ No newline at end of file +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +int strncmp(const char* s1, const char* s2, size_t n) +{ + register int __res; + int d0, d1, d2; + __asm__ __volatile__( + "1:\tdecl %3\n\t" + "js 2f\n\t" + "lodsb\n\t" + "scasb\n\t" + "jne 3f\n\t" + "testb %%al,%%al\n\t" + "jne 1b\n" + "2:\txorl %%eax,%%eax\n\t" + "jmp 4f\n" + "3:\tsbbl %%eax,%%eax\n\t" + "orb $1,%%al\n" + "4:" + : "=a"(__res), "=&S"(d0), "=&D"(d1), "=&c"(d2) + : "1"(s1), "2"(s2), "3"(n)); + return __res; +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strncpy.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strncpy.c index 91e05621cd..f52c57e12b 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strncpy.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strncpy.c @@ -1,29 +1,21 @@ -/* strncpy( char *, const char *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -char * strncpy( char * s1, const char * s2, size_t n ) -{ - char * rc = s1; - - while ( n && ( *s1++ = *s2++ ) ) - { - /* Cannot do "n--" in the conditional as size_t is unsigned and we have - to check it again for >0 in the next loop below, so we must not risk - underflow. - */ - --n; - } - - /* Checking against 1 as we missed the last --n in the loop above. */ - while ( n-- > 1 ) - { - *s1++ = '\0'; - } - - return rc; +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +char* strncpy(char* dst, const char* src, size_t n) +{ + int d0, d1, d2, d3; + __asm__ __volatile__( + "1:\tdecl %2\n\t" + "js 2f\n\t" + "lodsb\n\t" + "stosb\n\t" + "testb %%al,%%al\n\t" + "jne 1b\n\t" + "rep\n\t" + "stosb\n" + "2:" + : "=&S"(d0), "=&D"(d1), "=&c"(d2), "=&a"(d3) + : "0"(src), "1"(dst), "2"(n) + : "memory"); + return dst; } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strpbrk.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strpbrk.c index c58f87433e..520626edb1 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strpbrk.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strpbrk.c @@ -1,30 +1,16 @@ -/* strpbrk( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -char * strpbrk( const char * s1, const char * s2 ) -{ - const char * p1 = s1; - const char * p2; - - while ( *p1 ) - { - p2 = s2; - - while ( *p2 ) - { - if ( *p1 == *p2++ ) - { - return ( char * ) p1; - } - } - - ++p1; - } - - return NULL; -} \ No newline at end of file +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include "unconst.h" +#include + +char* strpbrk(const char* s1, const char* s2) +{ + const char* scanp; + int c, sc; + + while ((c = *s1++) != 0) { + for (scanp = s2; (sc = *scanp++) != 0;) + if (sc == c) + return unconst(s1 - 1, char*); + } + return 0; +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strrchr.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strrchr.c index 4a36793424..57df1b6dc9 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strrchr.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strrchr.c @@ -1,27 +1,18 @@ -/* strrchr( const char *, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -char * strrchr( const char * s, int c ) -{ - size_t i = 0; - - while ( s[i++] ) - { - /* EMPTY */ - } - - do - { - if ( s[--i] == ( char ) c ) - { - return ( char * ) s + i; - } - } while ( i ); - - return NULL; -} \ No newline at end of file +/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include "unconst.h" +#include + +char* strrchr(const char* s, int c) +{ + char cc = c; + const char* sp = (char*)0; + while (*s) { + if (*s == cc) + sp = s; + s++; + } + if (cc == 0) + sp = s; + return unconst(sp, char*); +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strspn.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strspn.c index 96ce6d67b8..c10702d4bc 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strspn.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strspn.c @@ -1,37 +1,15 @@ -/* strspn( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -size_t strspn( const char * s1, const char * s2 ) -{ - size_t len = 0; - const char * p; - - while ( s1[ len ] ) - { - p = s2; - - while ( *p ) - { - if ( s1[len] == *p ) - { - break; - } - - ++p; - } - - if ( ! *p ) - { - return len; - } - - ++len; - } - - return len; -} \ No newline at end of file +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +size_t strspn(const char* s1, const char* s2) +{ + const char *p = s1, *spanp; + char c, sc; + +cont: + c = *p++; + for (spanp = s2; (sc = *spanp++) != 0;) + if (sc == c) + goto cont; + return (p - 1 - s1); +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strstr.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strstr.c index d1f28b1ff9..628e3cf5ce 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strstr.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strstr.c @@ -1,34 +1,21 @@ -/* strstr( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -char * strstr( const char * s1, const char * s2 ) -{ - const char * p1 = s1; - const char * p2; - - while ( *s1 ) - { - p2 = s2; - - while ( *p2 && ( *p1 == *p2 ) ) - { - ++p1; - ++p2; - } - - if ( ! *p2 ) - { - return ( char * ) s1; - } - - ++s1; - p1 = s1; - } - - return NULL; -} \ No newline at end of file +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include "unconst.h" +#include + +char* strstr(const char* s, const char* find) +{ + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return 0; + } while (sc != c); + } while (strncmp(s, find, len) != 0); + s--; + } + return unconst(s, char*); +} 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 1f756940e9..84c39df9a8 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c @@ -1,30 +1,49 @@ -/* strtok( char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -char* strtok(char* s, const char* delim) -{ - static char* savep; - char* res; - - if(s) - savep = NULL; - else - s = savep; - - if (*s == '\0') - return NULL; - s += strspn(s, delim); - if (*s == '\0') - return NULL; - res = s; - s += strcspn(s, delim); - savep = s + 1; - *s = '\0'; - return res; -} - +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +char* strtok(char* s, const char* delim) +{ + const char* spanp; + int c, sc; + char* tok; + static char* last; + + if (s == NULL && (s = last) == 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 */ + 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 = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + last = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/strxfrm.c b/programs/develop/ktcc/trunk/libc.obj/source/string/strxfrm.c index f24afd534d..3636f4144a 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/string/strxfrm.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/strxfrm.c @@ -1,26 +1,22 @@ -/* strxfrm( char *, const char *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -size_t strxfrm( char * s1, const char * s2, size_t n ) -{ - size_t len = strlen( s2 ); - - if ( len < n ) - { - /* Cannot use strncpy() here as the filling of s1 with '\0' is not part - of the spec. - */ - /* FIXME: This should access _PDCLIB_lc_collate. */ - while ( n-- && ( *s1++ = ( unsigned char )*s2++ ) ) - { - /* EMPTY */ - } - } - - return len; +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +size_t strxfrm(char* dst, const char* src, size_t n) +{ + size_t r = 0; + int c; + + if (n != 0) { + while ((c = *src++) != 0) { + r++; + if (--n == 0) { + while (*src++ != 0) + r++; + break; + } + *dst++ = c; + } + *dst = 0; + } + return r; } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/string/unconst.h b/programs/develop/ktcc/trunk/libc.obj/source/string/unconst.h new file mode 100755 index 0000000000..752f3c4cd9 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/source/string/unconst.h @@ -0,0 +1,8 @@ +#ifndef _UNCONST_H_ +#define _UNCONST_H_ + +#ifndef unconst +#define unconst(__v, __t) __extension__ ({union { const __t __cp; __t __p; } __q; __q.__cp = __v; __q.__p;}) +#endif + +#endif // _UNCONST_H_ diff --git a/programs/develop/ktcc/trunk/libc.obj/source/sys/opendir.c b/programs/develop/ktcc/trunk/libc.obj/source/sys/opendir.c index 7a44e40198..1a2f653cf4 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/sys/opendir.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/sys/opendir.c @@ -6,7 +6,7 @@ #include #include -#define CHECK_DIR_ERR() if(_ksys_work_files(&inf)){ \ +#define CHECK_DIR_ERR() if(_ksys70(&inf).status){ \ free((void*)inf.p16); \ errno = ENOTDIR; \ return NULL; \ diff --git a/programs/develop/ktcc/trunk/libc.obj/source/time/asctime.c b/programs/develop/ktcc/trunk/libc.obj/source/time/asctime.c index 099c9a3797..3996ae511a 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/time/asctime.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/time/asctime.c @@ -1,34 +1,34 @@ #include "stddef.h" #include +#include #include #include -#include -const char *wday_str[7]={"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; -const char *mon_str[12]={"Jan", "Feb", "Mar", "Ap", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; +const char* wday_str[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; +const char* mon_str[12] = { "Jan", "Feb", "Mar", "Ap", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; #pragma GCC push_options #pragma GCC optimize("O0") #define TIME_STR_MAX 27 -char *asctime(const struct tm *tm){ - if(!tm){ - errno = EINVAL; +char* asctime(const struct tm* tm) +{ + if (!tm) { + __errno = EINVAL; return NULL; } - if(tm->tm_wday>6 || tm->tm_wday<0 || tm->tm_mon<0 || tm->tm_mon>11){ + if (tm->tm_wday > 6 || tm->tm_wday < 0 || tm->tm_mon < 0 || tm->tm_mon > 11) { errno = EINVAL; return NULL; } static char time_str[TIME_STR_MAX]; - snprintf(time_str, TIME_STR_MAX-1, "%.3s %.3s%3d %02d:%02d:%02d %d\n", + snprintf(time_str, TIME_STR_MAX - 1, "%.3s %.3s%3d %02d:%02d:%02d %d\n", wday_str[tm->tm_wday], mon_str[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, - 1900 + tm->tm_year - ); + 1900 + tm->tm_year); return time_str; } #pragma GCC pop_options diff --git a/programs/develop/ktcc/trunk/libc.obj/source/time/difftime.c b/programs/develop/ktcc/trunk/libc.obj/source/time/difftime.c index 44c7323c28..83f167ca94 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/time/difftime.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/time/difftime.c @@ -1,6 +1,6 @@ #include -double difftime (time_t end, time_t beginning) +double difftime(time_t end, time_t beginning) { - return end - beginning; -} + return end - beginning; +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/time/localtime.c b/programs/develop/ktcc/trunk/libc.obj/source/time/localtime.c index dc1a26b5b6..45505b8a4b 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/time/localtime.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/time/localtime.c @@ -1,108 +1,112 @@ -#include -#include #include #include #include +#include +#include -#define LEAPOCH (946684800LL + 86400*(31+29)) +#define LEAPOCH (946684800LL + 86400 * (31 + 29)) -#define DAYS_PER_400Y (365*400 + 97) -#define DAYS_PER_100Y (365*100 + 24) -#define DAYS_PER_4Y (365*4 + 1) +#define DAYS_PER_400Y (365 * 400 + 97) +#define DAYS_PER_100Y (365 * 100 + 24) +#define DAYS_PER_4Y (365 * 4 + 1) -static int __secs_to_tm(long long t, struct tm *tm) +static int __secs_to_tm(long long t, struct tm* tm) { - long long days, secs, years; - int remdays, remsecs, remyears; - int qc_cycles, c_cycles, q_cycles; - int months; - int wday, yday, leap; - static const char days_in_month[] = {31,30,31,30,31,31,30,31,30,31,31,29}; + long long days, secs, years; + int remdays, remsecs, remyears; + int qc_cycles, c_cycles, q_cycles; + int months; + int wday, yday, leap; + static const char days_in_month[] = { 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29 }; - // Reject time_t values whose year would overflow int - if (t < INT_MIN * 31622400LL || t > INT_MAX * 31622400LL) - return -1; - - secs = t - LEAPOCH; - days = secs / 86400; - remsecs = secs % 86400; - - if (remsecs < 0) { - remsecs += 86400; - days--; - } + // Reject time_t values whose year would overflow int + if (t < INT_MIN * 31622400LL || t > INT_MAX * 31622400LL) + return -1; - wday = (3+days)%7; - if (wday < 0) wday += 7; + secs = t - LEAPOCH; + days = secs / 86400; + remsecs = secs % 86400; - qc_cycles = days / DAYS_PER_400Y; - remdays = days % DAYS_PER_400Y; - if (remdays < 0) { - remdays += DAYS_PER_400Y; - qc_cycles--; - } + if (remsecs < 0) { + remsecs += 86400; + days--; + } - c_cycles = remdays / DAYS_PER_100Y; - if (c_cycles == 4) c_cycles--; - remdays -= c_cycles * DAYS_PER_100Y; + wday = (3 + days) % 7; + if (wday < 0) + wday += 7; - q_cycles = remdays / DAYS_PER_4Y; - if (q_cycles == 25) q_cycles--; - remdays -= q_cycles * DAYS_PER_4Y; + qc_cycles = days / DAYS_PER_400Y; + remdays = days % DAYS_PER_400Y; + if (remdays < 0) { + remdays += DAYS_PER_400Y; + qc_cycles--; + } - remyears = remdays / 365; - if (remyears == 4) remyears--; - remdays -= remyears * 365; + c_cycles = remdays / DAYS_PER_100Y; + if (c_cycles == 4) + c_cycles--; + remdays -= c_cycles * DAYS_PER_100Y; - leap = !remyears && (q_cycles || !c_cycles); - yday = remdays + 31 + 28 + leap; - if (yday >= 365+leap) yday -= 365+leap; + q_cycles = remdays / DAYS_PER_4Y; + if (q_cycles == 25) + q_cycles--; + remdays -= q_cycles * DAYS_PER_4Y; - years = remyears + 4*q_cycles + 100*c_cycles + 400LL*qc_cycles; + remyears = remdays / 365; + if (remyears == 4) + remyears--; + remdays -= remyears * 365; - for (months=0; days_in_month[months] <= remdays; months++) - remdays -= days_in_month[months]; + leap = !remyears && (q_cycles || !c_cycles); + yday = remdays + 31 + 28 + leap; + if (yday >= 365 + leap) + yday -= 365 + leap; - if (months >= 10) { - months -= 12; - years++; - } + years = remyears + 4 * q_cycles + 100 * c_cycles + 400LL * qc_cycles; - if (years+100 > INT_MAX || years+100 < INT_MIN) - return -1; + for (months = 0; days_in_month[months] <= remdays; months++) + remdays -= days_in_month[months]; - tm->tm_year = years + 100; - tm->tm_mon = months + 2; - tm->tm_mday = remdays + 1; - tm->tm_wday = wday; - tm->tm_yday = yday; + if (months >= 10) { + months -= 12; + years++; + } - tm->tm_hour = remsecs / 3600; - tm->tm_min = remsecs / 60 % 60; - tm->tm_sec = remsecs % 60; + if (years + 100 > INT_MAX || years + 100 < INT_MIN) + return -1; - return 0; + tm->tm_year = years + 100; + tm->tm_mon = months + 2; + tm->tm_mday = remdays + 1; + tm->tm_wday = wday; + tm->tm_yday = yday; + + tm->tm_hour = remsecs / 3600; + tm->tm_min = remsecs / 60 % 60; + tm->tm_sec = remsecs % 60; + + return 0; } -struct tm *__localtime_r(const time_t *restrict t, struct tm *restrict tm) +struct tm* __localtime_r(const time_t* restrict t, struct tm* restrict tm) { - // Reject time_t values whose year would overflow int because - // __secs_to_zone cannot safely handle them. - if (*t < INT_MIN * 31622400LL || *t > INT_MAX * 31622400LL) { - errno = EOVERFLOW; - return NULL; - } - //__secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone); - if (__secs_to_tm((long long)*t,tm) < 0) { - errno = EOVERFLOW; - return NULL; - } - return tm; + // Reject time_t values whose year would overflow int because + // __secs_to_zone cannot safely handle them. + if (*t < INT_MIN * 31622400LL || *t > INT_MAX * 31622400LL) { + errno = EOVERFLOW; + return NULL; + } + //__secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone); + if (__secs_to_tm((long long)*t, tm) < 0) { + errno = EOVERFLOW; + return NULL; + } + return tm; } -struct tm * localtime (const time_t * timer) +struct tm* localtime(const time_t* timer) { - static struct tm tm; - return __localtime_r(timer, &tm); -} - + static struct tm tm; + return __localtime_r(timer, &tm); +} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/time/mktime.c b/programs/develop/ktcc/trunk/libc.obj/source/time/mktime.c index e5cbbae04f..26e4b224e8 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/time/mktime.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/time/mktime.c @@ -1,23 +1,23 @@ #include -time_t mktime (struct tm * timeptr) +time_t mktime(struct tm* timeptr) { -// int utcdiff = -3; - const int mon_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + // int utcdiff = -3; + const int mon_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; unsigned long int tyears, tdays, leaps, utc_hrs; int i; - - tyears = timeptr->tm_year - 70 ;// tm->tm_year is from 1900. + + tyears = timeptr->tm_year - 70; // tm->tm_year is from 1900. leaps = (tyears + 2) / 4; // no of next two lines until year 2100. i = (timeptr->tm_year - 100) / 100; - leaps -= ( (i/4)*3 + i%4 ); + leaps -= ((i / 4) * 3 + i % 4); tdays = 0; - for (i=0; i < timeptr->tm_mon; i++) tdays += mon_days[i]; - - tdays += timeptr->tm_mday-1; // days of month passed. + for (i = 0; i < timeptr->tm_mon; i++) + tdays += mon_days[i]; + + tdays += timeptr->tm_mday - 1; // days of month passed. tdays = tdays + (tyears * 365) + leaps; -// utc_hrs = timeptr->tm_hour + utcdiff; // for your time zone. + // utc_hrs = timeptr->tm_hour + utcdiff; // for your time zone. return (tdays * 86400) + (timeptr->tm_hour * 3600) + (timeptr->tm_min * 60) + timeptr->tm_sec; -} - +} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/source/time/time.c b/programs/develop/ktcc/trunk/libc.obj/source/time/time.c index b53916a696..ae949c2517 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/time/time.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/time/time.c @@ -1,32 +1,33 @@ -#include #include +#include -time_t time(time_t *timer){ +time_t time(time_t* timer) +{ static struct tm __buffertime; int kos_date, kos_time; kos_date = _ksys_get_date().val; kos_time = _ksys_get_time().val; - + int bcd_day = (kos_date >> 16); int bcd_mon = ((kos_date & 0xFF00) >> 8); int bcd_year = (kos_date & 0xFF); - __buffertime.tm_mday = ((bcd_day & 0xF0)>>4)*10 + (bcd_day & 0x0F); - __buffertime.tm_mon = ((bcd_mon & 0xF0)>>4)*10 + (bcd_mon & 0x0F) - 1; - __buffertime.tm_year = ((bcd_year & 0xF0)>>4)*10 + (bcd_year & 0x0F) + 100; - + __buffertime.tm_mday = ((bcd_day & 0xF0) >> 4) * 10 + (bcd_day & 0x0F); + __buffertime.tm_mon = ((bcd_mon & 0xF0) >> 4) * 10 + (bcd_mon & 0x0F) - 1; + __buffertime.tm_year = ((bcd_year & 0xF0) >> 4) * 10 + (bcd_year & 0x0F) + 100; + __buffertime.tm_wday = __buffertime.tm_yday = __buffertime.tm_isdst = -1; /* temporary */ - + int bcd_sec = (kos_time >> 16); int bcd_min = ((kos_time & 0xFF00) >> 8); int bcd_hour = (kos_time & 0xFF); - - __buffertime.tm_sec = ((bcd_sec & 0xF0)>>4)*10 + (bcd_sec & 0x0F); - __buffertime.tm_min = ((bcd_min & 0xF0)>>4)*10 + (bcd_min & 0x0F); - __buffertime.tm_hour = ((bcd_hour & 0xF0)>>4)*10 + (bcd_hour & 0x0F); - + + __buffertime.tm_sec = ((bcd_sec & 0xF0) >> 4) * 10 + (bcd_sec & 0x0F); + __buffertime.tm_min = ((bcd_min & 0xF0) >> 4) * 10 + (bcd_min & 0x0F); + __buffertime.tm_hour = ((bcd_hour & 0xF0) >> 4) * 10 + (bcd_hour & 0x0F); + time_t ret = mktime(&__buffertime); - if(timer){ - *timer=ret; + if (timer) { + *timer = ret; } return ret; }