home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20193 < prev    next >
Encoding:
Text File  |  1993-01-25  |  2.4 KB  |  52 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!pacbell.com!charon.amdahl.com!netcomsv!netcom.com!pdh
  3. From: pdh@netcom.com (Phil Howard )
  4. Subject: Re: How do you read binary data piped into stdin?
  5. Message-ID: <1993Jan26.012308.19664@netcom.com>
  6. Keywords: stdin, redirection, binary data
  7. Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
  8. References: <N0gRXB1w165w@eastwind.mcds.com>
  9. Date: Tue, 26 Jan 1993 01:23:08 GMT
  10. Lines: 40
  11.  
  12. chorn@eastwind.mcds.com (Christopher Horn) writes:
  13.  
  14. >I'm relatively new to C, so still have a lot to learn, so I apologize
  15. >if this is a silly question. I need to read raw binary data from
  16. >stdin (it is being piped in) but it appears stdin operates in text
  17. >mode. The first ascii 26 that comes along triggers end of file, and
  18. >I can't read the rest of the data. Could someone please explain, or
  19. >better yet show me a short peice of code, that could do this? The
  20. >answer is probably obvious, but it eludes me at the moment. Thanks
  21. >a lot!
  22.  
  23. Unfortunately, standard C lacks a facility to change the mode of an open
  24. file.  This would be what you need, and I have had situations where I need
  25. this as well.
  26.  
  27. You could use the system specific I/O facilities, such as for many systems
  28. the POSIX interface.  On UNIX, simply read from file descriptor 0.  Programs
  29. like UNIX uncompress, would be doing this (and not using stdio).
  30.  
  31. Portability?  Like I say, standard C didn't include this capability.
  32. This is one of the cases for something that you just cannot get any
  33. portability.  Maybe the next version of ANSI C?
  34.  
  35. If portability is not the issue for you, and you are working on a finit
  36. set of systems, but you need to use the stdio library, you could investigate
  37. the implementation dependent structure FILE and see what hack you could do
  38. (perhaps changing a flag bit) to change the mode from text to binary.
  39. It might not work on many systems, however.
  40.  
  41.  
  42.  
  43.  
  44. > ---
  45. > Christopher Horn           |  "We're all caught in a state of decay..."
  46. > chorn@eastwind.mcds.com    |  The East Wind  +1 201 875 7063
  47. -- 
  48. /************************************************************************\
  49. | Phil Howard,  pdh@netcom.com,  KA9WGN    Spell protection?  "1(911)A1" |
  50. | "It's not broken... it's just functionally challenged" --Phil and Pete |
  51. \************************************************************************/
  52.