cwFileSys.cpp: expandPath() now drops leading white space. pathParts() now expands the path prior to splitting it.
This commit is contained in:
parent
dd7dcc654e
commit
2171d8a0a6
@ -329,9 +329,19 @@ char* cw::filesys::expandPath( const char* dir )
|
|||||||
|
|
||||||
memset(&res,0,sizeof(res));
|
memset(&res,0,sizeof(res));
|
||||||
|
|
||||||
|
// if dir is empty
|
||||||
if( dir == nullptr )
|
if( dir == nullptr )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
// skip leading white space
|
||||||
|
for(; *dir; ++dir)
|
||||||
|
if( !isspace(*dir) )
|
||||||
|
break;
|
||||||
|
|
||||||
|
// if dir is empty
|
||||||
|
if( strlen(dir) == 0 )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
if((sysRC = wordexp(dir,&res,flags)) != 0)
|
if((sysRC = wordexp(dir,&res,flags)) != 0)
|
||||||
{
|
{
|
||||||
switch(sysRC)
|
switch(sysRC)
|
||||||
@ -387,7 +397,7 @@ char* cw::filesys::expandPath( const char* dir )
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cw::filesys::pathPart_t* cw::filesys::pathParts( const char* pathStr )
|
cw::filesys::pathPart_t* cw::filesys::pathParts( const char* path0Str )
|
||||||
{
|
{
|
||||||
unsigned n = 0; // char's in pathStr
|
unsigned n = 0; // char's in pathStr
|
||||||
unsigned dn = 0; // char's in the dir part
|
unsigned dn = 0; // char's in the dir part
|
||||||
@ -396,6 +406,9 @@ cw::filesys::pathPart_t* cw::filesys::pathParts( const char* pathStr )
|
|||||||
char* cp = nullptr;
|
char* cp = nullptr;
|
||||||
pathPart_t* rp = nullptr;
|
pathPart_t* rp = nullptr;
|
||||||
|
|
||||||
|
char* pathBaseStr = expandPath(path0Str);
|
||||||
|
const char* pathStr = pathBaseStr;
|
||||||
|
|
||||||
if( pathStr==nullptr )
|
if( pathStr==nullptr )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
@ -415,10 +428,15 @@ cw::filesys::pathPart_t* cw::filesys::pathParts( const char* pathStr )
|
|||||||
|
|
||||||
// if pathStr is empty
|
// if pathStr is empty
|
||||||
if( n == 0 )
|
if( n == 0 )
|
||||||
return nullptr;
|
{
|
||||||
|
// nothing to do
|
||||||
|
goto errLabel;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char buf[n+1];
|
char buf[n+1];
|
||||||
buf[n] = 0;
|
buf[n] = 0;
|
||||||
|
|
||||||
@ -522,7 +540,12 @@ cw::filesys::pathPart_t* cw::filesys::pathParts( const char* pathStr )
|
|||||||
if( en == 0 )
|
if( en == 0 )
|
||||||
rp->extStr = nullptr;
|
rp->extStr = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
errLabel:
|
errLabel:
|
||||||
|
|
||||||
|
mem::release(pathBaseStr);
|
||||||
|
|
||||||
|
|
||||||
return rp;
|
return rp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user