Refactor search_for_file() util function.

It was getting too bloated and allocated memory in ways that were
difficult to understand how to manage.  Separated out primarily in to
new find_file() and open_file()/open_package() functions.

Also renamed other util functions for path-related things.
This commit is contained in:
Jon Siwek 2013-10-07 15:01:03 -05:00
parent 68227f112d
commit 90477df973
9 changed files with 331 additions and 304 deletions

View file

@ -342,18 +342,16 @@ vector<ParseLocationRec> parse_location_string(const string& s)
if ( ! sscanf(line_string.c_str(), "%d", &plr.line) )
plr.type = plrUnknown;
FILE* throwaway = search_for_file(filename.c_str(), "bro",
&full_filename, true, 0);
if ( ! throwaway )
string path(find_file(filename, bro_path(), "bro"));
if ( path.empty() )
{
debug_msg("No such policy file: %s.\n", filename.c_str());
plr.type = plrUnknown;
return result;
}
fclose(throwaway);
loc_filename = full_filename;
loc_filename = copy_string(path.c_str());
plr.type = plrFileAndLine;
}
}