Search code examples
c++clinuxunixstat

stat() function not returning correctly


I have this function

long processFile(char * fileName)
{
    struct stat statBuf;
    mode_t mode;
    int result;
    result = stat(fileName, &statBuf);
    if (result == -1);
        return -1;
    if(S_ISDIR(mode))
        return(processDirectory(fileName));
    else
        return 1;
}

If the "fileName" is an actual file I want it to return one, but if "fileName" is a directory I want it to go to my function called processDirectory. For some reason no matter what I do, the stat() call keeps returning a -1. I have tried hard coding a file name like "test.txt" and a directory called "/test" which both live in the same directory as my executable. Any guidance will be appreciated.


Solution

  • if (result == -1);
        return -1;
    

    Remove the semicolon from the first line.