- if ( access ( fn, F_OK ) == 0 )
- {
- return -3;
- } else {
- if ( errno == ENOENT)
- {
- char *tmp = g_strdup ( fn );
-#ifdef WINDOWS
- mkdir( dirname ( dirname ( tmp ) ) );
- g_free ( tmp ); tmp = g_strdup ( fn );
- mkdir( dirname ( tmp ) );
-#else
- mkdir( dirname ( dirname ( tmp ) ), 0777 );
- g_free ( tmp ); tmp = g_strdup ( fn );
- mkdir( dirname ( tmp ), 0777 );
-#endif
- g_free ( tmp );
- }
- if ( ! (f = fopen ( fn, "w+b" )) ) /* immediately open file so other threads won't -- prevents race condition */
- return -4;
- }