By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,301 Members | 3,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,301 IT Pros & Developers. It's quick & easy.

What is the difference between fopen and open in C

P: n/a
Is difference lies in the fact that fopen part of c library and
platform in-depended, whereas open is a system call? what about
functionalities?

thx
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In comp.lang.c, magicman wrote:
Is difference lies in the fact that fopen part of c library and
platform in-depended, whereas open is a system call? what about
functionalities?
With respect to the C standard, fopen() is defined by the standard, takes
specific arguments, performs a specific function, and returns specific
results, while open() is *not* defined (or even recognized) by the
standard. fopen() is guaranteed to be part of the standard I/O library in
a hosted environment, while open() is left available as any sort of user
function.

In /some environments/, open() is an environment-specific function that
provides low-level ("system") access to specific I/O functions. However,
there is no guarantee (from the C language pov) of what open() does, what
arguments it takes or what it returns, and it is perfectly legal for an
application program to include a function called open() with it's own code.

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
Jun 27 '08 #2

P: n/a
magicman wrote:
Is difference lies in the fact that fopen part of c library and
platform in-depended, whereas open is a system call?
Basically yes.
what about functionalities?
Which also unsurprisingly differ. Generally open is more flexible than
fopen. It allows you to specify various status values for the file and
returns error codes, which fopen is not guaranteed to do.

See man 3 open and man 2 open. The actual system call is wrapped by a
user-space function, both with identical names.

To further discuss open <news:comp.unix.programmershould be more
appropriate.

Jun 27 '08 #3

P: n/a
In article <19**********************************@m45g2000hsb. googlegroups.com>,
magicman <ir*********@gmail.comwrote:
>Is difference lies in the fact that fopen part of c library and
platform in-depended, whereas open is a system call? what about
functionalities?
open() is the Unix system call for opening files. The fact that it's
a system call rather than some other kind library function isn't very
important to users; but it corresponds to the fact that in Unix it's
the basic file opening method. Some other operating systems have a
similar function, but as C comes from the world of Unix you probably
mean that one.

fopen() is the standard C function for opening files. A Unix
implementation will use open() in the implementation of fopen(),
but the stream returned by fopen() provides buffering and works
with functions like printf().

Unless you want to take advantage of system-specific features, stick
with fopen().

-- Richard
--
:wq
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.