home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.lang.c
- Subject: Re: How to extract file descriptor
- Date: 21 Nov 1992 20:08:17 GMT
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 31
- Message-ID: <1em4vhINNsen@early-bird.think.com>
- References: <1992Nov21.065113.21296@nuscc.nus.sg>
- NNTP-Posting-Host: telecaster.think.com
-
- In article <1992Nov21.065113.21296@nuscc.nus.sg> isc40038@nusunix1.nus.sg (LIM FANG HOW) writes:
- >Qn1 : Does the structure pointed by file pointer contains the file
- > descriptor ? I could not find the file descriptor in the stdio.h
- > in my system (SUN sparc using 4.3BSD)
-
- It's called "_file" in the struct _iobuf. But you don't really need to
- know that, since it's very system-specific.
-
- >Qn2 : If yes, how to extract it from the structure ?
-
- Use the fileno() macro, which takes a FILE*. This should be portable
- across most Unix flavors, and maybe even to some non-Unix systems.
-
- > I tried the following and it returns fd not defined :
- ...
- > fdes=fp->fd;
-
- That should be
-
- fdes=fileno(fp);
-
- >Qn3 : Is there any way to lock a file using the file pointer instead of
- > file descriptor ?
-
- No, locking is not part of stdio. Many systems that can support stdio
- (i.e. just about any system) don't support file locking.
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-