cleanup
This commit is contained in:
parent
f1652cd9f5
commit
c01b0c06c5
5 changed files with 3 additions and 102 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
./.vscode
|
||||
./bin
|
||||
.vscode/
|
||||
bin/
|
||||
src/tmp*
|
||||
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
|
|
@ -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
BIN
bin/main
Binary file not shown.
57
src/tmp1.c
57
src/tmp1.c
|
|
@ -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);
|
||||
*/
|
||||
39
src/tmp2.c
39
src/tmp2.c
|
|
@ -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");
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue