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

open() and fopen()

P: n/a
What is the difference betweeb the two functions? Thanks.

Jul 10 '06 #1
Share this Question
Share on Google+
27 Replies


P: n/a
>What is the difference betweeb the two functions? Thanks.

fopen() exists in standard C. open() does not (unless the
program supplies one).

Gordon L. Burditt
Jul 10 '06 #2

P: n/a
Gordon Burditt <go***********@burditt.orgwrote:
What is the difference betweeb the two functions? Thanks.

fopen() exists in standard C. open() does not (unless the
program supplies one).
I'll also point out that open() is a POSIX function. The set of POSIX C
programming language entry points is not on-topic for this group, but
there are others. For example, it appears that comp.unix.programmer may
be a more appropriate group.

For a first approximation, one reasonable relationship between these two
functions might be that fopen() is implemented in terms of open() on
some system for which open() is available.

--
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
Jul 10 '06 #3

P: n/a
"Jack" <ju******@gmail.comwrote:
# What is the difference betweeb the two functions? Thanks.

fopen is available on any hosted ANSI C system and operates according
to ANSI C. The existence and semantics of open depend on each system.

On Unix, open and related function (such as lseek, read, write) each
results in a transfer across protection boundaries into the kernel
and do not use provide buffering in the user space of the process.
fopen is more portable and generally more efficient. open allows
additional, non-portable operations.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Elvis was an artist. But that didn't stop him from joining the service
in time of war. That's why he is the king, and you're a shmuck.
Jul 10 '06 #4

P: n/a
SM Ryan wrote:
"Jack" <ju******@gmail.comwrote:
# What is the difference betweeb the two functions? Thanks.

fopen is available on any hosted ANSI C system and operates according
to ANSI C. The existence and semantics of open depend on each system.

On Unix, open and related function (such as lseek, read, write) each
results in a transfer across protection boundaries into the kernel
and do not use provide buffering in the user space of the process.
fopen is more portable and generally more efficient. open allows
additional, non-portable operations.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Elvis was an artist. But that didn't stop him from joining the service
in time of war. That's why he is the king, and you're a shmuck.
I like the sig but there was no war when Elvis was in the Army. March
1958 to March 1960. Between wars.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Jul 11 '06 #5

P: n/a
Joe Wright wrote:
SM Ryan wrote:
"Jack" <ju******@gmail.comwrote:
# What is the difference betweeb the two functions? Thanks.

fopen is available on any hosted ANSI C system and operates according
to ANSI C. The existence and semantics of open depend on each system.

On Unix, open and related function (such as lseek, read, write) each
results in a transfer across protection boundaries into the kernel
and do not use provide buffering in the user space of the process.
fopen is more portable and generally more efficient. open allows
additional, non-portable operations.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Elvis was an artist. But that didn't stop him from joining the service
in time of war. That's why he is the king, and you're a shmuck.

I like the sig but there was no war when Elvis was in the Army. March
1958 to March 1960. Between wars.
It's a quote from the move "Dogma", I doubt the writers were concerned
about factual accuracy ;)

Robert Gamble

Jul 11 '06 #6

P: n/a
Joe Wright <jo********@comcast.netwrote:
# SM Ryan wrote:
# "Jack" <ju******@gmail.comwrote:
# # What is the difference betweeb the two functions? Thanks.
# >
# fopen is available on any hosted ANSI C system and operates according
# to ANSI C. The existence and semantics of open depend on each system.
# >
# On Unix, open and related function (such as lseek, read, write) each
# results in a transfer across protection boundaries into the kernel
# and do not use provide buffering in the user space of the process.
# fopen is more portable and generally more efficient. open allows
# additional, non-portable operations.
# >
# --
# SM Ryan http://www.rawbw.com/~wyrmwif/
# Elvis was an artist. But that didn't stop him from joining the service
# in time of war. That's why he is the king, and you're a shmuck.
#
# I like the sig but there was no war when Elvis was in the Army. March
# 1958 to March 1960. Between wars.

The Muse provided Inspiration and not the Facts.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Mention something out of a Charleton Heston movie, and suddenly
everybody's a theology scholar.
Jul 13 '06 #7

P: n/a
fopen = open() + buffer

"Jack" <ju******@gmail.com>
??????:11**********************@75g2000cwc.googleg roups.com...
What is the difference betweeb the two functions? Thanks.

