Pregunta

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.

¿Fue útil?

Solución

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

Remove the semicolon from the first line.

Otros consejos

From Your Post it looks like there could be some problem with the user security or the way directory may not have appropriate authorization for searching. Anyway you can do the quick testing by using 'stat' command and check whether its working or not.

$ stat filename.txt

Yes errno at the time of stat() returning -1 would be helpful to understand why this system call is failing.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top