Return value of successful open call - Unix

This is a discussion on Return value of successful open call - Unix ; Return value of successful open call is non negative integer. Thats mean zero can be file descriptor. Is this a special file descriptor or zero can be a file descriptor for a regular file. Can someone highlight on this. Regards, ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Return value of successful open call

  1. Return value of successful open call

    Return value of successful open call is non negative integer. Thats
    mean zero can be file descriptor. Is this a special
    file descriptor or zero can be a file descriptor for a regular file.

    Can someone highlight on this.

    Regards,
    Paresh


  2. Re: Return value of successful open call

    2007-11-05, 09:02(-00), paresh:
    > Return value of successful open call is non negative integer. Thats
    > mean zero can be file descriptor. Is this a special
    > file descriptor or zero can be a file descriptor for a regular file.
    >
    > Can someone highlight on this.

    [...]

    By convention, file descriptors 0, 1 and 2 are used as the
    default fd to read data from, write data to and write error to
    respectively (called stdin, stdout, stderr). Most applications
    assume they are already open when you start them, so that it's
    generally an error condition for them if they are not.
    Applications like getty/xterm/... generally open the 3 of them
    to your terminal and shell redirection operators for instance
    can reassign them to something else. Functions like scanf, gets,
    puts, printf... read from fd 0 and write to fd 1.

    But appart from that, they are like any other fds. So for
    instance a daemon can use them as any other fds (though you'll
    find some tend to open /dev/null on them to avoid side effects
    in case they run other commands).

    --
    Stéphane

  3. Re: Return value of successful open call

    On Nov 5, 3:06 pm, Stephane CHAZELAS wrote:
    > 2007-11-05, 09:02(-00), paresh:> Return value of successful open call is non negative integer. Thats
    > > mean zero can be file descriptor. Is this a special
    > > file descriptor or zero can be a file descriptor for a regular file.

    >
    > > Can someone highlight on this.

    >
    > [...]
    >
    > By convention, file descriptors 0, 1 and 2 are used as the
    > default fd to read data from, write data to and write error to
    > respectively (called stdin, stdout, stderr). Most applications
    > assume they are already open when you start them, so that it's
    > generally an error condition for them if they are not.
    > Applications like getty/xterm/... generally open the 3 of them
    > to your terminal and shell redirection operators for instance
    > can reassign them to something else. Functions like scanf, gets,
    > puts, printf... read from fd 0 and write to fd 1.
    >
    > But appart from that, they are like any other fds. So for
    > instance a daemon can use them as any other fds (though you'll
    > find some tend to open /dev/null on them to avoid side effects
    > in case they run other commands).
    >
    > --
    > Stéphane


    Thanks
    Paresh


+ Reply to Thread