Jul 13 '06 #8

P: n/a
# I like the sig but there was no war when Elvis was in the Army. March
# 1958 to March 1960. Between wars.

Not exactly. The Korean war was never quite settled, there was an
armistice in 1953, but not a full peace agreement. There have been
multilateral meetings every week since then, but no progress. We're
officialy still at war. BTW that was the last war where a president
actually made a declaration of war.

Jul 13 '06 #9

P: n/a
In article <e9**********@news.cn99.com>,
zuoyongping <sh*********@163.comtop-posted:
>"Jack" <ju******@gmail.com>
??????:11**********************@75g2000cwc.google groups.com...
>What is the difference betweeb the two functions? Thanks.
>fopen = open() + buffer
Not on most systems. On systems that follow anything close to
Unix or POSIX, open() accepts a flags field that contain flags
that have functionality not available with fopen() or any other
standard C library call.

Furthermore, some streams will not be buffered by fopen(); and one
can setbuf() the buffer away. Thus, the buffer is not the
essential difference between open() and fopen().
--
Programming is what happens while you're busy making other plans.
Jul 13 '06 #10

P: n/a
zuoyongping wrote:
>
"Jack" <ju******@gmail.com>
??????:11**********************@75g2000cwc.googleg roups.com...
>What is the difference betweeb the two functions? Thanks.
fopen = open() + buffer
Your reply belongs under the text you are replying to (or interspersed
with it) not above.

Also, you are wrong. There are lots of systems on which open does not
exist, a file opened with fopen will not necessarily be buffered, and
there are other differences between at least some implementations of
open and fopen, including open not being topical here.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Jul 13 '06 #11

P: n/a
On 13 Jul 2006 08:12:32 -0700, "Ancient_Hacker" <gr**@comcast.net>
wrote:
># I like the sig but there was no war when Elvis was in the Army. March
# 1958 to March 1960. Between wars.

Not exactly. The Korean war was never quite settled, there was an
armistice in 1953, but not a full peace agreement. There have been
multilateral meetings every week since then, but no progress. We're
officialy still at war.
In fact, bullets still fly across the DMZ on occasion. When I was
there in 62-63, there was some kind of incident about once a month. I
had a field radio sitting up on the shelf with a bullet hole through
it.
BTW that was the last war where a president
actually made a declaration of war.
--
Al Balmer
Sun City, AZ
Jul 13 '06 #12

P: n/a
On Thu, 13 Jul 2006 17:35:26 GMT, Al Balmer <al******@att.netwrote:
>On 13 Jul 2006 08:12:32 -0700, "Ancient_Hacker" <gr**@comcast.net>
wrote:
>># I like the sig but there was no war when Elvis was in the Army. March
# 1958 to March 1960. Between wars.

Not exactly. The Korean war was never quite settled, there was an
armistice in 1953, but not a full peace agreement. There have been
multilateral meetings every week since then, but no progress. We're
officialy still at war.

In fact, bullets still fly across the DMZ on occasion. When I was
there in 62-63, there was some kind of incident about once a month. I
had a field radio sitting up on the shelf with a bullet hole through
it.
>BTW that was the last war where a president
actually made a declaration of war.
My apologies - thought I was still in a.f.c. This is very much
off-topic here.

--
Al Balmer
Sun City, AZ
Jul 13 '06 #13

P: n/a


Ancient_Hacker wrote On 07/13/06 11:12,:
>># I like the sig but there was no war when Elvis was in the Army. March

# 1958 to March 1960. Between wars.

Not exactly. The Korean war was never quite settled, there was an
armistice in 1953, but not a full peace agreement. There have been
multilateral meetings every week since then, but no progress. We're
officialy still at war. BTW that was the last war where a president
actually made a declaration of war.
<off-topic>

That's odd: The power to declare war rests with the
Congress, not with the President. (According to Article I,
Section 8 of a document nobody pays attention to any more.)

</off-topic>

--
Er*********@sun.com

Jul 13 '06 #14

P: n/a
"Ancient_Hacker" <gr**@comcast.netwrites:
># I like the sig but there was no war when Elvis was in the Army. March
# 1958 to March 1960. Between wars.

