This commit is contained in:
TheK0tYaRa 2025-06-15 14:05:16 +03:00
parent f1652cd9f5
commit ca37985ab2
5 changed files with 2 additions and 102 deletions

4
.gitignore vendored
View file

@ -1,2 +1,2 @@
./.vscode
./bin
.vscode/
bin/

View file

@ -1,4 +0,0 @@
{
"C_Cpp.default.configurationProvider": "mesonbuild.mesonbuild",
"C_Cpp.default.compileCommands": "/home/thek0tyara/Documents/projects/c/builddir/compile_commands.json"
}

BIN
bin/main

Binary file not shown.

View file

@ -1,57 +0,0 @@
/*
// Helper to create child paths safely
char* make_child_path(const char* parent, const char* child) {
size_t parent_len = strlen(parent);
size_t child_len = strlen(child);
size_t total = parent_len + child_len + 2; // +2 for '/' and null term
char* path = malloc(total);
if (!path) return NULL;
snprintf(path, total, "%s/%s", parent, child);
return path;
}
// Inside your directory processing loop:
d = (struct linux_dirent64*)(buf + bpos);
bpos += d->d_reclen;
// Skip . and ..
if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0)
continue;
// Create child path safely
char* child_path = make_child_path(node->path, d->d_name);
if (!child_path) {
perror("malloc failed");
continue;
}
// Use stack variable for stat (no allocation)
struct stat file_stat;
if (lstat(child_path, &file_stat) == -1) { // Use lstat to avoid following symlinks
perror("stat failed");
free(child_path);
continue;
}
// Determine file type
const char* type = "OTHER";
long path_size = 0;
if (S_ISREG(file_stat.st_mode)) {
type = "FILE";
path_size = file_stat.st_size;
}
else if (S_ISDIR(file_stat.st_mode)) {
type = "DIR";
// For directory metadata size only (not contents!)
path_size = file_stat.st_blocks * 512;
}
// Add more types (LNK, FIFO, etc) as needed
printf("%s\t%ld\t%s\n", type, path_size, d->d_name);
// Cleanup
free(child_path);
*/

View file

@ -1,39 +0,0 @@
/*
d = (struct linux_dirent64 *)(buf + bpos);
bpos += d->d_reclen;
// Skip . and .. entries
if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0)
continue;
// Print filename (no path, no metadata)
//
char *child_path=node->path;
strcat(child_path, "/");
strcat(child_path, d->d_name);
struct stat *file_stat=malloc(sizeof(struct stat));
// bool is_dir;
if (stat(child_path, file_stat) == -1) {
perror("stat failed");
}
long path_size = 0;
switch (file_stat->st_mode & S_IFMT) {
case S_IFREG:
path_size=file_stat->st_size;
printf("FILE\t%ld\t%s\n", path_size, child_path);
break;
case S_IFDIR:
path_size=file_stat->st_blocks*512;
printf("DIR\t%ld\t%s/\n", path_size, child_path);
break;
default:
printf("UNKNOWN\t%ld\t%s\n", path_size, child_path);
break;
}
free(child_path);
// free(file_stat);
// free(d);
printf("next...\n");
*/