file descriptor vs file handle

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Thu Feb 28 12:23:16 AEST 1991


In article <1021 at uncw.UUCP>, session at uncw.UUCP (Zack C. Sessions) writes:
> cwong at charlie.coyote.trw.com (Chun Wong) writes:
> 
> >Can someone distinguish the differences between a file descriptor and
> >a file handle?  I know that creat returns a file handle whereas fopen
> >returns a file descriptor.  What's the difference?  Are they interchangeable?
> 
> >-C. Wong
> 
> A file handle as you call it is also referred to as a path. It is
> typically an int variable and is used by creat and open and read
> and write and close. (plus others). A File Descriptor is a special
> structure which is specific for your system and defined in your
> stdio.h defs file.

Hoo *boy*!

>From the System V Interface Definition (for real up-to-date definitions
see IEEE 1003.1 and the ANSI C standard)

file-descriptor
	A file-descriptor is a small integer used to identify a file
	for the purposes of doing I/O.  The value of a file-descriptor
	is from 0 to {OPEN_MAX}-1.  An open file-descriptor is obtained
	from a call to the creat(), dup(), fcntl(), open(), or pipe()
	routine.

path-name 
	In a C program, a path-name is a null-terminated character
	string starting with an optional slash, followed by zero or
	more directory-names separated by slashes, optionally followed
	by a file-name.  ...

	(In Common Lisp, MIT Scheme, ZYX Prolog, and some other systems,
	a "path name" is a structure having Host, Device, Directory,
	Name, Type, and Version fields, and the string version is called
	a name-string.)

stdio-stream
	A file with associated stdio buffering is called a stream.
	A stream is [represented by] a pointer to a type FILE defined
	by the header <stdio.h>.

So,
	char *A_Path_Name = "/usr/include/stdio.h";
	int A_File_Descriptor = open(A_Path_Name, O_RDONLY):
	FILE *A_Stdio_Stream = fdopen(A_File_Descriptor, "r");


In short, RTFM.
-- 
The purpose of advertising is to destroy the freedom of the market.



More information about the Comp.lang.c mailing list