Path: utzoo!attcan!uunet!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: file descriptor vs file handle Message-ID: <4842@goanna.cs.rmit.oz.au> Date: 28 Feb 91 01:23:16 GMT References: <90361.145855COS99291@ufrj.bitnet> <1021@uncw.UUCP> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 52 In article <1021@uncw.UUCP>, session@uncw.UUCP (Zack C. Sessions) writes: > cwong@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 . 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.