home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!swrinde!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!usenet-feed.umr.edu!mcastle
- From: mcastle@cs.umr.edu (Michael R Castle)
- Subject: Re: How do you read binary data piped into stdin?
- References: <N0gRXB1w165w@eastwind.mcds.com>
- Date: Tue, 26 Jan 1993 17:38:17 GMT
- Nntp-Posting-Host: next9.cs.umr.edu
- Organization: University of Missouri - Rolla, Rolla, MO
- Keywords: stdin, redirection, binary data
- Sender: cnews@umr.edu (UMR Usenet News Post)
- Message-ID: <1993Jan26.173817.1397@umr.edu>
- Lines: 48
-
- In article <N0gRXB1w165w@eastwind.mcds.com> chorn@eastwind.mcds.com 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!
-
- After reading the followups for this article, I'm surprised no one has
- asked the obvious "What system are you on?"
-
- The only system I've come across where ascii 26 is special is MS-DOS
- (well, ok, OS/2 as well).
-
- If it is ms-dos, please specify. Knowing what system you are using
- (especially for very system dependent things such as file i/o), helps
- tremendously in helping solve the problem.
-
- Anyway, if it IS really ms-dos, the following will work for turbo-c
- and djgpp (gcc/g++ ported to dos). I believe it will work with ms-c
- as well, but not sure.
-
- #include <fnctl.h>
-
- setmode(fileno(stdin),O_BINARY);
-
- This will change stdin (or any open file) to binary mode.
-
- You can use this to change back and forth between binary/text mode if you
- so wish.
-
- Btw, when trying to help a friend port pbmplus to os/2, this solution
- did NOT work because setmode() would not affect a stream (ie, stdin,
- stdout, i guess anything opened with fopen()). T'was more than a bit
- annoying (oh, with ibm c-set/2).
-
- hope this helps.
-
- regards,
- mrc
- --
- Mike Castle .-=NEXUS=-. Life is like a clock: You can work constantly
- mcastle@cs.umr.edu and be right all the time, or not work at all
- S087891@UMRVMA.UMR.EDU and be right at least twice a day. -- mrc
- We are all of us living in the shadow of Manhattan. -- Watchmen
-