Skip to main content
gamedev.net
🔒 Locked

Getting binary input to stdin

Started by Evil Bill Oct 25, 2002 at 8:02 PM 5 replies 450+ views
Original Post
Evil Bill
Evil Bill
Hi, i''m writing a CGI program to uplaod files, and i''m having a bit of difficulty. Since the parameters (including the file) are passed to the CGI program through stdin, stdin contains non-ASCII characters. This causes fread(), fgets(), etc to fail when they start reading non-ASCII characters. Does anyone know how i can get binary input in stdin? I''ve tried freopen("Blah.txt","rb",stdin) which just doesn''t work (not really that supprising) and fdopen(fileno(stdin),"rb") which still doesn''t take non-ASCII characters - it doesn''t seem to work at all with stdin or normal files I know this is the problem because if i put all my data (including the CGI headers) into a file and use that instead of stdin, it works perfectly (if i open the file with "rb"). Obviously this is pointless though, since i need to get the data before i can put it into a file with the CGI headers to get the data from :s Soo... back to the question: How can i get binary input through stdin? Cheers, Steve Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)
Shannon Barber
Shannon Barber
I''m not certain if you''re allowed to do binary IO on stdin.

You could use an octal encoding (e.g. like email attachments).
Send the binary hexidecimal values as text and convert.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Zipster
Zipster
Well, MSDN says that freopen is typically used with stdin, stdout, and stderr, and that freopen accepts the binary translation mode. Not only does it fail to suggest that stdin can''t be "opened" in binary mode, but on the contrary - "The stdin, stdout, and stderr streams always open in text mode by default; you can also override this default when opening any of these files."

However, MSDN is notorious for leaving out small details, so I wouldn''t doubt that it is a restriction.
Evil Bill
Evil Bill
Kylotan: fread has the same problem.
Magmai Kai Holmlor: Yeah, but that would involve the client downloading a program to convert their file, and then uploading the converted file. Geocities doesn''t do this, and its file upload works fine.
Zipster: The MSDN doesn''t say anything about stdin with freopen, but i searched for that quote you gave, and came up with setmode(), and it works perfectly :D:D

Thanks All!

Steve

Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)
Zipster
Zipster
quote:
Original post by Evil Bill
Zipster: The MSDN doesn''t say anything about stdin with freopen, but i searched for that quote you gave, and came up with setmode(), and it works perfectly :D:D

Sure it does! Just below the first table, "freopen is typically used to redirect the pre-opened files stdin, stdout, and stderr to files specified by the user." Hehe, at the bottom of the page is a reference to setmode()
Evil Bill
Evil Bill
Ah yes... so it does. Oops

Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.