Add function scan directory

This commit is contained in:
Fabio Scotto di Santolo
2026-07-31 20:09:37 +02:00
parent af56ec524d
commit 078b95dc4b
7 changed files with 224 additions and 0 deletions

29
src/main.c Normal file
View File

@@ -0,0 +1,29 @@
#include "scan.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "command not found [scan]\n");
return EXIT_FAILURE;
}
// I check the argument command exists
errno = 0;
const char *cmd = argv[1];
if (strcmp(cmd, "scan") == 0) {
const char *directory = argv[2];
if (scan(directory) == -1) {
const int err = errno;
fprintf(stderr, "scan failed: %s\n", strerror(err));
return EXIT_FAILURE;
}
} else {
fprintf(stderr, "command %s is not valid\n", cmd);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}