Code Comments
Programming Forum and web based access to our favorite programming groups.What is the difference betweeb the two functions? Thanks.
Post Follow-up to this messageJack 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 Follow-up to this messageJack 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 Follow-up to this messageJack 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 Follow-up to this messageHubble 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 Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.