Question

I have a piece of code which creates a directory from a string, cwd here is a string giving the directory path. Unfortunately there was an error which didn't allow me to create the directory, so I used the perror() and strerror() functions like so, to get the symbolic name of the error.

struct stat st = {0};
if (stat(cwd, &st) == -1) {

    if(mkdir(cwd, 0700)==-1){
        int err=errno;
        perror("MKDIR ERROR");
        printf("%s \n",strerror(err));
    }

}

My problem is that perror() and strerror() give an error saying 'No such file or directory exists'. I looked up the man page of mkdir here, but the said error is not in the list of errors given on the man page. Am I doing something wrong?

Was it helpful?

Solution

but the said error is not in the list of errors given on the man page

It clearly shows ENOENT which is exactly what you are seeing. Most likely one of the components of your path ("ancestors") does not exist.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top