Skip to content

Commit

Permalink
fix fullpath/dir() with extension-less files
Browse files Browse the repository at this point in the history
  • Loading branch information
spencersalazar committed Jul 17, 2014
1 parent cdda073 commit 9a1a987
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/chuck_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static void usage()
#else
extern "C" int chuck_main( int argc, const char ** argv )
#endif
{
{
Chuck_Compiler * compiler = NULL;
Chuck_VM * vm = NULL;
Chuck_VM_Code * code = NULL;
Expand Down
16 changes: 16 additions & 0 deletions src/util_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ std::string get_full_path( const std::string & fp )

char * result = realpath(fp.c_str(), buf);

// try with .ck extension
if(result == NULL && !str_endsin(fp.c_str(), ".ck"))
result = realpath((fp + ".ck").c_str(), buf);

if(result == NULL)
return fp;
else
Expand All @@ -410,6 +414,10 @@ std::string get_full_path( const std::string & fp )

DWORD result = GetFullPathName(fp.c_str(), MAX_PATH, buf, NULL);

// try with .ck extension
if(result == 0 && !str_endsin(fp.c_str(), ".ck"))
result = GetFullPathName((fp + ".ck").c_str(), MAX_PATH, buf, NULL);

if(result == 0)
return fp;
else
Expand Down Expand Up @@ -539,3 +547,11 @@ std::string normalize_directory_separator(const std::string &filepath)
return std::string(filepath);
#endif // __PLATFORM_WIN32__
}

int str_endsin(const char *str, const char *end)
{
size_t len = strlen(str);
size_t endlen = strlen(end);

return strncmp(str+(len-endlen), end, endlen) == 0;
}
4 changes: 4 additions & 0 deletions src/util_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ std::string extract_filepath_dir(std::string &filepath);
// convert \ to / (on Windows)
std::string normalize_directory_separator(const std::string &filepath);

// determine if the last characters of str match end exactly
// e.g. to test file extension
int str_endsin(const char *str, const char *end);

//-----------------------------------------------------------------------------
// name: parse_path_list()
// desc: split "x:y:z"-style path list into {"x","y","z"}
Expand Down

0 comments on commit 9a1a987

Please sign in to comment.