Not exactly. The Korean war was never quite settled, there was an
armistice in 1953, but not a full peace agreement. There have been
multilateral meetings every week since then, but no progress. We're
officialy still at war. BTW that was the last war where a president
actually made a declaration of war.
This is incorrect, but I'm not going to go into the details here.

Followups redirected.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 13 '06 #15

P: n/a
Eric Sosman <Er*********@sun.comwrites:
Ancient_Hacker wrote On 07/13/06 11:12,:
>>># I like the sig but there was no war when Elvis was in the Army. March

# 1958 to March 1960. Between wars.

Not exactly. The Korean war was never quite settled, there was an
armistice in 1953, but not a full peace agreement. There have been
multilateral meetings every week since then, but no progress. We're
officialy still at war. BTW that was the last war where a president
actually made a declaration of war.

<off-topic>

That's odd: The power to declare war rests with the
Congress, not with the President. (According to Article I,
Section 8 of a document nobody pays attention to any more.)
As long as this is generating a subthread, I'll mention that Congress
has not declared war since 1942.
</off-topic>
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 13 '06 #16

P: n/a
"Chris Smith" <cd*****@twu.netwrote in message
news:MP************************@news.altopia.net.. .
Gordon Burditt <go***********@burditt.orgwrote:
>What is the difference betweeb the two functions? Thanks.

fopen() exists in standard C. open() does not (unless the
program supplies one).

I'll also point out that open() is a POSIX function. The set of POSIX C
programming language entry points is not on-topic for this group, but
there are others. For example, it appears that comp.unix.programmer may
be a more appropriate group.
It may or may not be a POSIX function, depending on the implementation and
possibly compilation options. On the DS9k, open() will open the silo cover
in preparation for an ICBM launch, whereas fopen() will open a file.

S

--
Stephen Sprunk "Stupid people surround themselves with smart
CCIE #3723 people. Smart people surround themselves with
K5SSS smart people who disagree with them." --Aaron Sorkin
--
Posted via a free Usenet account from http://www.teranews.com

Jul 13 '06 #17

P: n/a
Stephen Sprunk <st*****@sprunk.orgwrote:
It may or may not be a POSIX function
No, it is.
, depending on the implementation and
possibly compilation options. On the DS9k, open() will open the silo cover
in preparation for an ICBM launch, whereas fopen() will open a file.
Then the DS9k is not an implementation of POSIX.

--
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
Jul 13 '06 #18

P: n/a
Chris Smith <cd*****@twu.netwrites:
Stephen Sprunk <st*****@sprunk.orgwrote:
>It may or may not be a POSIX function

No, it is.
open() is a POSIX function. But in a non-POSIX environment, there's
nothing stopping you from writing your own function and calling it
"open".
>, depending on the implementation and
possibly compilation options. On the DS9k, open() will open the silo cover
in preparation for an ICBM launch, whereas fopen() will open a file.

Then the DS9k is not an implementation of POSIX.
Clearly it isn't. Did anyone imply that it is?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 13 '06 #19

P: n/a
Keith Thompson wrote:
Chris Smith <cd*****@twu.netwrites:
Stephen Sprunk <st*****@sprunk.orgwrote:
It may or may not be a POSIX function
No, it is.

open() is a POSIX function. But in a non-POSIX environment, there's
nothing stopping you from writing your own function and calling it
"open".
Okay, I understand now. It remains correct to say that open() is a
POSIX function. But, indeed, on non-POSIX platforms, the name is of
course available for other things. Given the context, I'm pretty sure
that POSIX was relevant, and that I pointed Jack to the right newsgroup.
I apologize to the ~0.01% of possible Jacks who may have asked that
question without using a POSIX or POSIX-ish system.

--
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
Jul 14 '06 #20

P: n/a

Eric Sosman wrote:
<off-topic>

That's odd: The power to declare war rests with the
Congress, not with the President. (According to Article I,
Section 8 of a document nobody pays attention to any more.)

</off-topic>
Sorry, I heard that on the radio yesterday and didnt think thru the
impossibility of that.

To be more precise: I think Truman was the last president that
intended to ask Congress for a declaration of war-- but first he
conferred with congressional leaders and they opined it would take a
long time to get a declaration passed, but most of congress was in
favor. So the prez went ahead and committed US troops to that UN
"police action".

