Complex statement

Discussion in 'C Programming' started by seema_coma@yahoo.co.in, Sep 2, 2005.

  1. Guest

    Hi all,

    Can somebody explain what this statement does,
    if ((tempFD = open(tempFileName, O_RDWR | O_CREAT | O_EXCL)) < 0)

    Thanks in advance
    Seema
     
    , Sep 2, 2005
    #1
    1. Advertising

  2. Guest

    wrote:
    > Hi all,
    >
    > Can somebody explain what this statement does,
    > if ((tempFD = open(tempFileName, O_RDWR | O_CREAT | O_EXCL)) < 0)
    >
    > Thanks in advance
    > Seema


    tempFD = open(tempFileName, O_RDWR | O_CREAT | O_EXCL);
    if (tempFD < 0)

    Do "man open" to see open's input parameters and return value.
     
    , Sep 2, 2005
    #2
    1. Advertising

  3. wrote:
    > Hi all,
    >
    > Can somebody explain what this statement does,
    > if ((tempFD = open(tempFileName, O_RDWR | O_CREAT | O_EXCL)) < 0)


    If we knew for sure what version of what library you were using, some
    might. But they shouldn't, since the experts for your platform or
    implementation have newsgroups of their own. Unless your question is
    about C as defined by the standard, no reliable substantive answers from
    comp.lang.c should be expected. In your case, the function open() is
    not defined as part of the standard C libaries (nor are O_RDWR, O_CREAT,
    or O_EXCL). Questions about fopen(), a standard C function, we can
    answer. It is most likely (although definitely not certain) that one of
    the unix programming newsgroups is what you want.
     
    Martin Ambuhl, Sep 2, 2005
    #3
  4. John Bode Guest

    wrote:
    > Hi all,
    >
    > Can somebody explain what this statement does,
    > if ((tempFD = open(tempFileName, O_RDWR | O_CREAT | O_EXCL)) < 0)
    >
    > Thanks in advance
    > Seema


    The open() function itself is not part of the standard C library, but
    part of the Unix (POSIX?) API. Refer to the man page for specifics.
    The above is a shorthand equivalent to the following:

    char *tempFileName = ...; /* some file name */
    int fileAccessMask = 0_RDWR | O_CREAT | O_EXCL;
    int tempFD = open (tempFileName, fileAccessMask);

    if (tempFD < 0)
    {
    /* do something */
    }

    Essentially, the open() call and the test are being squashed into the
    conditional expression.
     
    John Bode, Sep 2, 2005
    #4
  5. tedu Guest

    John Bode wrote:
    > wrote:
    > > Hi all,
    > >
    > > Can somebody explain what this statement does,
    > > if ((tempFD = open(tempFileName, O_RDWR | O_CREAT | O_EXCL)) < 0)
    > >
    > > Thanks in advance
    > > Seema

    >
    > The open() function itself is not part of the standard C library, but
    > part of the Unix (POSIX?) API. Refer to the man page for specifics.
    > The above is a shorthand equivalent to the following:
    >
    > char *tempFileName = ...; /* some file name */
    > int fileAccessMask = 0_RDWR | O_CREAT | O_EXCL;
    > int tempFD = open (tempFileName, fileAccessMask);


    OT, but you should never call open with O_CREAT and no mode.
     
    tedu, Sep 2, 2005
    #5
  6. In article <>,
    John Bode <> wrote:
    >
    > char *tempFileName = ...; /* some file name */
    > int fileAccessMask = 0_RDWR | O_CREAT | O_EXCL;


    gcc says: invalid suffix "_RDWR" on integer constant
     
    Anonymous 7843, Sep 2, 2005
    #6
  7. Guest

    wrote:
    > Can somebody explain what this statement does,
    >if ((tempFD = open(tempFileName, O_RDWR | O_CREAT | O_EXCL)) < 0)


    open() is not a standard C function, it belongs to UNIX.
    if calling open() failed, it will return -1.
    therfore, the expression " (tempFD = open(tempFileName, O_RDWR |
    O_CREAT | O_EXCL)) < 0" is to check whether the call is successful or
    not.
     
    , Sep 3, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.amnet.net.au
    Replies:
    1
    Views:
    585
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=
    Apr 13, 2004
  2. Stanimir Stamenkov
    Replies:
    2
    Views:
    755
    Stanimir Stamenkov
    Oct 25, 2005
  3. Robert Mark Bram
    Replies:
    0
    Views:
    694
    Robert Mark Bram
    Feb 4, 2007
  4. Ankit
    Replies:
    5
    Views:
    950
    GArlington
    Oct 4, 2007
  5. Kottiyath

    How complex is complex?

    Kottiyath, Mar 18, 2009, in forum: Python
    Replies:
    22
    Views:
    771
Loading...

Share This Page