forked from vusec/vuzzer64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosutils.H
74 lines (61 loc) · 1.66 KB
/
osutils.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
///
/// @file
/// \brief Utility functions with OS-specific implementations.
///
#ifndef __OSUTILS_H__
#define __OSUTILS_H__
#include <iostream>
#include <string>
#include <assert.h>
#include <libgen.h>
#include <limits.h>
#include <regex.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <set>
#include "pin.H"
#include "libdft_api.h"
extern std::string filename;
extern std::set<int> fdset;
// Check whether the file needs to be tainted or not
inline int in_dtracker_whitelist(const std::string & fname) {
LOG("in_dtracker_whitelist " + fname + "\n");
if(fname.find(filename) != std::string::npos){
return 0;
}else{
return 1;
}
}
inline int path_isdir(const std::string & path) {
#if defined(TARGET_LINUX) || defined(TARGET_MAC)
struct stat stats;
return (stat(path.c_str(), &stats) == 0 && S_ISDIR(stats.st_mode));
#elif defined(TARGET_WINDOWS)
assert(0);
return -1;
#endif
}
inline int path_exists(const std::string & path) {
#if defined(TARGET_LINUX) || defined(TARGET_MAC)
return (access(path.c_str(), F_OK) == 0);
#elif defined(TARGET_WINDOWS)
assert(0);
return -1;
#endif
}
///
/// @brief Resolves an open file descriptor to a filename.
///
/// Any symbolic links in the path are resolved. If an error occurs,
/// the respective error message is returned instead of the file path.
/// Because the function uses a static buffer, the file path may be
/// returned truncated ending with "...".
///
/// @param fd -- the file descriptor to be resolved.
/// @return A string representing the full path to the file.
std::string fdname(int fd);
#endif
/* vim: set noet ts=4 sts=4 sw=4 ai : */