MCPcopy Create free account
hub / github.com/clementgallet/libTAS / queryCmdPid

Function queryCmdPid

src/program/utils.cpp:154–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154std::string queryCmdPid(const char **command, pid_t* popen_pid)
155{
156 std::string outputstr;
157 int p[2];
158 FILE *output;
159 pid_t pid;
160
161 if (pipe(p) != 0)
162 return "";
163
164 pid = fork();
165
166 if (pid < 0)
167 return "";
168 else if (pid == 0) {
169 close(p[STDIN_FILENO]);
170 dup2(p[STDOUT_FILENO], STDOUT_FILENO);
171
172 execvp(*command, const_cast<char* const*>(command));
173 perror("execvp");
174 _exit(1);
175 }
176
177 *popen_pid = pid;
178
179 close(p[STDOUT_FILENO]);
180 output = fdopen(p[STDIN_FILENO], "r");
181
182 if (output != NULL) {
183 char buf[256];
184 if (fgets(buf, 256, output) != 0) {
185 outputstr = buf;
186 }
187 }
188
189 /* Trim the value */
190 size_t end = outputstr.find_last_not_of(" \n\r\t\f\v");
191 outputstr = (end == std::string::npos) ? "" : outputstr.substr(0, end + 1);
192
193 /* Close pipe */
194 fclose(output);
195
196 return outputstr;
197}
198
199uint64_t getSymbolAddress(const char* symbol, const char* file)
200{

Callers 1

game_engineMethod · 0.85

Calls 6

forkFunction · 0.85
closeFunction · 0.85
dup2Function · 0.85
fcloseFunction · 0.85
find_last_not_ofMethod · 0.80
substrMethod · 0.80

Tested by

no test coverage detected