Writing to file and mkdir race conditions C

view story

http://stackoverflow.com – I made a function that tries to create a directory, and then write a simple file: buffer = "Hello world!"; string url = "a/b/c/d/"; string tmp = ""; string done = ""; while((tmp = GetBaseDir(url)).compare("")!=0){ done+=tmp; mkdir(done.c_str(), 0777); } // GetBaseDir returns "a/", and changes url to "b/c/d/" ofstream file; file.open((url+"file.txt").c_str(),ios::trunc); file << buffer; file.close(); As you can see, it only tries, if there is a failure it just keeps going on. I read that 'open' will fail if another process opened that same file with write permissions. But, is (HowTos)