Static Value-Flow Analysis
Loading...
Searching...
No Matches
Functions
ExtAPI.cpp File Reference
#include "Util/ExtAPI.h"
#include "Util/SVFUtil.h"
#include "Util/Options.h"
#include "Util/config.h"
#include <ostream>
#include <sys/stat.h>
#include "SVFIR/SVFVariables.h"
#include <dlfcn.h>

Go to the source code of this file.

Functions

static std::string GetStdoutFromCommand (const std::string &command)
 
static std::string getFilePath (const std::string &path)
 
std::string getCurrentSOPath ()
 

Function Documentation

◆ getCurrentSOPath()

std::string getCurrentSOPath ( )

Definition at line 143 of file ExtAPI.cpp.

144{
146 if (dladdr((void*)&getCurrentSOPath, &info) && info.dli_fname)
147 {
148 return std::string(info.dli_fname);
149 }
150 return "";
151}
std::string getCurrentSOPath()
Definition ExtAPI.cpp:143
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ getFilePath()

static std::string getFilePath ( const std::string path)
static

Definition at line 102 of file ExtAPI.cpp.

103{
104 std::string bcFilePath;
105
106 if (path == "SVF_DIR")
107 {
108 const char* svfdir = getenv("SVF_DIR");
109 if (!svfdir)
110 return "";
111
113
114 if (!bcFilePath.empty() && bcFilePath.back() != '/')
115 bcFilePath.push_back('/');
116
117 bcFilePath.append(SVF_BUILD_TYPE "-build/lib/extapi.bc");
118 }
119 else if (path == "npm root")
120 {
121 // Check npm exists before calling `npm root`.
122 // If npm is missing, this command returns empty.
124 "command -v npm >/dev/null 2>&1 && npm root"
125 );
126
127 if (bcFilePath.empty())
128 return "";
129
130 if (bcFilePath.back() != '/')
131 bcFilePath.push_back('/');
132
133 bcFilePath.append("SVF/lib/extapi.bc");
134 }
135
136 return bcFilePath;
137}
static std::string GetStdoutFromCommand(const std::string &command)
Definition ExtAPI.cpp:76
char * getenv(const char *name)
Definition extapi.c:1172

◆ GetStdoutFromCommand()

static std::string GetStdoutFromCommand ( const std::string command)
static

Definition at line 76 of file ExtAPI.cpp.

77{
78 char buffer[128];
79 std::string result;
80
81 FILE* pipe = popen(command.c_str(), "r");
82 if (!pipe)
83 return "";
84
85 while (fgets(buffer, sizeof(buffer), pipe) != nullptr)
86 {
87 result += buffer;
88 }
89
90 int status = pclose(pipe);
91 if (status != 0)
92 return "";
93
94 // remove trailing newlines
95 result.erase(std::remove(result.begin(), result.end(), '\n'), result.end());
96 result.erase(std::remove(result.begin(), result.end(), '\r'), result.end());
97
98 return result;
99}
char * buffer
Definition cJSON.h:163
char * fgets(char *str, int n, void *stream)
Definition extapi.c:869