0

Consider a situation where you have a file handle and would like to open a new file handle from it. You might want to do this because you need different access rights, or perhaps you want the two handles to have separate file offsets. You can't simply open the file again from a path because the file in question is unlinked; it's only accessible through the file handle you hold.

What doesn't work (as these only create a new handle to existing file description, i.e. shared file offset):

  1. DuplicateHandle (Win32)
  2. dup
  3. fcntl + F_DUPFD

I have found the following options available on various platforms and would like to know if I am missing any.

Windows

  1. ReOpenFile (since Vista)

Linux

  1. open + /proc/self/fd/

FreeBSD

  1. open + /dev/fd (only if fdescfs was mounted with the "nodup" option)
  2. openat + O_EMPTY_PATH

OS X

  1. Nothing.
2
  • Which programming language are you using? Commented Aug 3 at 7:51
  • It would be the same in any language. If you need to pick one for some reason, then C. Commented Aug 3 at 18:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.