Solved

Easy : different between _open and fopen

Posted on 2002-07-26
3
1,081 Views
Last Modified: 2012-06-22
To open the file
why "_open" have underscore at the front?
Izzit means it is a lower level system call?
Whats the different between _open and fopen?
0
Comment
Question by:cialat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 7181625
fopen is ANSI standard.  _open is nonstandard
0
 
LVL 5

Accepted Solution

by:
nebeker earned 40 total points
ID: 7184077
On some systems, "_open" is called "open".  I believe that both of them adhere to the POSIX spec.

The first difference is that fopen returns a FILE *, and the open (or _open) returns an integer (file descriptor).  

The second is that they each have their own set of functions that work with them:

fopen:  uses fclose, fread, fwrite, fseek, etc.
open:  uses close, read, write, seek, etc.

As ozo mentioned, fopen is ANSI standard, so it is going to be named "fopen" on all platforms.  You can also "open" -- just keep in mind that it will be "open" on some platforms and "_open" on others...

As a personal rule, I tend to use "open" when I'm reading blocks of raw data from a file, and "fopen" when I want to deal with strings.  For example, you can use fprintf (to write) and fscanf (to read) formatted text to/from a file.  You won't be able to do this if the file is opened with "open" or "_open".  On the other hand, if I have a program that is grabbing files from a directory and pushing them out through a socket (i.e. reading the data without interpreting it), then I'll use the "open" call....

In the end, it doesn't really make much of a difference :)
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 9480660
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:
Accept nebeker's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Kent (Kdo)
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question