- 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
This commit is contained in:
superturbocat2001 2020-11-29 22:05:50 +00:00
parent 53ddecef5a
commit 5941f0e334
6 changed files with 111 additions and 2 deletions

View File

@ -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

View File

@ -0,0 +1,64 @@
#include <stdlib.h>
#include <dir.h>
#include <stdbool.h>
#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);
}

View File

@ -0,0 +1,20 @@
#ifndef _DIR_H
#define _DIR_H
#include <stdbool.h>
#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

View File

@ -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

View File

@ -0,0 +1,21 @@
#include <dir.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
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);
}
}