I am taking a file path from a user. I need to then access that file, and create it if it does not exist. I also need to create any intermediate directories if they don't exist as well.
For example, if my directory looks like:
mydir
|
+---subdir
| |
| +-- FileA
|
+---File1
I might receive mydir/subdir/FileA and would then access the relevant file. However, I might also receive mydir/NewDir/FileB.
How can I do this using Unix system calls in C? I have tried using open() with the (O_RDWR | O_CREAT) flags, but this didn't work out.