- 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 */
+ gchar *dir = g_path_get_dirname ( fn );
+ g_mkdir_with_parents ( dir , 0777 );
+ g_free ( dir );
+
+ /* create placeholder file */
+ if ( ! (f = g_fopen ( fn, "w+b" )) ) /* immediately open file so other threads won't -- prevents race condition */