MCPcopy Create free account
hub / github.com/apache/thrift / include_file

Function include_file

compiler/cpp/src/thrift/main.cc:343–392  ·  view source on GitHub ↗

* Finds the appropriate file path for the given filename */

Source from the content-addressed store, hash-verified

341 * Finds the appropriate file path for the given filename
342 */
343string include_file(string filename) {
344 // Absolute path? Just try that
345 if (filename[0] == '/') {
346 // Realpath!
347 char rp[THRIFT_PATH_MAX];
348 // cppcheck-suppress uninitvar
349 if (saferealpath(filename.c_str(), rp, THRIFT_PATH_MAX) == nullptr) {
350 pwarning(0, "Cannot open include file %s\n", filename.c_str());
351 return std::string();
352 }
353
354 // Stat this file
355 struct stat finfo;
356 if (stat(rp, &finfo) == 0) {
357 return rp;
358 }
359 } else { // relative path, start searching
360 // new search path with current dir global
361 vector<string> sp = g_incl_searchpath;
362 sp.insert(sp.begin(), g_curdir);
363
364 // iterate through paths
365 vector<string>::iterator it;
366 for (it = sp.begin(); it != sp.end(); it++) {
367 string sfilename = *(it) + "/" + filename;
368
369 // Realpath!
370 char rp[THRIFT_PATH_MAX];
371 // cppcheck-suppress uninitvar
372 if (saferealpath(sfilename.c_str(), rp, THRIFT_PATH_MAX) == nullptr) {
373 continue;
374 }
375
376 // Stat this files
377 struct stat finfo;
378 if (stat(rp, &finfo) == 0) {
379 return rp;
380 }
381 }
382 }
383
384 // Uh oh
385 if (g_strict >= 192) {
386 // On strict mode this should be failure instead of warning
387 failure("Could not find include file %s", filename.c_str());
388 } else {
389 pwarning(0, "Could not find include file %s\n", filename.c_str());
390 }
391 return std::string();
392}
393
394/**
395 * Clears any previously stored doctext string.

Callers

nothing calls this directly

Calls 7

saferealpathFunction · 0.85
stringFunction · 0.85
statClass · 0.85
pwarningFunction · 0.70
failureFunction · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected