Unable to delete directory in Cygwin

Nick Clifton nickc@redhat.com
Thu Jun 22 15:06:00 GMT 2006


Hi Gina,

> While this logic works fine in the linux, the temporary directory does
> not get deleted in cygwin.

Since this appears to be a cygwin specific problem, you really ought to 
post your question on their mailing list.


> /* ldmain.c */
> main()
> {
> my_function();
> delete tmp_directory;//I have to delete the tmp_directory only here 
> }
> 
> /* myfile.c */
> my_function()
> {
> create tmp directory tmp_directory;
> .
> create intermediate files in the above directory; .
> my_process_function(intermediate files);//processes the intermediate
> files .
> return;
> }

Note - for good programming practice you ought to try to keep the 
creation and deletion of the directory in the same function.  ie either 
create and delete it in main() or in my_function() but do not create it 
in a child function and then hope that the parent function will remember 
to delete it.

> After debugging using gdb, I found that in cygwin, the intermediate
> files still had some handlers open for it despite of reaching till 
 > the end of the main() function in linker. Due to this, the temporary
> files get deleted only after exiting from the main. Hence as the 
 > temporary drectory is not empty till then, it cannot get deleted.

This is probably due to a difference in the behaviour of the unlink() 
system call between Linux and Cygwin.  It may well not be a bug though. 
  It may just be that two OS's have different behaviours.

Cheers
   Nick



More information about the Binutils mailing list