open,fopen differences

B

Blue

Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

Thank you.

Cheers,
Blue :).
 
A

Artie Gold

Blue said:
Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

Thank you.

Cheers,
Blue :).

From a C perspective, the difference is simple: fopen(), fread(),
fwrite(), etc. exist, the rest do not.

If you want to write portable code, use fopen(), etc. [1]

HTH,
--ag

[1] Of course, if you *need* to use whatever platform specific lower
level primitives exist on your platform, by all means do so -- but
further questions about them will be off topic here.
 
B

bigben

Blue said:
Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

Thank you.

Cheers,
Blue :).

From a C perspective, the difference is simple: fopen(), fread(),
fwrite(), etc. exist, the rest do not.

If you want to write portable code, use fopen(), etc. [1]

HTH,
--ag

[1] Of course, if you *need* to use whatever platform specific lower
level primitives exist on your platform, by all means do so -- but
further questions about them will be off topic here.
fopen/fread/fwrite have buffer to fasten I/O process, but open/read/write
dosen't
 
J

Jack Klein

Blue said:
Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

Thank you.

Cheers,
Blue :).

From a C perspective, the difference is simple: fopen(), fread(),
fwrite(), etc. exist, the rest do not.

If you want to write portable code, use fopen(), etc. [1]

HTH,
--ag

[1] Of course, if you *need* to use whatever platform specific lower
level primitives exist on your platform, by all means do so -- but
further questions about them will be off topic here.
fopen/fread/fwrite have buffer to fasten I/O process, but open/read/write
dosen't

Where in the ISO C standard does it state what "open", "read" and
"write" do? Nowhere, because such functions are not even defined.
They do whatever the implementation says they do, and whatever that is
it is not a C matter.

What if the "open" function on some platform popped out the tray on
the CD drive? What in the C standard prohibits it?
 
B

Blue

in the au jus.



Bisque à l?Enfant

Honor the memory of Grandma with this dish by utilizing her good
silver soup tureen and her great grandchildren (crawfish, crab or
lobster will work just as well, however this dish is classically
made with crawfish).

Stuffed infant heads, stuffed crawfish heads, stuffed crab or lobster shells;
make patties if shell or head is not available
(such as with packaged crawfish, crab, or headless baby).
Flour
oil
onions
bell peppers
garlic salt, pepper, etc.
3 cups chicken stock
2 sticks butter
3 tablespoons oil

First stuff the heads, or make the patties (see index)
then fry or bake.
Set aside to drain on paper towels.
Make a roux with butter, oil and flour,
brown vegetables in the roux, then add chicken stock and
allow to simmer for 20 minutes.
Add the patties or stuffed heads, and some loose crawfish,
lobster, long piglet, or what have you.
Cook on low for 15 minutes, then allow it to set for at least
15 minutes more.
Serve over steamed rice; this dish is very impressive!



Stuffed Cabbage Rolls

Babies really can be found under a cabbage leaf -
or one can arrange for ground beef to be found there instead.

8 large cabbage leaves
1 lb. lean ground newborn human filets, or ground chuck
Onions
peppers
celery
garlic
soy sauce
salt pepper, etc
Olive oil
breadcrumbs
Tomato Gravy (see index)

Boil the cabbage leaves for 2 minut
 
M

Michael Mair

Blue said:
Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

fopen/fclose/fread/fwrite are C standard library functions.

open/close/read/write _may_ be functions provided by your operating
systems or come from somewhere else -- or they might not be there
at all; they are not standard C.

If you want your programs to be portable or as portable as possible,
restrict yourself to the standard library (whenever possible).

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

It is possible that internally fopen() & Co. use open() and
friends if available.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

If you want file access functions and the standard library functions
are sufficient for your purposes, then use them. Only if the other
functions provide something you cannot get using the standard library,
use the other functions.


Cheers
Michael
 
G

Gordon Burditt

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

fopen(), fread(), and fwrite() are present in ANSI C. open(),
read(), and write() are not, but they are present in POSIX.
I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

On a particular implementation, this may be correct. In general,
the line between "system calls" and "library functions" is fuzzy
at best and meaningless at worst.
May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

Parse sense no.
But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

ANSI C is more portable than POSIX. DO NOT try to mix the two sets.
The representation of an "open file handle" or whatever you call
it is very different between open() and fopen().

Gordon L. Burditt
 
C

CBFalconer

Blue said:
Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

No you don't. You know that fopen, fread, fwrite, fclose are
available because the standard says they must be. You KNOW
absolutely nothing about open, read, write, because the standard
says nothing about them. They may be present on some systems, in
some form or other, but that has nothing to do with the C
language. You would be well advised to ignore them unless forced
into building some non-portable non-standard peculiar software.

