Files
kolibrios/programs/develop/ktcc/trunk/libc.obj/samples/dir_example.c
Egor00f 15f27eb1c3 libc.obj: add call exit after main && add build for ctr0.o && use return instead exit in samples
нен работает
по стандартам после `main` должно быть закрыте всего, что закрывается в `exit`
ну терпите, crt увеличиласть на несколько байт
обертка для `exit` в crt нужна т.к. `exit` импортируется.

зачем вообще было держать бинарь `libc.obj/lib/crt0.o`, если абсолютно такой же лежит в `bin/lib/` всемсте `tcc`? Нет, зачем вообще тащить бинари в репку?
2026-01-15 21:19:10 +05:00

47 lines
1.1 KiB
C

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/dir.h>
#include <sys/dirent.h>
const char* folder_type = "Folder";
const char* file_type = "File";
int main()
{
char* path = getcwd(NULL, PATH_MAX);
printf("Current directory: %s\n", path);
if (mkdir("test")) {
puts("Test folder created!");
} else {
puts("Error creating folder!");
}
DIR* mydir = opendir(path);
if (!mydir) {
puts("File system error.");
return -1;
}
struct dirent* file_info;
char* str_type = NULL;
putc(' ');
while ((file_info = readdir(mydir)) != NULL) {
if (file_info->d_type == IS_FOLDER) {
(*con_set_flags)(CON_COLOR_GREEN);
str_type = (char*)folder_type;
} else {
(*con_set_flags)(7);
str_type = (char*)file_type;
}
printf("%3d %20s %s\n ", file_info->d_ino, file_info->d_name, str_type);
};
setcwd("/sys/develop");
path = getcwd(NULL, PATH_MAX);
printf("Move to the directory: %s\n", path);
free(path);
return 0;
}