I don't think Kennedy, Johnson, Nixon, Bush#1, Bush#2 any of them
intended to ask for a declaration of war. Congress can of course to a
considerable extent control the long-term intensity of the war by
allocating funds accordingly.

All horribly off-topic.

Jul 14 '06 #21

P: n/a
In article <MP************************@news.altopia.net>,
Chris Smith <cd*****@twu.netwrote:
>Okay, I understand now. It remains correct to say that open() is a
POSIX function. But, indeed, on non-POSIX platforms, the name is of
course available for other things. Given the context, I'm pretty sure
that POSIX was relevant, and that I pointed Jack to the right newsgroup.
I apologize to the ~0.01% of possible Jacks who may have asked that
question without using a POSIX or POSIX-ish system.
Far far more than ~0.01%. Windows NT and XP are not POSIX,
and to get POSIX with them, you have to use special tools and
special link libraries... and even then on XP the resulting binary
needs XP Professional because XP Home Edition does not have the
requires subsystem.
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
Jul 14 '06 #22

P: n/a
Walter Roberson wrote...
Chris Smith <cd*****@twu.netwrote:
I apologize to the ~0.01% of possible Jacks who may have asked that
question without using a POSIX or POSIX-ish system.

Far far more than ~0.01%. Windows NT and XP are not POSIX,
and to get POSIX with them, you have to use special tools and
special link libraries... and even then on XP the resulting binary
needs XP Professional because XP Home Edition does not have the
requires subsystem.
And you think it's equally likely that developers on Win32 platforms
will show up on newsgroups asking about the difference between open()
and fopen()? If so, then you are either lying or insane. If not, then
please lay off the phony nonsense. I merely pointed out that it's
practically certain that Jack is looking for a POSIX function, and
pointed him to the right newsgroup to ask about it. There's something
seriously wrong here when that gets this kind of reaction.

--
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
Jul 14 '06 #23

P: n/a
In article <MP************************@news.altopia.net>,
Chris Smith <cd*****@twu.netwrote:
>Walter Roberson wrote...
>Chris Smith <cd*****@twu.netwrote:
>I apologize to the ~0.01% of possible Jacks who may have asked that
question without using a POSIX or POSIX-ish system.
>Far far more than ~0.01%. Windows NT and XP are not POSIX,
>And you think it's equally likely that developers on Win32 platforms
will show up on newsgroups asking about the difference between open()
and fopen()?
No, I think it *more* likely that Win32 developers would do so.
Unix (and Linux) developers, in *my* experience, -tend- more towards
"try to help yourself first and ask about the confusion if necessary".

>If so, then you are either lying or insane. If not, then
please lay off the phony nonsense. I merely pointed out that it's
practically certain that Jack is looking for a POSIX function, and
pointed him to the right newsgroup to ask about it. There's something
seriously wrong here when that gets this kind of reaction.
It is my -belief- that the probability that the OP is using Windows
is at least 40%. That is, to my mind, a sufficiently high probability
that your unqualified reference to POSIX deserved a comment.

If you believe that I am lying, if you believe that I don't
*really* believe the OP might well be using Windows, then I
cannot think at the moment of any way to convince you of the
sincerity of my belief. You could examine large numbers of my
postings and assess whether I'm in the habit of making deliberate
mistatements of truth (okay, so the Flaming Lapdogs posting was
deliberate humour).

If you believe that I am insane, then do you have the medical
credentials to make that assessment? Is there some fact that
I am deliberately or subconciously ignoring? Or are you
merely making a -judgement- of the OP's intention based upon your
assessment of relative -probabilities- -- an assessment that I,
having very likely witnessed a different assortment of postings,
might have come to a conclusion on?

Saying that someone is either "lying or insane" is rather strong
wording, and you should not so post unless you have strong evidence
to support your phrasing. People may be mistaken; people may
not be in full possession of the facts; people may have come to
different conclusions than you would have given the same facts;
people may overlook important details for lack of time, or
due to distraction, or because they do not have the experience or
skills to interpret those facts. But to call someone you barely
know, "lying or insane" is disappointing.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
Jul 14 '06 #24

