> Date: Mon, 15 Oct 2007 07:58:43 -0400
> From: Earnie Boyd <[EMAIL PROTECTED]>
> 
> 
> Quoting Eli Zaretskii <[EMAIL PROTECTED]>:
> 
> >> Date: Mon, 15 Oct 2007 00:45:47 +0100 (BST)
> >> From: Johannes Schindelin <[EMAIL PROTECTED]>
> >> cc: Alex Riesen <[EMAIL PROTECTED]>, [EMAIL PROTECTED], [EMAIL PROTECTED],
> >>     [EMAIL PROTECTED], make-w32@gnu.org
> >>
> >> The problem is that on Windows, you cannot keep a file open and delete it
> >> at the same time.
> >
> > That is no longer true, for quite some time.  NT4 and later versions
> > support that almost exactly like Posix filesystems.
> >
> 
> You still can't keep a file open and delete it as far as I know.  If 
> you can please share how.

I attach a short toy program that can demonstrate this.  While it
sleeps for 30 seconds, go to another shell window and delete the file
which it has open (either its first command-line arg or "topen.tst" if
no arg was given.  Then try `dir' or `ls' on the removed file, and you
will see that continues to be listed until the program closes the
handle, at which point it is actually removed.

Again, this is a toy program, so please don't pounce on me saying that
it doesn't do anything useful.  Making some practical use out of this
feature is left as an exercise to the interested readers ;-).  See
also FILE_FLAG_DELETE_ON_CLOSE.

(Note that above I said "almost" exactly like Posix, and that's
because a Posix filesystem will not show the file in `ls' after it was
deleted like that, while Windows does.  All the rest is similar.)

----------------------------- cut here ----------------------------
#include <stdio.h>
#include <errno.h>
#include <windows.h>

int
main (int argc, char *argv[])
{
  HANDLE fh = CreateFile (argc > 1 ? argv[1] : "topen.tst",
                          GENERIC_READ,
                          FILE_SHARE_READ | FILE_SHARE_DELETE,
                          NULL, OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL, NULL);

  if (fh != INVALID_HANDLE_VALUE)
    {
      Sleep (30000);
      CloseHandle (fh);
    }
  else
    fprintf (stderr, "%s: cannot open: %lu\n",
         argc > 1 ? argv[1] : "topen.tst", GetLastError ());

  return 0;
}


_______________________________________________
Make-w32 mailing list
Make-w32@gnu.org
http://lists.gnu.org/mailman/listinfo/make-w32

Reply via email to