What is the difference between fopen and open in C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts

  • Richard Tobin
    Guest replied
    Re: What is the difference between fopen and open in C

    In article <199b3caa-f6fc-4755-bf49-698a6c4aaa16@m4 5g2000hsb.googl egroups.com>,
    magicman <ironsel2000@gm ail.comwrote:
    >Is difference lies in the fact that fopen part of c library and
    >platform in-depended, whereas open is a system call? what about
    >functionalitie s?
    open() is the Unix system call for opening files. The fact that it's
    a system call rather than some other kind library function isn't very
    important to users; but it corresponds to the fact that in Unix it's
    the basic file opening method. Some other operating systems have a
    similar function, but as C comes from the world of Unix you probably
    mean that one.

    fopen() is the standard C function for opening files. A Unix
    implementation will use open() in the implementation of fopen(),
    but the stream returned by fopen() provides buffering and works
    with functions like printf().

    Unless you want to take advantage of system-specific features, stick
    with fopen().

    -- Richard
    --
    :wq

    Leave a comment:


  • santosh
    Guest replied
    Re: What is the difference between fopen and open in C

    magicman wrote:
    Is difference lies in the fact that fopen part of c library and
    platform in-depended, whereas open is a system call?
    Basically yes.
    what about functionalities ?
    Which also unsurprisingly differ. Generally open is more flexible than
    fopen. It allows you to specify various status values for the file and
    returns error codes, which fopen is not guaranteed to do.

    See man 3 open and man 2 open. The actual system call is wrapped by a
    user-space function, both with identical names.

    To further discuss open <news:comp.unix .programmershou ld be more
    appropriate.

    Leave a comment:


  • Lew Pitcher
    Guest replied
    Re: What is the difference between fopen and open in C

    In comp.lang.c, magicman wrote:
    Is difference lies in the fact that fopen part of c library and
    platform in-depended, whereas open is a system call? what about
    functionalities ?
    With respect to the C standard, fopen() is defined by the standard, takes
    specific arguments, performs a specific function, and returns specific
    results, while open() is *not* defined (or even recognized) by the
    standard. fopen() is guaranteed to be part of the standard I/O library in
    a hosted environment, while open() is left available as any sort of user
    function.

    In /some environments/, open() is an environment-specific function that
    provides low-level ("system") access to specific I/O functions. However,
    there is no guarantee (from the C language pov) of what open() does, what
    arguments it takes or what it returns, and it is perfectly legal for an
    application program to include a function called open() with it's own code.

    --
    Lew Pitcher

    Master Codewright & JOAT-in-training | Registered Linux User #112576
    http://pitcher.digitalfreehold.ca/ | GPG public key available by request
    ---------- Slackware - Because I know what I'm doing. ------


    Leave a comment:


  • magicman
    Guest started a topic What is the difference between fopen and open in C

    What is the difference between fopen and open in C

    Is difference lies in the fact that fopen part of c library and
    platform in-depended, whereas open is a system call? what about
    functionalities ?

    thx
Working...