-
Notifications
You must be signed in to change notification settings - Fork 0
/
filewalker.h
113 lines (89 loc) · 2.9 KB
/
filewalker.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef SITH_FILEWALKER_H
#define SITH_FILEWALKER_H
#ifdef __cplusplus
extern "C" {
#endif
#include "plat.h"
#include "file.h"
#include "string_heap.h"
#include <limits.h>
#ifdef _WIN32
#define SITH_NAMESEP '\\'
// This macro accounts for a NUL character, we're removing it for consistency with all other MAXCH macros
#define SITH_MAXCH_PATHNAME (MAX_PATH - 1)
#elif defined __unix__
#define SITH_NAMESEP '/'
#include <dirent.h>
#ifdef __linux__
#include <linux/limits.h>
#elif defined __APPLE__
#include <freebsd/limits.h>
#else
#define PATH_MAX 4096
#endif
#define SITH_MAXCH_PATHNAME PATH_MAX
#else
#define SITH_MAXCH_PATHNAME 4096
#endif
//PATH_MAX on linux is not reliable. MAX_PATH on windows is reliable until we don't use \\?\ extended paths
typedef enum retMean{
return_file,
return_dir,
return_error
} ReturnWalk;
typedef struct filewalker SithWalker;
/*
* This function intialize a SithWalker.
* @param a path (can be relative or absolute), as a NULL terminated string
* @return a SithWalker (may be non-initialized)
*/
SithWalker* InitWalker(const char* path);
/*
* Walk the directory represented by this SithWalker putting results into files HeapString
*
* @param walker: The walker
* @param files : the heapstring with the content of the files
* Remarks: If processing an high number of file it may exhaust the aviable memory.
*/
int WalkInDir(SithWalker* walker, HeapString* files);
/*
* Walk the directory and it's subdirectories represented by this SithWalker putting results into files HeapString
*
* @param walker: The walker
* @param files : the heapstring with the content of the files
* Remarks: If processing an high number of file it may exhaust the aviable memory.
*/
int WalkInDirRecursive(SithWalker* walker, HeapString* files);
/*
* Start the directory walking.
* Cannot be called if it's already initialized.
* @walker : a walker
* @size: a pointer to a writable FileSize object.
* @file: a string that will be filled with file path
* @return walker_success if file, walker_dir if directory, walker_error if generic error.
*/
ReturnWalk WalkFirst(SithWalker* walker, FileSize* size, HeapString* file);
/*
* Start the directory walking.
* Must be called with an already initialized walker.
* @walker : a walker
* @size: a pointer to a writable FileSize object.
* @file: a string that will be filled with file path
* @return walker_success if file, walker_dir if directory, walker_error if generic error.
*/
ReturnWalk WalkNext(SithWalker* walker, FileSize* size, HeapString* file);
/*
* Reset the walker to the initial state
*/
void WalkReset(SithWalker* walker);
/*
* The walker is disposed and cannot be used again
* The memory internally occupied is freed if any.
*/
void DisposeWalker(SithWalker* walker);
int GetWorkingDirectory(char* buffer, size_t length);
int SetWorkingDirectory(const char* path);
#ifdef __cplusplus
}
#endif
#endif /* SITH_FILEWALKER_H */