Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

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


Report this thread to moderator Post Follow-up to this message
Old Post
Jack
07-14-06 11:59 PM


Re: open() and fopen()
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


Report this thread to moderator Post Follow-up to this message
Old Post
davids@webmaster.com
07-14-06 11:59 PM


Re: open() and fopen()
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



Report this thread to moderator Post Follow-up to this message
Old Post
Rich Gibbs
07-14-06 11:59 PM


Re: open() and fopen()
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.


Report this thread to moderator Post Follow-up to this message
Old Post
Hubble
07-15-06 11:59 PM


Re: open() and fopen()
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


Report this thread to moderator Post Follow-up to this message
Old Post
Jack
07-17-06 12:00 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:22 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.