From 5451715e39f7baab40a1052e74865420357221a3 Mon Sep 17 00:00:00 2001 From: superturbocat2001 Date: Tue, 1 Dec 2020 16:19:41 +0000 Subject: [PATCH] - Added "lsdir" function to libck ktcc. - Added "fs" folder to build.bat in libck for tcc. - Updated libck and dir_example git-svn-id: svn://kolibrios.org@8289 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/ktcc/trunk/bin/lib/libck.a | Bin 131106 -> 131644 bytes programs/develop/ktcc/trunk/libc/build.bat | 4 +- programs/develop/ktcc/trunk/libc/fs/dir.c | 44 +++++++++++++++++- .../develop/ktcc/trunk/libc/include/dir.h | 20 +++++++- .../develop/ktcc/trunk/samples/dir_example.c | 34 +++++++++++--- 5 files changed, 90 insertions(+), 12 deletions(-) diff --git a/programs/develop/ktcc/trunk/bin/lib/libck.a b/programs/develop/ktcc/trunk/bin/lib/libck.a index f41bc4736d63afea13eeed0270f30c42effa7ede..b06062aad8bff8a610dccd942fcff620021c0a58 100644 GIT binary patch delta 2077 zcmcJQe@v8h9LL|EUXQYyBtuFv;*4h|BWf7r8oJ)iIA z*Yo*&e>~6at1$5-IB7e8{~39*z|w4BSq`w=53Dc(D?LE& zY9MdFPQfPNT2%D|6R4akXaca^1-$PAK8#Gq!?uruGSJ)#94r7nLQ9K4J4S>qJuBN;XGz0QX#%tQ- zAgHz)RNo3}7zL^Qplxll{c7Uex39pXe(`RGIu|dn5pc_G(9V9rMGM%FykifTgI`WtKAi=SVH-@iY z1__P>2R5kxXiSsHsSsUEYA7e_ZU1zXF+P3JF}7A6)!Wq3=}EiB~6~!^mg4i zs93{ZgJvI5rIB_EkCR(E9UbX~Ly>4S>gX~m(iJVELHbjbOo}wVRXRWEbc`dp?l#U> zr7M$0FDFKaja*JTm9obrZ-;{W3pF-i?szed@o<>StlA)C}Pp*(6nZ(M~^Ix34 zJ;VGdhTGpr+uS3YX`#EciL&Rs$MqM0aIf?EZ!%Xb;;kv-C}DY=Wf|)tOX%xZ*0Y`w z)1P8_z~Js_qUEx7O0cE6;-&KP*Nb^jT3J$pS4ygjx7bmoi^>WL-1&NrG4SI~ z3YiG-=U>zR7BUIQ;>Lu0L`e2;h)KJUocC7De;(*^A^Djh z2P|4be8i7yX(+&1z=$@V@ND2e(|#3*HUTk_Kx_pt`3n&50H#_1ORjF_5}+>|8-Z?n zWvsHl6UfN|4i^K*KLk1{xzn{8P*4CACICfJ{F1D=Bu-cA2Chh-YZq`$9`1KlwZM&J zpr*yAPR96akfIM|SCu9s(A)^L)&p&_u;-P)OKm*xDg$^ejdxPmBLzRmgdZ0HpArG@ z9FSYU;0|!WS}>#&9Fz`@m-&@I?~nZUWnvgRkTp zdOZz%lPeRy{RY05q^CO2=M1pRSd!G=I&gcQp)Aip>o$ADU8{4#er7pm9He1r804I> z8Wyy7dA;84RsHr@L!289GTV{EX^HZehY^HXV)rFS0H%oBVw6z*(C9USHsM*yN8&z?mPXJqU`_x diff --git a/programs/develop/ktcc/trunk/libc/build.bat b/programs/develop/ktcc/trunk/libc/build.bat index 7f2e9e1967..2aa876eba8 100644 --- a/programs/develop/ktcc/trunk/libc/build.bat +++ b/programs/develop/ktcc/trunk/libc/build.bat @@ -10,7 +10,7 @@ set CC=kos32-tcc set CFLAGS=-c -nostdinc -DGNUC -I"%cd%\%INCLUDE%" -Wall set AR=kos32-ar set ASM=fasm -set dirs=stdio memory kolibrisys string stdlib math dlfcn libgen +set dirs=stdio memory kolibrisys string stdlib math dlfcn libgen fs rem #### END OF CONFIG SECTION #### set objs= @@ -68,4 +68,4 @@ echo # All operations has been done... # echo # For cleaning run this script with param " clean" # echo #################################################### pause -exit 0 \ No newline at end of file +exit 0 diff --git a/programs/develop/ktcc/trunk/libc/fs/dir.c b/programs/develop/ktcc/trunk/libc/fs/dir.c index b4a1d73a02..708379096d 100644 --- a/programs/develop/ktcc/trunk/libc/fs/dir.c +++ b/programs/develop/ktcc/trunk/libc/fs/dir.c @@ -35,10 +35,52 @@ bool dir_operations(unsigned char fun_num, char *path) } } +int lsdir(const char* dir, short_file_info **list) +{ + int num_of_file=0; + kol_struct70 inf; + + inf.p00 = 1; + inf.p04 = 0; + inf.p12 = 2; + inf.p16 = (unsigned*) malloc(32+inf.p12*560); + inf.p20 = 0; + inf.p21 = dir; + + if(kol_file_70(&inf)) + { + free((void*)inf.p16); + return FS_ERROR; + } + + num_of_file = *(unsigned*)(inf.p16+8); + inf.p12 = num_of_file; + free((void*)inf.p16); + inf.p16 = (unsigned) malloc(32+inf.p12*560); + *list = (short_file_info*)malloc(num_of_file*sizeof(short_file_info)); + + if(kol_file_70(&inf)) + { + free((void*)inf.p16); + return FS_ERROR; + } + + for(int i=0; i +#define rmfile(obj) rmdir(obj) #define PATH_MAX 4096 +#define PATH_MAX 4096 +#define T_FOLDER 16 +#define T_FILE 0 +#define FS_ERROR -1 + +typedef struct { + unsigned type; + char *name; +} short_file_info; + +//Writes information about files in the "dir" folder to an struct array"list". Returns the number of files. +int lsdir(const char* dir, short_file_info **list); // Get the path to the working directory(if buf is NULL, then memory will be allocated automatically) char *getcwd(char *buf, unsigned size); @@ -11,10 +24,13 @@ char *getcwd(char *buf, unsigned size); // Set path to working directory void setcwd(const char* cwd); -// Remove directory (returns "true" if successful) +// Delete empty folder (returns "true" if successful) bool rmdir(const char* dir); -// Create directory (returns "true" if successful) +// Delete a file (returns "true" if successful) +bool rmfile(const char* name); + +// Create a foldery (returns "true" if successful) bool mkdir(const char* dir); #endif diff --git a/programs/develop/ktcc/trunk/samples/dir_example.c b/programs/develop/ktcc/trunk/samples/dir_example.c index 3c56fb8ab4..3a8260c45f 100644 --- a/programs/develop/ktcc/trunk/samples/dir_example.c +++ b/programs/develop/ktcc/trunk/samples/dir_example.c @@ -2,20 +2,40 @@ #include #include #include + int main() { char *path=getcwd(NULL, PATH_MAX); printf("Current directory: %s\n", path); - setcwd("/sys"); //String must be null terminated! - path=getcwd(NULL, PATH_MAX); - printf("Move to the directory: %s\n", path); - free(path); - if(true==mkdir("TEST1")){ + if(true==mkdir("test")){ puts("Test folder created!"); - return(0); } else{ puts("Error creating folder!"); - return(-1); } + short_file_info *info; + int num = lsdir(path, &info); + if(num==FS_ERROR) + { + puts("File system error."); + return -1; + } + printf("Objects in the folder: %d\n", num); + for(int j=0; j