Solved

Easy : different between _open and fopen

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
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…
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.

776 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