🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #7917

Re: open vs fopen?

#7917
From: Tanmoy Bhattacharya
Date: Thu, 08 Feb 1996 00:15
46 lines
2533 bytes
In article <4f8qf1$h3b@ssbunews.ih.att.com> bamford@marconi.ih.att.com
(Harold E. Bamford) writes: 
   >In C, why would one use open and DOS int handles rather than fopen and
   >stdio file handles?
   >
   >Is there some speed advantage or differnet functionality?

   open() is for raw I/O.  You use read(), write(), lseek(), ltell()

   fopen() is for buffered I/O.  You can use fread(), fscanf(), fgets(),
   getchar(), putchar, fprint(), fwrite(), fseek(), ftell(), etc.
                       ^^^^^^???

You can specify that fopen etc. should not buffer at the level of the
C library. Whether there are further buffers up or down stream is an
OS issue.

   For certain applications, you can get away without buffering.  But
   often it is easier to do the programming if you don't have to worry
   about unneeded system calls and buffering gives you that.

   Raw I/O is faster if you are, for instance, sucking the entire contents
   of a file into memory at once.

   Buffered I/O tends to automatically include parts of the standard C
   library that you may not need (*printf* stuff).

Why?

   It depends on your goal.  And usually the reasons for using one or the
   other are operating system independent.

And, very importantly, fopen etc. are defined in the C standard, and
hence, code using it is maximally portable. open and its relatives are
are not defined by the C standard. (They are defined by other
standards, but that is a different issue.)

Cheers
Tanmoy
--
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
Technical Details
Message-ID: <TANMOY.96Feb7171553@qcd.lanl.gov>
Path: arc1-ca.pugleaf.net!newshost.lanl.gov!tanmoy
References: <uEYFxc9nX8WX083yn@mbnet.mb.ca> <4f8qf1$h3b@ssbunews.ih.att.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newshost.lanl.gov!tanmoy
From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
Newsgroups: comp.os.msdos.programmer,comp.lang.c
Subject: Re: open vs fopen?
Date: 08 Feb 1996 00:15:53 GMT
Organization: Los Alamos National Laboratory
Distribution: na
Message-ID: <TANMOY.96Feb7171553@qcd.lanl.gov>
References: <uEYFxc9nX8WX083yn@mbnet.mb.ca> <4f8qf1$h3b@ssbunews.ih.att.com>
NNTP-Posting-Host: qcd.lanl.gov
Mime-Version: 1.0
Content-Type: text
In-reply-to: bamford@marconi.ih.att.com's message of 7 Feb 1996 00:06:57 GMT