home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / programm / 3819 < prev    next >
Encoding:
Text File  |  1992-07-20  |  2.0 KB  |  44 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!sun-barr!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!math.fu-berlin.de!fub!geminix.in-berlin.de!gemini
  3. From: gemini@geminix.in-berlin.de (Uwe Doering)
  4. Subject: Re: fdclose function? Or something like it?
  5. References: <1992Jul20.201947.21749@crd.ge.com>
  6. Organization: Private UNIX Site
  7. Date: Tue, 21 Jul 1992 06:54:46 GMT
  8. Message-ID: <JWA5Y3@geminix.in-berlin.de>
  9. Lines: 33
  10.  
  11. volpe@bart.NoSubdomain.NoDomain (Christopher R Volpe) writes:
  12.  
  13. >Folks-
  14. >  I'm looking for advice on the following scenario: 
  15. >
  16. >  My routine is handed a file descriptor opened and managed by some
  17. >calling routine. (The descriptor actually corresponds to a connected
  18. >internet-domain socket, but hopefully that will not be relevant.) In my
  19. >routine, I would like to do some stdio-type operations (e.g. fprintf) on 
  20. >the descriptor, so I open a stream with `stream=fdopen(fd,"w");'. Now,
  21. >before I return to the caller, I want to free up the stream since I no 
  22. >longer need it, and since this routine may be called may times with
  23. >the same descriptor or different descriptors, and I don't want to 
  24. >run out of streams after doing too many fdopens. However, I don't want
  25. >to disturb the underlying descriptor, so I can't do a "fclose(stream)".
  26. >Is there some way to "undo" an fdopen call? Something like an "fdclose"
  27. >call that might close the stream without closing the descriptor? 
  28.  
  29. You could dup() the file descriptor at the beginning of your routine,
  30. then associate this duplicated fd with a stream via fdopen(). At the
  31. end of your routine you can fclose() this stream without closing the
  32. socket connection because the original fd still holds it open. So
  33. after this you can continue to write to the socket from elsewhere
  34. in your program via the original fd that was before passed to your
  35. routine.
  36.  
  37. Hope that helps.
  38.  
  39.       Uwe
  40. -- 
  41. Uwe Doering  |  INET : gemini@geminix.in-berlin.de
  42. Berlin       |----------------------------------------------------------------
  43. Germany      |  UUCP : ...!unido!fub!geminix.in-berlin.de!gemini
  44.