open() and fopen()
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > open() and fopen()




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    open() and fopen()  
Jack


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-14-06 06:19 PM

What is the difference betweeb the two functions? Thanks.






[ Post a follow-up to this message ]



    Re: open() and fopen()  
davids@webmaster.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-14-06 06:19 PM


Jack wrote:
> What is the difference betweeb the two functions? Thanks.

I don't know what answer would help you more than just reading the
descriptions of each function. The general idea is that 'fopen' aims to
be a portable C function to open a file whereas 'open' is a portable
POSIX function to open a file. On most POSIX systems, the C stdio
library (and thus 'fopen') is implemented on top of 'open'.

They just come from two different standards.

DS






[ Post a follow-up to this message ]



    Re: open() and fopen()  
Rich Gibbs


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-15-06 12:19 AM

Jack said the following, on 07/14/06 12:39:
> What is the difference betweeb the two functions? Thanks.
>

First, please put your question in the body of your message, not just in
the Subject: header; that ensures everyone can see it.

The two functions Jack refers to are open(2) and fopen(3).

The open(2) function is a Unix/Linux system call that opens (and
possibly creates) a specified file, and associates it with a file
descriptor (a small positive integer).   It is standard in POSIX
environments.

fopen(3) is a function in the standard C library.  It opens a specified
file and associates it with a C stream (referred to by a FILE * object).

There are, of course, similarities between the two functions.  C, of
course, originated in the UNIX environment, and the C standard attempts
to preserve some features of that environment across platforms.  There
is an interesting discussion of the issues involved in P.J. Plauger's
excellent book, _The Standard C Library_.

The man pages have all the details.

--
Rich Gibbs
richg74@gmail.com
"You can observe a lot by watching." -- Yogi Berra







[ Post a follow-up to this message ]



    Re: open() and fopen()  
Hubble


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-15-06 06:21 PM


Jack schrieb:

>open() and fopen()
> What is the difference betweeb the two functions? Thanks.

In short:
open is a system call under Unix/Linux for low level (unbuffered) I/O.
It should be used in conjuction with (the system calls) read, write,
close and uses a file descriptor to indicate an open file. The usage
pattern can be looked up by "man open". It often is

#include <fcntl.h>

int fd;
char * name;
..
fd=open(name, O_RDONLY);
..


fopen is part of the stdio library which implements buffered I/O over
the low level I/O supplied by the operating system. Use it with fread,
fwrite and fclose. fopen yields a file pointer, which should be treated
mostly as an opaque structure, although it (often) contains a file
descriptor which can be obtained in special cases. Use "man fopen"


#include <stdio.h>
FILE * fp;
char * name;

fp=fopen(name,"r");
..

Hubble.






[ Post a follow-up to this message ]



    Re: open() and fopen()  
Jack


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-17-06 06:22 AM


Hubble wrote:
> Jack schrieb:
> 
>
> In short:
> open is a system call under Unix/Linux for low level (unbuffered) I/O.
> It should be used in conjuction with (the system calls) read, write,
> close and uses a file descriptor to indicate an open file. The usage
> pattern can be looked up by "man open". It often is
>
>     #include <fcntl.h>
>
>     int fd;
>     char * name;
>     ...
>     fd=open(name, O_RDONLY);
>     ...
>
>
> fopen is part of the stdio library which implements buffered I/O over
> the low level I/O supplied by the operating system. Use it with fread,
> fwrite and fclose. fopen yields a file pointer, which should be treated
> mostly as an opaque structure, although it (often) contains a file
> descriptor which can be obtained in special cases. Use "man fopen"
>
>
>     #include <stdio.h>
>     FILE * fp;
>     char * name;
>
>     fp=fopen(name,"r");
>     ...
>
> Hubble.

Thanks a lot.

Jack






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:41 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register