Solved

Easy : different between _open and fopen

Posted on 2002-07-26
3
1,012 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
3 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
fopen is ANSI standard.  _open is nonstandard
0
 
LVL 5

Accepted Solution

by:
nebeker earned 40 total points
Comment Utility
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:Kdo
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops 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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now