rdos wrote:Using that definition, I feel Posix file handles doesn't qualify.
What is a "Posix file handle"? I don't know if you mean a file descriptor or a FILE*. The latter is not a POSIX invention, it is standard C. They are representative of two very different approaches to handles, but they are still both handles.
rdos wrote:1. You can interrogate them (although, through cludges)
You can not interrogate a file descriptor - to the application it is
just a number. You can only affect the resource it refers to using the interfaces provided by the system.
You are not
intended to interrogate a FILE* - the structure it points to does not have an exposed definition. That it
is just a pointer to a struct in memory does not make it
not a handle.
rdos wrote:2. The owner doesn't provide you with an interface
For a file descriptor, the "system" is the owner, and the interface it provides is the system calls that take file descriptors as arguments (or return them, or use them in other structures).
For a FILE*, the owner is the libc. The interfaces are all of the libc functions that deal with those FILE*s. That this lives in the same memory space as the user of the handles is irrelevant.
rdos wrote:3. Not all functions in the "interface" can operate on all handles (for example, positioning doesn't work on stdin or stout)
That's irrelevant to whether either of these are handles. Handles do not imply any universality of interfaces.
rdos wrote:Additionally, the Posix handle tables & numbers are maintained by the user library, [...]
File descriptor tables are not at all maintained by the "user library", nor are the numbers.
rdos wrote:[...] and due to the presence of dup[...]
dup is purely part of the file descriptor API and does not interact with the FILE API. The libc is not involved in what happens behind the scenes to the file descriptor table when
dup is called. As an example, with glibc on Linux,
dup only calls the
fcntl system call (through a wrapper that sets up some syscall cancellation context that isn't important), examines the result for an error code to set
errno, and otherwise returns the resulting file descriptor. It does not track it in anyway, nor does it have influence over what file descriptor will be returned.
rdos wrote:the library might have its own table that translates between handles and "OS handles" (if the latter exists at all).
On a POSIX system, FILE objects will most definitely have a file descriptor in them somewhere (if they reference a file that works that way - fmemopen is a whole different ordeal), and the FILE APIs will most assuredly involve calling the relevant POSIX APIs using that file descriptor, but that is a one-directional relationship. Generally, FILEs may be stored or tracked in some sort of list (in order to support automatically flushing at exit), but this list
does not represent a table by which a file descriptor may be mapped to a FILE. Further, if you use
fileno to obtain the file descriptor backing a FILE, the FILE APIs are oblivious to things you do "behind its back" with that file descriptor and intermixing the two APIs with the same resource is unspecified.
rdos wrote:It's actually very unclear (and OS dependent) how this stuff is implemented in the C library.
That is the entire point: What the owner of the handle is doing with it to implement the functionality it is exposing to you is none of your business as the user of the handle.