home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- 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
- From: pdh@netcom.com (Phil Howard )
- Subject: Re: How do you read binary data piped into stdin?
- Message-ID: <1993Jan26.012308.19664@netcom.com>
- Keywords: stdin, redirection, binary data
- Organization: Netcom - Online Communication Services (408 241-9760 guest)
- References: <N0gRXB1w165w@eastwind.mcds.com>
- Date: Tue, 26 Jan 1993 01:23:08 GMT
- Lines: 40
-
- chorn@eastwind.mcds.com (Christopher Horn) writes:
-
- >I'm relatively new to C, so still have a lot to learn, so I apologize
- >if this is a silly question. I need to read raw binary data from
- >stdin (it is being piped in) but it appears stdin operates in text
- >mode. The first ascii 26 that comes along triggers end of file, and
- >I can't read the rest of the data. Could someone please explain, or
- >better yet show me a short peice of code, that could do this? The
- >answer is probably obvious, but it eludes me at the moment. Thanks
- >a lot!
-
- Unfortunately, standard C lacks a facility to change the mode of an open
- file. This would be what you need, and I have had situations where I need
- this as well.
-
- You could use the system specific I/O facilities, such as for many systems
- the POSIX interface. On UNIX, simply read from file descriptor 0. Programs
- like UNIX uncompress, would be doing this (and not using stdio).
-
- Portability? Like I say, standard C didn't include this capability.
- This is one of the cases for something that you just cannot get any
- portability. Maybe the next version of ANSI C?
-
- If portability is not the issue for you, and you are working on a finit
- set of systems, but you need to use the stdio library, you could investigate
- the implementation dependent structure FILE and see what hack you could do
- (perhaps changing a flag bit) to change the mode from text to binary.
- It might not work on many systems, however.
-
-
-
-
- > ---
- > Christopher Horn | "We're all caught in a state of decay..."
- > chorn@eastwind.mcds.com | The East Wind +1 201 875 7063
- --
- /************************************************************************\
- | Phil Howard, pdh@netcom.com, KA9WGN Spell protection? "1(911)A1" |
- | "It's not broken... it's just functionally challenged" --Phil and Pete |
- \************************************************************************/
-