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:
31
src/scan.c
Normal file
31
src/scan.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#define _XOPEN_SOURCE 500
|
||||
#include "scan.h"
|
||||
#include "walk.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef PATH_MAX
|
||||
static long pathmax = PATH_MAX;
|
||||
#else
|
||||
static long pathmax = 1024;
|
||||
#endif
|
||||
|
||||
int print_file(const char *file) {
|
||||
printf("[%s]\n", file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Scan recursively directory, printing all entry */
|
||||
int scan(const char *directory) {
|
||||
if (directory == NULL || strlen(directory) == 0)
|
||||
return -1;
|
||||
char path[pathmax];
|
||||
const char *dir = NULL;
|
||||
if ((dir = realpath(directory, path)) == NULL) {
|
||||
perror("realpath");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return walk(dir, print_file);
|
||||
}
|
||||
Reference in New Issue
Block a user