Skip to content

Commit

Permalink
Use a local copy of the filename so trailing slashes can be excluded
Browse files Browse the repository at this point in the history
from the stat call while the filename remains unchanged.
  • Loading branch information
kmpeters committed Jul 24, 2024
1 parent 1409a89 commit 0f7987a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions sscanApp/src/saveData_writeXDR.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,23 +719,32 @@ LOCAL int fileStatus(char* fname)
{
struct stat status;
int retVal;

errno = 0;

int len;
char lastChar;

char *fnameLocal;

len = strlen(fname);
lastChar = fname[len-1];

/* Use a local copy of the filename */
fnameLocal = (char *)calloc(len+1, sizeof(char));
strcpy(fnameLocal, fname);

lastChar = fnameLocal[len-1];
if ((lastChar == '/') || (lastChar == '\\'))
{
fname[len-1] = 0;
fnameLocal[len-1] = 0;
}

retVal = stat(fname, &status);
retVal = stat(fnameLocal, &status);
if ((retVal == -1) && (debug_saveData)) {
printf("saveData: stat returned -1 for filename '%s'; errno=%d\n", fname, errno);
printf("saveData: stat returned -1 for filename '%s'; errno=%d\n", fnameLocal, errno);
}

free(fnameLocal);

return retVal;
}

Expand Down

0 comments on commit 0f7987a

Please sign in to comment.