P: n/a
Walter Roberson wrote:
In article <MP************************@news.altopia.net>,
Chris Smith <cd*****@twu.netwrote:
>Walter Roberson wrote...
>>Chris Smith <cd*****@twu.netwrote:
I apologize to the ~0.01% of possible Jacks who may have asked that
question without using a POSIX or POSIX-ish system.
>>Far far more than ~0.01%. Windows NT and XP are not POSIX,
>And you think it's equally likely that developers on Win32 platforms
will show up on newsgroups asking about the difference between open()
and fopen()?

No, I think it *more* likely that Win32 developers would do so.
Unix (and Linux) developers, in *my* experience, -tend- more towards
"try to help yourself first and ask about the confusion if necessary".
<snip>

In support of Walter, at least some development systems I've used on
Win32 systems *do* have an open function (this is not counting Cygwin).
Whether said open function conforms to the POSIX specification is
another matter.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Jul 14 '06 #25

P: n/a
Walter Roberson said:
In article <MP************************@news.altopia.net>,
Chris Smith <cd*****@twu.netwrote:
<snip>
>
>>If so, then you are either lying or insane. If not, then
please lay off the phony nonsense. I merely pointed out that it's
practically certain that Jack is looking for a POSIX function, and
pointed him to the right newsgroup to ask about it. There's something
seriously wrong here when that gets this kind of reaction.

It is my -belief- that the probability that the OP is using Windows
is at least 40%.
According to his headers, the OP is using Windows for his news access, at
least. Furthermore, ***he had to ask the question***, which is another
strong hint that he's using Windows.

<snip>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 14 '06 #26

P: n/a

In article <MP************************@news.altopia.net>, Chris Smith <cd*****@twu.netwrites:
Walter Roberson wrote...
Chris Smith <cd*****@twu.netwrote:
>I apologize to the ~0.01% of possible Jacks who may have asked that
>question without using a POSIX or POSIX-ish system.
Far far more than ~0.01%. Windows NT and XP are not POSIX,
and to get POSIX with them, you have to use special tools and
special link libraries...
The Windows console subsystem includes an open() library function
(which does not conform to the current POSIX standard; for example,
it does not support O_NOCTTY). See io.h in the Microsoft SDK. The
POSIX subsystem is not required.
And you think it's equally likely that developers on Win32 platforms
will show up on newsgroups asking about the difference between open()
and fopen()?
Since both of those exist on Win32, that seems entirely plausible.
If so, then you are either lying or insane.
Or perhaps simply more knowledgeable than you. That doesn't seem to
be much more difficult than being more courteous.
I merely pointed out that it's
practically certain that Jack is looking for a POSIX function,
It's easy to be certain when you don't know what you're talking about,
true.
There's something
seriously wrong here when that gets this kind of reaction.
There's something wrong here, all right, but it's not Walter or
comp.lang.c.

--
Michael Wojcik mi************@microfocus.com

Writing poetry is an unnatural act. It takes great skill to make it
seem natural. -- Elizabeth Bishop
Jul 16 '06 #27

P: n/a

In article <c6************@news.flash-gordon.me.uk>, Flash Gordon <sp**@flash-gordon.me.ukwrites:
>
In support of Walter, at least some development systems I've used on
Win32 systems *do* have an open function (this is not counting Cygwin).
Such as, for example, all of the ones supplied by Microsoft. In the
SDK, it's prototyped in io.h (only if extensions are enabled, ie
__STD_C__ is not defined).

The Microsoft C implementations actually generate the symbol _open,
or __imp__open, for the function, depending on the linking mode.
Note, though, that "open" is not simply a macro - it's in the regular
identifier namespace, and behaves as a function wrt sequence points,
etc. (All of this is easily demonstrated by generating preprocessed
output and other intermediate output forms.)
Whether said open function conforms to the POSIX specification is
another matter.
It does not.

Really, determining all of this is quite easy, for anyone with a
Windows system and a network connection. That there has been so much
misinformation (and unproductive hostility, from certain quarters)
amply justifies the rule among most clc regulars against answering OT
questions.

If the proponents of providing OT answers cannot get them right, who
here will correct them?

--
Michael Wojcik mi************@microfocus.com

Reversible CA's are -automorphisms- on shift spaces. It is a notorious
fact in symbolic dynamics that describing such things on a shift of finite
type are -fiendishly- difficult. -- Chris Hillman
Jul 16 '06 #28

This discussion thread is closed

Replies have been disabled for this discussion.