Solved

Easy : different between _open and fopen

Posted on 2002-07-26
3
1,029 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
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:Kdo
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

864 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

24 Experts available now in Live!

Get 1:1 Help Now