Article View: comp.std.c
Article #1793Re: file descriptor
From: Chris Torek
Date: Sat, 06 Oct 1990 04:42
Date: Sat, 06 Oct 1990 04:42
39 lines
2103 bytes
2103 bytes
In article <121948@linus.mitre.org> cazier@mbunix.mitre.org (Cazier) writes:
>How would you legally set a file descriptor to some predetermined value
>as can be done in FORTRAN. For example, I can OPEN(8) or set a value
>IN=8 then OPEN(IN) -- and subsequently WRITE(8) as desired. What's the
>equivalent in C?
I cannot figure out what this question is supposed to mean. The only
reason one might want to write
IN=8
and then eventually
OPEN(IN, ...)
in FORTRAN is because the language's I/O statements require numbers as
arguments and, as a result, people tend to hardcode specific numbers
(such as 5 and 6 for input and output). The C language's I/O functions
supplied as part of any hosted implementation do not take numeric
values, but rather values of type `FILE *'. There are only three
predefined `FILE *' values, namely stdin, stdout, and stderr. Thus,
there are two possible answers:
1. There is no equivalent because the equivalent of write(8) does
not occur. The only `constants' that can be hardcoded into I/O
calls are stdin, stdout, and stderr. A program that opens an
input file does this with code of the form
FILE *f = fopen(...);
if (f == NULL) handle_error_no_such_file();
... do I/O using f, or return f to caller, or whatever ...
2. The equivalent is freopen, which takes a currently-open file,
closes it, opens a new one, and puts all the relevant stuff under
the same `FILE *' value so that I/O operations on that `FILE *'
refer to the new file.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain: chris@cs.umd.edu Path: uunet!mimsy!chris
Technical Details
Message-ID:
<26876@mimsy.umd.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!sdd.hp.com!uakari.primate.wisc.edu!uflorida!haven!mimsy!chrisReferences:
<121948@linus.mitre.org>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!sdd.hp.com!uakari.primate.wisc.edu!uflorida!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.std.c Subject: Re: file descriptor Message-ID: <26876@mimsy.umd.edu> Date: 6 Oct 90 04:42:37 GMT References: <121948@linus.mitre.org> Distribution: usa Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 39