open() and fopen()

G

Gordon Burditt

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
 
C

Chris Smith

Gordon Burditt said:
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.
 
S

SM Ryan

# 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.
 
J

Joe Wright

SM said:
# 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.

I like the sig but there was no war when Elvis was in the Army. March
1958 to March 1960. Between wars.
 
R

Robert Gamble

Joe said:
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
 
S

SM Ryan

# SM Ryan wrote:
# > # 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.
 
A

Ancient_Hacker

# 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.
 
W

Walter Roberson

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().
 
F

Flash Gordon

> 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.
 
A

Al Balmer

# 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.
 
A

Al Balmer

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.

My apologies - thought I was still in a.f.c. This is very much
off-topic here.
 
E

Eric Sosman

Ancient_Hacker wrote On 07/13/06 11:12,:
# 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>
 
K

Keith Thompson

Ancient_Hacker said:
# 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.
 
K

Keith Thompson

Eric Sosman said:
Ancient_Hacker wrote On 07/13/06 11:12,:

<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.
 
S

Stephen Sprunk

Chris Smith said:
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
 
C

Chris Smith

Stephen Sprunk said:
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.
 
K

Keith Thompson

Chris Smith said:
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".
Then the DS9k is not an implementation of POSIX.

Clearly it isn't. Did anyone imply that it is?
 
C

Chris Smith

Keith said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top