mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Improve detail::script_specific_filename()
- To handle relative paths that don't start with a '.' - To handle getcwd() failures
This commit is contained in:
parent
d3261238dd
commit
ab1f1f8360
1 changed files with 7 additions and 4 deletions
|
@ -29,16 +29,19 @@ std::string script_specific_filename(const StmtPtr& body)
|
||||||
auto bl_f = body_loc->filename;
|
auto bl_f = body_loc->filename;
|
||||||
ASSERT(bl_f != nullptr);
|
ASSERT(bl_f != nullptr);
|
||||||
|
|
||||||
if ( bl_f[0] == '.' &&
|
if ( (bl_f[0] != '.' && bl_f[0] != '/') ||
|
||||||
(bl_f[1] == '/' || (bl_f[1] == '.' && bl_f[2] == '/')) )
|
(bl_f[0] == '.' && (bl_f[1] == '/' ||
|
||||||
|
(bl_f[1] == '.' && bl_f[2] == '/'))) )
|
||||||
{
|
{
|
||||||
// Add working directory to avoid collisions over the
|
// Add working directory to avoid collisions over the
|
||||||
// same relative name.
|
// same relative name.
|
||||||
static std::string working_dir;
|
static std::string working_dir;
|
||||||
if ( working_dir.size() == 0 )
|
if ( working_dir.empty() )
|
||||||
{
|
{
|
||||||
char buf[8192];
|
char buf[8192];
|
||||||
getcwd(buf, sizeof buf);
|
if ( ! getcwd(buf, sizeof buf) )
|
||||||
|
reporter->InternalError("getcwd failed: %s", strerror(errno));
|
||||||
|
|
||||||
working_dir = buf;
|
working_dir = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue