From 5941f0e3343eab912ef03c7fe1adc8fa759fd332 Mon Sep 17 00:00:00 2001 From: superturbocat2001 Date: Sun, 29 Nov 2020 22:05:50 +0000 Subject: [PATCH] - Added 4 functions to libck: getcwd, setcwd, mkdir, rmdir. - Fixed Makefile for building "libck" under tcc. - Added example to new functions git-svn-id: svn://kolibrios.org@8280 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/ktcc/trunk/bin/lib/libck.a | Bin 130124 -> 131106 bytes .../ktcc/trunk/libc/{makefile => Makefile} | 7 +- programs/develop/ktcc/trunk/libc/fs/dir.c | 64 ++++++++++++++++++ .../develop/ktcc/trunk/libc/include/dir.h | 20 ++++++ .../develop/ktcc/trunk/samples/build_all.sh | 1 + .../develop/ktcc/trunk/samples/dir_example.c | 21 ++++++ 6 files changed, 111 insertions(+), 2 deletions(-) rename programs/develop/ktcc/trunk/libc/{makefile => Makefile} (80%) create mode 100644 programs/develop/ktcc/trunk/libc/fs/dir.c create mode 100644 programs/develop/ktcc/trunk/libc/include/dir.h create mode 100644 programs/develop/ktcc/trunk/samples/dir_example.c diff --git a/programs/develop/ktcc/trunk/bin/lib/libck.a b/programs/develop/ktcc/trunk/bin/lib/libck.a index cd0266c33748c77b2a7fd99941a996c07f23cfdc..f41bc4736d63afea13eeed0270f30c42effa7ede 100644 GIT binary patch delta 9669 zcmb_h30zd=7C&cT6c7Rh12kw<6hVPI3(Vlc0~0mN9&J`u>WHJFECORLS!gcLrA)oa zXFl_33*|=Om=}@U@>TXUm#kiDhOKI4T4t7}?|kKDwugl)-ys^g{|Om&0uU zj(z~}$w7cm$+ORQ0({j4;N%p5uj%+S89qY>zbA!14gt830dS=sAU+Q0cM7n@Sipeu zfUO1thExKE^#E+M6R>SLU=&?%Zx9mu4qyj5k9(vHF#ayUM7kkqO`|A}05*ud3m}(X zQ+_MA1Oa9b1nfW0H_1H(IO-k1yjri6H5|}B|II%~%H9QhVl3dS3cxvE0?z*caKW12 zm$Jp10DY12?to2YX+OYc>x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qX$Pr+V*{Eq9;BIJ&kluU(PICvGAXe-h4mDtt zugtlys&NeXprgP6guH29Y(rFiPx_G}9OzM!NDT-#Ch2b>f z9ClM>@)~yza&dB027w}4Z~>w%@=d;-Gp;o^+5*cOP~eAWp(``#_F1rS(~PSYhX5wu zP()~RJan;V=jP>e^7WnP&W8`vu&*J4&OZ;`nFDp_(SZ!+K$+rzLzX|0Q*eI=a4h9V zB}GA8tL#uZ`D;kv9Qx%dI>huD%9ukm{Gxu`%Wgng$lbk!e$#+Q@52`{XZ~^BNnc%p z|HfX!6c*I+dq*?k@{N{qhEq;uwRJEahb!v-2AYicb1WG^yWyCnOt^SsB!6tdx3TgR z8Abno2|DT_M7EUX)_I@x<_TEHYQ$rWc%r({!1PVz@XM(( zczpPEUkkzk85NtZ`BCxHHBA6_rXMu%2y<$cP^uuTVnh4Vt=0}*3 z7GL*E^j_yc!NJUerHzXzcP0oZdpP~-hQCay=m+OoYa8B?$yuX~**w%Vg<|XT zPZBw>kZb#axY>}>e-f+zquSmz+0ACVO{ngXAjRB-zl5n%d;n$__p?;*RT0t;KSQFPMN;Y=xD@gq4oG`} diff --git a/programs/develop/ktcc/trunk/libc/makefile b/programs/develop/ktcc/trunk/libc/Makefile similarity index 80% rename from programs/develop/ktcc/trunk/libc/makefile rename to programs/develop/ktcc/trunk/libc/Makefile index 1e4c6b4539..cc383c8538 100644 --- a/programs/develop/ktcc/trunk/libc/makefile +++ b/programs/develop/ktcc/trunk/libc/Makefile @@ -1,9 +1,9 @@ INCLUDE = include LIBSFORBUILD = math LIBNAME = libck.a -CC = gcc +CC = ../bin/kos32-tcc CFLAGS = -I$(INCLUDE) -m32 -nostdinc -nostdlib -DGNUC -DIRS := stdio kolibrisys string stdlib memory math +DIRS := stdio memory kolibrisys string stdlib math dlfcn libgen fs ############################################################## #files := $(foreach dir,$(DIRS),$(dir)/$(wildcard $(dir)/*)) @@ -28,3 +28,6 @@ $(asmfiles): clean: $(doClean) + +install: + cp $(LIBNAME) ../bin/lib diff --git a/programs/develop/ktcc/trunk/libc/fs/dir.c b/programs/develop/ktcc/trunk/libc/fs/dir.c new file mode 100644 index 0000000000..b4a1d73a02 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/fs/dir.c @@ -0,0 +1,64 @@ +#include +#include +#include + +#pragma pack(push,1) +typedef struct { + unsigned p00; + unsigned long long p04; + unsigned p12; + unsigned p16; + char p20; + char *p21; +} kol_struct70; +#pragma pack(pop) + +int kol_file_70(kol_struct70 *k) +{ + asm volatile ("int $0x40"::"a"(70), "b"(k)); +} + +bool dir_operations(unsigned char fun_num, char *path) +{ + kol_struct70 inf; + inf.p00 = fun_num; + inf.p04 = 0; + inf.p12 = 0; + inf.p16 = 0; + inf.p20 = 0; + inf.p21 = path; + if(!kol_file_70(&inf)){ + return true; + } + else { + return false; + } +} + +char *getcwd(char *buf, unsigned size) +{ + if(buf == NULL){ + buf = malloc(size); + } + __asm__ __volatile__( + "int $0x40" + ::"a"(30),"b"(2),"c"(buf), "d"(size)); + return(buf); +} + +void setcwd(const char* cwd) +{ + __asm__ __volatile__( + "int $0x40" + ::"a"(30),"b"(1),"c"(cwd)); +} + +bool rmdir(const char* dir) +{ + return dir_operations(8, dir); +} + +bool mkdir(const char* dir) +{ + return dir_operations(9, dir); +} diff --git a/programs/develop/ktcc/trunk/libc/include/dir.h b/programs/develop/ktcc/trunk/libc/include/dir.h new file mode 100644 index 0000000000..f22ad7be20 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/include/dir.h @@ -0,0 +1,20 @@ +#ifndef _DIR_H +#define _DIR_H + +#include + +#define PATH_MAX 4096 + +// Get the path to the working directory(if buf is NULL, then memory will be allocated automatically) +char *getcwd(char *buf, unsigned size); + +// Set path to working directory +void setcwd(const char* cwd); + +// Remove directory (returns "true" if successful) +bool rmdir(const char* dir); + +// Create directory (returns "true" if successful) +bool mkdir(const char* dir); + +#endif diff --git a/programs/develop/ktcc/trunk/samples/build_all.sh b/programs/develop/ktcc/trunk/samples/build_all.sh index 60c0dc970d..8ef72d69ff 100644 --- a/programs/develop/ktcc/trunk/samples/build_all.sh +++ b/programs/develop/ktcc/trunk/samples/build_all.sh @@ -11,4 +11,5 @@ ../tcc clayer/boxlib.c -lck -lbox -o /tmp0/1/boxlib_ex ../tcc clayer/libimg.c -lck -limg -o /tmp0/1/libimg_ex ../tcc console/console.c -lck -limg -o /tmp0/1/console +../tcc dir_example.c -lck -o /tmp0/1/dir_example exit diff --git a/programs/develop/ktcc/trunk/samples/dir_example.c b/programs/develop/ktcc/trunk/samples/dir_example.c new file mode 100644 index 0000000000..3c56fb8ab4 --- /dev/null +++ b/programs/develop/ktcc/trunk/samples/dir_example.c @@ -0,0 +1,21 @@ +#include +#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")){ + puts("Test folder created!"); + return(0); + } + else{ + puts("Error creating folder!"); + return(-1); + } +}