Should fopen() create missing path components?

Thomas Hoffmann <[email protected]> Fri, 07 Nov 2003 19:15:54 +0100
Newsgroups gmane.comp.ide.emx.devel
Organization private site
Message-ID <[email protected]>
A supposedly simple question, but I did not find a definitive answer in 
any of the documents I looked through: If I give to fopen(fna,"w") a 
file name with path components that do not exist yet: Should fopen() 
silently create all path components, should it fail (as it does on my 
system with errno=ENOENT) or is this up to the implementation?

You can try this snippet: it gives 0 and 2 on my computer in a "clean" 
directory. If I create the dir "d", it prints 0 and 0, of course:

//can fopen() use a filename with a non-existing path?
#include <stdio.h>
#include <errno.h>
FILE *fp;

int main() {

fp=fopen("d2","w");
printf("%i\n",errno);

fp=fopen("d/d2","w");
printf("%i\n",errno);

return 0;
}

-- 
Thomas Hoffmann                                    
[email protected]                                  Dresden, Germany

.sig under construction ...