-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfs.h
44 lines (37 loc) · 894 Bytes
/
fs.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
/*
* Copyright (C) dirlt
*/
#ifndef __CC_COMMON_FS_H__
#define __CC_COMMON_FS_H__
#include <sys/types.h>
#include <dirent.h>
#include <vector>
#include <string>
#include <cstring>
#include "common/log.h"
namespace common {
static inline int list_directory(const char* path,
std::vector< std::string >* files) {
DIR* dir = opendir(path);
if(dir == NULL) {
WARNING("opendir(%s) failed(%s)", path, SERRNO);
return -1;
}
struct dirent* ent = NULL;
files->clear();
while(1) {
ent = readdir(dir);
if(ent == NULL) {
break;
}
if(strcmp(ent->d_name, ".") == 0 ||
strcmp(ent->d_name, "..") == 0) {
continue;
}
files->push_back(ent->d_name);
}
closedir(dir);
return 0;
}
}; // namespace common
#endif // __CC_COMMON_FS_H__