From 9257d2c34c2a9cb711cc1ab802c659e46a73c46b Mon Sep 17 00:00:00 2001 From: turbocat Date: Fri, 12 Nov 2021 22:45:22 +0000 Subject: [PATCH] libc.obj: - Added basename() and dirname() - libc_test all tabs -> spaces git-svn-id: svn://kolibrios.org@9262 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../develop/ktcc/trunk/bin/lib/libc.obj.a | Bin 83244 -> 84304 bytes .../ktcc/trunk/libc.obj/include/libgen.h | 7 + .../ktcc/trunk/libc.obj/samples/libc_test.c | 130 +++++++++--------- .../develop/ktcc/trunk/libc.obj/source/libc.c | 3 + .../trunk/libc.obj/source/misc/basename.c | 13 ++ .../ktcc/trunk/libc.obj/source/misc/dirname.c | 14 ++ .../ktcc/trunk/libc.obj/source/symbols.txt | 3 + 7 files changed, 107 insertions(+), 63 deletions(-) create mode 100644 programs/develop/ktcc/trunk/libc.obj/include/libgen.h create mode 100644 programs/develop/ktcc/trunk/libc.obj/source/misc/basename.c create mode 100644 programs/develop/ktcc/trunk/libc.obj/source/misc/dirname.c diff --git a/programs/develop/ktcc/trunk/bin/lib/libc.obj.a b/programs/develop/ktcc/trunk/bin/lib/libc.obj.a index 5c7878caed882b408979b7cc72a2c325324ba866..d0cb67e74c6257da2536d1cee3d46d677d48cd4e 100644 GIT binary patch delta 777 zcmX}m0Z5Z^5XRx(ndT6&p+km=3|VD4o7PG*MMcFTLn9-D5o$A5EgL2^LYmbG6N%x5 zNJvRUNN89|Nk~{oSV*jpkPwlOkdTm&kdWvQ>w|}T|L}454s^ssx?+O){#=J;?W>Ce z?t#GzaUO`*na~18mFNRgD6IqSBSM7q+SlwWAMgYG*%W55cZsaE!p- zG02;Q{Anmyg(5S4N^DSi0Lp8i!U+dma7d3HZiA`-9MOYEb-}R+9G{01E8sN3$qcBo zLW2Wb1#r3;-0G}mk80BFRn2A4qWdpZg0C8`=$+PDxT@Nmez;x-0T_OJ2HgSZX@@(V&>MuisxJ)p)dTfV_4mLdBMg|}u^EP}@YDjsI-hId5gWYB zhEWH+%7Zb#HhrVUwdvb3n9!#0)uiSRIwR^+B}}Q$)i7NHU(`%3%sOGt4PQMl?}cwI zu;7F5YEeu7(9%l*_!)%dF#J+0z3{saRtMnE5aMSTi5fwoN0E(Vh+!Own?T|xk%S0h zoI(<35YrrzJdcAMyKdbzXU?3NIdf*snX{eQYOR}XcB!c_|X{Pn)iuQXG;FkPGMkM_Fk|DV4O zcmO6Z)Qy8#XT1+Bs=*J|05qzmFf>QN7K0XLSFNfo4(-aJIuhViok?(|pgRpc890!I zz9r~i0rw^hLX=@EjJV*48;*M5_$Zw4!O0+;3c+bTct#hT&B3`MoG-(L3S6{+-wc;* z5NLzT4hX6%nnUWU<_UGp36r}2dJlyA;D+9b48fF&d7^Oh7{o{6_827e=hNzr7w-BX z>4%vB%mv|I2vQSpe-hGRc&IWFc&z5t6P1m@(+WJR!gFBJ3@=Qur1O;)&ROA26D-@{ ztsPdP+Vs83Ytw=gR<-E|Rn+`ZXGwkPfi?BH57yoAMQsehR}YlO;M+KCdf~edw*2rz zZENYDT6!l0zrwH^f#0eUhd&9Z&cWXl5+#k)WDvtVvNwyE7Ld9{#Jq&m=Mc*>(vU~2 zt4L!JX(}PjYlv+fY1u&RWu$czY1=~Dw-Lt<(y@y;Rc8fpsqQM$3v$qa95Nw?&B%ZS m8MI=QVLLM7c$u$xXV^nm*X$$X{@F$2zFP(3>w;0H2L1uhMwX%g diff --git a/programs/develop/ktcc/trunk/libc.obj/include/libgen.h b/programs/develop/ktcc/trunk/libc.obj/include/libgen.h new file mode 100644 index 0000000000..8fbee0d939 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/include/libgen.h @@ -0,0 +1,7 @@ +#ifndef _LIBGEN_H_ +#define _LIBGEN_H_ + +extern char* _FUNC(dirname)(char *); +extern char* _FUNC(basename)(char *); + +#endif diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c b/programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c index f961a0a23e..f69b12a885 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c @@ -1,84 +1,88 @@ +#include #include #include #include #include +#include int comp(void *a, void *b) { - return *(int*)a - *(int*)b; + return *(int*)a - *(int*)b; } int main(){ - puts("Start testing."); - assert(NULL == ((void*)0)); - assert(RAND_MAX == 65535); - assert(min(3, 10) == 3); - assert(max(3, 10) == 10); - assert(atof("12.4") == 12.4); - assert(atoi("-123") == -123); - assert(atol("-2146483647") == -2146483647L); - assert(atoll("-9223372036854775806") == -9223372036854775806LL); - assert(!strcmp("123", "123")); + puts("Start testing."); + assert(NULL == ((void*)0)); + assert(RAND_MAX == 65535); + assert(min(3, 10) == 3); + assert(max(3, 10) == 10); + assert(atof("12.4") == 12.4); + assert(atoi("-123") == -123); + assert(atol("-2146483647") == -2146483647L); + assert(atoll("-9223372036854775806") == -9223372036854775806LL); + assert(!strcmp("123", "123")); - char st1[32]; - itoa(-2341, st1); - assert(!strcmp(st1, "-2341")); + char st1[32]; + itoa(-2341, st1); + assert(!strcmp(st1, "-2341")); - assert(strlen("12345") == 5); - assert(abs(4) == 4); - assert(abs(-4) == 4); - assert(labs(1000000000) == 1000000000); - assert(labs(-1000000000) == 1000000000); - assert(llabs(100000000000) == 100000000000); - assert(llabs(-100000000000) == 100000000000); + assert(strlen("12345") == 5); + assert(abs(4) == 4); + assert(abs(-4) == 4); + assert(labs(1000000000) == 1000000000); + assert(labs(-1000000000) == 1000000000); + assert(llabs(100000000000) == 100000000000); + assert(llabs(-100000000000) == 100000000000); - div_t output1 = div(27, 4); - assert(output1.quot == 6); - assert(output1.rem == 3); + div_t output1 = div(27, 4); + assert(output1.quot == 6); + assert(output1.rem == 3); - ldiv_t output2 = ldiv(27, 4); - assert(output2.quot == 6); - assert(output2.rem == 3); + ldiv_t output2 = ldiv(27, 4); + assert(output2.quot == 6); + assert(output2.rem == 3); - lldiv_t output3 = lldiv(27, 4); - assert(output3.quot == 6); - assert(output3.rem == 3); + lldiv_t output3 = lldiv(27, 4); + assert(output3.quot == 6); + assert(output3.rem == 3); - char *st2 = malloc(sizeof(char)*2); - assert(st2 != NULL); - st2[0] = 'H'; - st2[1] = 'i'; - st2 = realloc(st2, sizeof(char)*3); - st2[2] = '!'; - assert(!strcmp(st2, "Hi!")); - free(st2); + char *st2 = malloc(sizeof(char)*2); + assert(st2 != NULL); + st2[0] = 'H'; + st2[1] = 'i'; + st2 = realloc(st2, sizeof(char)*3); + st2[2] = '!'; + assert(!strcmp(st2, "Hi!")); + free(st2); - st2 = calloc(2, sizeof(char)); - assert(st2 != NULL); - st2[0] = 'H'; - st2[1] = 'i'; - assert(!strcmp(st2, "Hi")); - free(st2); + st2 = calloc(2, sizeof(char)); + assert(st2 != NULL); + st2[0] = 'H'; + st2[1] = 'i'; + assert(!strcmp(st2, "Hi")); + free(st2); - char *start = "100.00 Rub"; - char *end; - assert(strtol(start, &end, 10) == 100L); - assert(!strcmp(end, ".00 Rub")); + char *start = "100.00 Rub"; + char *end; + assert(strtol(start, &end, 10) == 100L); + assert(!strcmp(end, ".00 Rub")); - end = NULL; - assert(strtod(start, &end) == 100.0); - assert(!strcmp(end, " Rub")); + end = NULL; + assert(strtod(start, &end) == 100.0); + assert(!strcmp(end, " Rub")); - // rand и srand проверены вручную :3 + char *st3 = "21.3e3Hello World!"; + assert(atof(st3) == 21300.0); - char *st3 = "21.3e3Hello World!"; - assert(atof(st3) == 21300.0); + int nums[10] = {5, 3, 9, 1, 8, 4, 2, 0, 7, 6}; + qsort(nums, 10, sizeof(int), (int(*) (const void *, const void *))comp); + for (int i = 0; i < 10; i++) { + assert(nums[i] == i); + } + + time_t libc_time = time(NULL); + struct tm *libc_tm = localtime(&libc_time); + printf(asctime(libc_tm)); - int nums[10] = {5, 3, 9, 1, 8, 4, 2, 0, 7, 6}; - qsort(nums, 10, sizeof(int), (int(*) (const void *, const void *))comp); - for (int i = 0; i < 10; i++) { - assert(nums[i] == i); - } - - puts("End testing."); - exit(0); -} \ No newline at end of file + puts("End testing."); + exit(0); +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/libc.c b/programs/develop/ktcc/trunk/libc.obj/source/libc.c index b1799af8fc..80e010e259 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/libc.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/libc.c @@ -116,6 +116,9 @@ #include "time/time.c" #include "time/asctime.c" +#include "misc/basename.c" +#include "misc/dirname.c" + __asm__( ".include \"math/acos.s\"\n\t" ".include \"math/asin.s\"\n\t" diff --git a/programs/develop/ktcc/trunk/libc.obj/source/misc/basename.c b/programs/develop/ktcc/trunk/libc.obj/source/misc/basename.c new file mode 100644 index 0000000000..99b37d7b50 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/source/misc/basename.c @@ -0,0 +1,13 @@ +#include +#include + +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; +} + diff --git a/programs/develop/ktcc/trunk/libc.obj/source/misc/dirname.c b/programs/develop/ktcc/trunk/libc.obj/source/misc/dirname.c new file mode 100644 index 0000000000..1dc6c08241 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/source/misc/dirname.c @@ -0,0 +1,14 @@ +#include +#include + +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; + return s; +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt b/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt index 8245b893dc..23da64f3a5 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt +++ b/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt @@ -172,3 +172,6 @@ time localtime asctime difftime +!____MISC____ +basename +dirname