Re: file descriptor VS file handle
Hi, i wrote: > > Why there are two sets of file accessing system calls must have historical > > reasons. to...@tuxteam.de wrote: > [...] file descriptor is a > kernel thing, FILE* is libc, i.e. userspace [1] (I know *you* know it, > but it might be interesting for others). Well, at least it did not come to me as explanation why there is FILE *. Have a nice day :) Thomas
Re: file descriptor VS file handle
cor...@free.fr (12023-07-13): > In linux systems, are file descriptor and file handle meaning the same > stuff? File descriptors are the standards Unix file descriptors. In the Unix specification, the word handle is used to designate either a file descriptor or a FILE * pointer of the stdio subsystem of the libc. Regards, -- Nicolas George signature.asc Description: PGP signature
Re: file descriptor VS file handle
On Thu, Jul 13, 2023 at 08:49:38AM +0200, Thomas Schmitt wrote: > Hi, > > cor...@free.fr wrote: > > In linux systems, are file descriptor and file handle meaning the same > > stuff? > > In the programming language C on Linux (more generally: on POSIX systems) > "File descriptor" is an integer number handed out by system calls like > open(2), pipe(2), socket(2), and others. It can be used by calls like > read(2), write(2), recv(2), send(2) to get or to deliver data. > (Execute e.g. >man 2 open > to get the manual page of the desired system call.) Exactly. > I am not aware that "file handle" has such a well defined meaning in > POSIX. To my understanding it just means a programming object that can be > used for similar activities as a file descriptor (and possibly for more > file related activities). In the Unix-ish C world it plainly doesn't exist. It is customary in Perl to designate a data structure wrapping (among other things) a file descriptor, but also buffers and things. Akin to a FILE * in (POSIX-ish) C. > Maybe you mean "file pointer", which usually refers to the return value > "FILE *" of fopen(3) and can be used by calls like fread(3), fscanf(3), > fwrite(3), or fprintf(3). This is implemented on top of file descriptor. > The call fileno(3) can obtain the file descriptor of a file pointer, so > that the above calls of man chapter 2 can be used. > The call fdopen(3) can create a file pointer from a file descriptor. Yep. This is the C "moral equivalent" to a Perl "file handle". I don't know any other context where this is used (but it probably resonates with the Windows folks, for whom "everything is a window handle" since times Windows 3.1 immemorial(. > Why there are two sets of file accessing system calls must have historical > reasons. They were already present in the mid 1980s. But obviously file > descriptor is the more fundamental one. I think they just have different uses. Plus, file descriptor is a kernel thing, FILE* is libc, i.e. userspace [1] (I know *you* know it, but it might be interesting for others). Cheers [1] "God made the integers, all else is the work of man" https://en.wikipedia.org/wiki/Leopold_Kronecker -- t signature.asc Description: PGP signature
Re: file descriptor VS file handle
Hi, cor...@free.fr wrote: > In linux systems, are file descriptor and file handle meaning the same > stuff? In the programming language C on Linux (more generally: on POSIX systems) "File descriptor" is an integer number handed out by system calls like open(2), pipe(2), socket(2), and others. It can be used by calls like read(2), write(2), recv(2), send(2) to get or to deliver data. (Execute e.g. man 2 open to get the manual page of the desired system call.) I am not aware that "file handle" has such a well defined meaning in POSIX. To my understanding it just means a programming object that can be used for similar activities as a file descriptor (and possibly for more file related activities). Maybe you mean "file pointer", which usually refers to the return value "FILE *" of fopen(3) and can be used by calls like fread(3), fscanf(3), fwrite(3), or fprintf(3). This is implemented on top of file descriptor. The call fileno(3) can obtain the file descriptor of a file pointer, so that the above calls of man chapter 2 can be used. The call fdopen(3) can create a file pointer from a file descriptor. Why there are two sets of file accessing system calls must have historical reasons. They were already present in the mid 1980s. But obviously file descriptor is the more fundamental one. A possible motivation to have FILE * is given in https://www.gnu.org/software/libc/manual/html_node/Streams-and-File-Descriptors.html Have a nice day :) Thomas
Re: file descriptor VS file handle
cor...@free.fr wrote: > In linux systems, are file descriptor and file handle meaning the same > stuff? Almost. A file handle is a variable that can hold a file descriptor. You might reuse the file handle to hold a different file descriptor later. -dsr-