From my homework:
Backup files are stored in a hidden directory called .mybackup, which
your program creates, if necessary. To create a directory, use the
mkdir() function (click here for details), but be sure to check
whether the directory already exists (using stat() or checking for
EEXIST). If the directory already exists, do not overwrite it.
I thought mkdir inherently returns -1 if the directory already exists. I definitely read that somewhere. Am I mistaken here?
mkdirreturns -1 for any error. So to distinguish between errors, that is, to discover if the directory already exists, you should either use thestatfunction or checkerrnoforEEXISTaftermkdirreturns -1.