Because open, read, write etc. are non-standard, they are off-topic
here. They may well be topical on a newsgroup dedicated to your
particular system.
 
D

Douglas A. Gwyn

Blue said:
But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

open() is not standard and might not be implemented in
some standard-conforming hosted environments, whereas
fopen() is standard and is implemented in all standard-
conforming hosted environments. Therefore for
portability, use the standard functions, not (emulated)
Unix system service calls.

There are other functional differences, the most
notable being that the stdio stream uses a buffer in
"user space", whereas the direct system-call I/O does
not. (There might or might not be kernel-space
buffers in both cases.) This can matter if record
length is important; for example, if you want to write
a magnetic tape record of length 80, write(fd,buf,80)
will do that, whereas fwrite(buf,80,1,fp) will likely
just put the data in a user-space buffer, with the
actual write occurring eventually when the buffer is
full - which will result in something like a 512-byte
magtape record. You could perhaps work around that by
issuing a fflush(fp) after the fwrite(), but it's a
kludgy way to accomplish what write() does directly.
 
J

Jonathan Leffler

Blue said:
Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

(a) fopen() et al are standardized in the C standard; open() et al are
standardized by POSIX. There are more standard C platforms than POSIX
platforms, so fopen() et al are more portable (if used carefully).

(b) fopen() et al deal with FILE * whereas open() et al use an integer.

(c) typically, open() in some variation is used by fopen() - the reason
for 'some variation' being that you are permitted (in standard C) to
write your own function called open() and the fopen() is not allowed to
call it instead of the system function.

(d) There are options that can be specified to open() that cannot be
specified to fopen(). If you need specialized control over the device,
you probably need to use open(). That said, you are immediately
limiting the portability of your application - because you require those
special semantics.

(e) Guideline: use fopen() et al until you find you can't do something.
Then work out how you can do it after all. Only if you really, really,
really can't do it, then drop into using open() etc.
 
C

Charles Mills

Blue said:
Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

open, ... are part of POSIX. fopen, ... are part of the standard
libarary.
I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

Not sure what your saying is totally correct. This is discussed in
"The Standard C Library" by Plauger. It is probably worth your time to
read the section on stdio if you haven't already.
But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

Generally you should use fopen and friends because they are part of the
standard library. Also for most situations they will be faster. If
you are writing large amounts of data (multiple pages at a time) you
may want to consider using open and friends (but fread and fwrite do
fine in this case too).

-Charlie
 
H

Hans-Bernhard Broeker

In comp.lang.c.moderated Blue said:
Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

The first element in each pair is a system-specific, non-portable
thing, the other is a properly standardized function of well-defined
behaviour.
But what difference does it makes from an application programmer
perspective?

The 'f' varieties allow you to write portable program's. What a
function called 'open()' might do on some random computer platform is
anyone's guess.
 
E

E. Rosten

Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

Well, you've pretty much covered it. open/read/close are POSIX system
calls, and are not portable to non POSIX systems, unlike f* ones. On unix
systems, open/read/write will be used internally, since there are the
operating system primitives for accessing files. Further, f* functions
provide buffering and formatted I/O, which the primitive calls do not do.

If you want portable C, use f* functions. If you need to access unix
functionality, like ioctl, mmap, tty mangling, etc, then you probably want
to use the unix primitives instead.

Also, some C libraries (I don'e believe this is standard, but I don't know
for sure), such as the GNU C one allow you to create custom FILE streams,
so you can read from things not natively represented by files on the
system (for instance, blocks of memory), which is a very, nice flexible
way of doing things.

-Ed

--
(You can't go wrong with psycho-rats.) (er258)(@)(eng.cam)(.ac.uk)

/d{def}def/f{/Times findfont s scalefont setfont}d/s{10}d/r{roll}d f 5/m
{moveto}d -1 r 230 350 m 0 1 179{1 index show 88 rotate 4 mul 0 rmoveto}
for /s 15 d f pop 240 420 m 0 1 3 { 4 2 1 r sub -1 r show } for showpage
 
J

Jonathan Bartlett

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

Other way around -- fopen calls open, fread calls read, etc.
But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

Application programmers normally don't need open and read, etc. Using
open and read gets you into system development issues, like restarting
system calls, buffered input/output, and all of that fun. The "f" class
functions take all of the dirty work away, while the other ones deal
directly with the operating system and all its ugliness.

You also have many more functions available with the "f" functions,
while with the open/read/write, that's pretty much all you get.

Jon
 

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,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top