File * to fd

From: Kamal R. Prasad (kamalp_at_acm.org)
Date: 12/23/04

  • Next message: Kamal R. Prasad: "mutex-locks"
    Date: 23 Dec 2004 10:10:43 -0800
    
    

    From: termbios (meson@techemail.com)
    Subject: File * to fd
     
    View this article only
    Newsgroups: comp.unix.programmer
    Date: 2004-12-22 15:24:08 PST

    >I get a FILE * pointer by calling popen. Now I want to change it into
    a
    >file descriptor. Is there a function call for it? Like fdopen create
    a
    >FILE* out of a file descriptor.

    FILE (struct __sFILE) has a member
    short _file; /* fileno, if Unix descriptor, else -1 */

    so, you just need to access (assuming your FILE* is fp) fp->_file to
    access the related file descriptor. Im not aware if the member varies
    across implementations -but if it doesn't, you save yourself a
    function call by accessing the member directly.

    regards
    -kamal


  • Next message: Kamal R. Prasad: "mutex-locks"
  • Quantcast