mirror of
https://github.com/KolibriOS/kolibrios.git
synced 2024-12-29 01:39:41 +03:00
- 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
This commit is contained in:
parent
e34d1445df
commit
5451715e39
Binary file not shown.
@ -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
|
||||
exit 0
|
||||
|
@ -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<num_of_file; i++)
|
||||
{
|
||||
(*list)[i].type = *(unsigned*)(inf.p16+32+(264+40)*i);
|
||||
(*list)[i].name =(char*)(inf.p16+32+40+(264+40)*i);
|
||||
}
|
||||
return num_of_file;
|
||||
}
|
||||
|
||||
|
||||
char *getcwd(char *buf, unsigned size)
|
||||
{
|
||||
if(buf == NULL){
|
||||
buf = malloc(size);
|
||||
if((buf = malloc(size))==NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
__asm__ __volatile__(
|
||||
"int $0x40"
|
||||
|
@ -3,7 +3,20 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#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
|
||||
|
@ -2,20 +2,40 @@
|
||||
#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")){
|
||||
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<num; j++)
|
||||
{
|
||||
printf("%s ", info[j].name);
|
||||
if(info[j].type==T_FOLDER)
|
||||
{
|
||||
printf("(Folder)\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("(File)\n");
|
||||
}
|
||||
}
|
||||
free(info);
|
||||
setcwd("/sys");
|
||||
path=getcwd(NULL, PATH_MAX);
|
||||
printf("Move to the directory: %s\n", path);
|
||||
free(path);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user