mirror of
https://github.com/fscotto/fsnap.git
synced 2026-11-26 03:09:51 +00:00
Add function scan directory
This commit is contained in:
29
src/main.c
Normal file
29
src/main.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user