filesys.cpp: Add nullptr guards to isDir(), isFile(), isLink().

This commit is contained in:
kevin 2022-05-14 10:12:47 -04:00
parent bd43bd7e30
commit f4852f7b90

View File

@ -63,6 +63,9 @@ bool cw::filesys::isDir( const char* dirStr )
errno = 0; errno = 0;
if( dirStr == nullptr )
return false;
if( stat(dirStr,&s) != 0 ) if( stat(dirStr,&s) != 0 )
{ {
// if the dir does not exist // if the dir does not exist
@ -81,6 +84,9 @@ bool cw::filesys::isFile( const char* fnStr )
struct stat s; struct stat s;
errno = 0; errno = 0;
if( fnStr == nullptr )
return false;
if( stat(fnStr,&s) != 0 ) if( stat(fnStr,&s) != 0 )
{ {
@ -101,6 +107,9 @@ bool cw::filesys::isLink( const char* fnStr )
struct stat s; struct stat s;
errno = 0; errno = 0;
if( fnStr == nullptr )
return false;
if( lstat(fnStr,&s) != 0 ) if( lstat(fnStr,&s) != 0 )
{ {
// if the file does not exist // if the file does not exist
@ -314,6 +323,9 @@ char* cw::filesys::expandPath( const char* dir )
memset(&res,0,sizeof(res)); memset(&res,0,sizeof(res));
if( dir == nullptr )
return nullptr;
if((sysRC = wordexp(dir,&res,flags)) != 0) if((sysRC = wordexp(dir,&res,flags)) != 0)
{ {
switch(sysRC) switch(sysRC)