Skip to content

Commit

Permalink
fix windows implicit path e.g., A --> A.ck
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Oct 18, 2024
1 parent 361e56d commit 018a2c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/core/util_platforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,20 @@ t_CKBOOL ck_isdir( const std::string & path )



//-----------------------------------------------------------------------------
// name: ck_fileexists()
// desc: check if file exists
//-----------------------------------------------------------------------------
t_CKBOOL ck_fileexists( const std::string & path )
{
// shuttle
struct stat fs;
// stat the path; 0 means success
return ( stat( path.c_str(), &fs ) == 0 );
}



#ifdef __PLATFORM_WINDOWS__
//-----------------------------------------------------------------------------
// name: win32_getline()
Expand Down
2 changes: 2 additions & 0 deletions src/core/util_platforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ FILE * ck_tmpfile();

// check if is dir
t_CKBOOL ck_isdir( const std::string & path );
// check if file exists
t_CKBOOL ck_fileexists( const std::string & path );

// do any platform-specific setup to enable ANSI escape codes
t_CKBOOL ck_configANSI_ESCcodes();
Expand Down
12 changes: 10 additions & 2 deletions src/core/util_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
// date: Summer 2005
//-----------------------------------------------------------------------------
#include "util_string.h"
#include "util_platforms.h"
#include "chuck_errmsg.h"

#ifdef __PLATFORM_WINDOWS__
Expand Down Expand Up @@ -772,7 +773,7 @@ std::string get_full_path( const std::string & fp )
if( result == NULL && !extension_matches(fp, ".ck") )
result = realpath((fp + ".ck").c_str(), buf);

if(result == NULL)
if( result == NULL )
return fp;
else
return buf;
Expand All @@ -787,6 +788,13 @@ std::string get_full_path( const std::string & fp )
DWORD result = GetFullPathNameA(fp.c_str(), MAX_PATH, buf, NULL);
#endif

// if successful
if( result )
{
// check if file exists; if not reset result
result = ck_fileexists( fp ) ? result : 0;
}

// try with .ck extension
if( result == 0 && !extension_matches(fp, ".ck") )
{
Expand All @@ -798,7 +806,7 @@ std::string get_full_path( const std::string & fp )
#endif
}

if(result == 0)
if( result == 0 )
return fp;
else
return normalize_directory_separator(buf);
Expand Down

0 comments on commit 018a2c2

Please sign in to comment.