?
Solved

Easy : different between _open and fopen

Posted on 2002-07-26
3
Medium Priority
?
1,095 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 160 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 46

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Suggested Courses
Course of the Month10 days, 2 hours left to enroll

762 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