diff --git a/programs/develop/ktcc/trunk/bin/lib/libck.a b/programs/develop/ktcc/trunk/bin/lib/libck.a index cd0266c337..f41bc4736d 100644 Binary files a/programs/develop/ktcc/trunk/bin/lib/libck.a and b/programs/develop/ktcc/trunk/bin/lib/libck.a differ 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); + } +}