home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / programm / 5387 < prev    next >
Encoding:
Internet Message Format  |  1992-11-21  |  1.7 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!ames!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!dsinc!ub!acsu.buffalo.edu!raman-v
  2. From: raman-v@cs.Buffalo.EDU (Vemulapati V. Ramanaprasad)
  3. Newsgroups: comp.unix.programmer
  4. Subject: Re: How to extract file descriptor
  5. Message-ID: <By2z0z.8pp@acsu.buffalo.edu>
  6. Date: 21 Nov 92 19:19:46 GMT
  7. References: <1992Nov21.063524.16930@nuscc.nus.sg>
  8. Sender: nntp@acsu.buffalo.edu
  9. Organization: State University of New York at Buffalo / CEDAR Research Group
  10. Lines: 28
  11. Originator: raman-v@arneb.cs.buffalo.edu
  12. Nntp-Posting-Host: arneb.cs.buffalo.edu
  13.  
  14.  
  15. In article <1992Nov21.063524.16930@nuscc.nus.sg>, isc40038@nusunix1.nus.sg (LIM FANG HOW) writes:
  16. |> I am trying to lock a file which is open using fopen. As what I know,
  17. |> fopen returns a file pointer which points to a structure that contains
  18. |> information about the file.But the flock function only takes a file
  19. |> descriptor and not a file pointer.
  20. |> 
  21. |> Qn1 : Does the structure pointed by file pointer contains the file
  22. |>       descriptor ? I could not find the file descriptor in the stdio.h
  23. |>       in my system (SUN sparc using 4.3BSD)
  24. |> 
  25. |> Qn2 : If yes, how to extract it from the structure ?
  26. |>       I tried the following and it returns fd not defined :
  27. |>               
  28. |>                FILE *fp;
  29. |>                    :
  30. |>                    :
  31. |>                fp=fopen("A","r");
  32. |>                    :
  33. |>                    :
  34. |>                fdes=fp->fd;
  35. |> 
  36. |> Qn3 : Is there any way to lock a file using the file pointer instead of
  37. |>       file descriptor ?
  38. |> 
  39. |>  
  40.  
  41. You can use the function fileno() which takes a file pointer as an argument and returns the file descriptor. See the man page for details.
  42.