binary data through stdin
Posted: Thu Mar 22, 2007 12:00 am
I currently have a need to read binary data that is piped in from stdin in Windows (in particular I'm writing some cgi scripts). I've had this need before when running transformations on binary data piped from the command-line.
Unfortunately, since this is Windows, and since stdin is open in text mode, all "\r\n" byte combinations are read as "\n".
Since I couldn't think of any other good solutions to this problem, I tried adding a new primitive function (set-mode). I gave it a shot and it seems to be working well.
Is there any other way around this short of adding a new function to change the mode?
Unfortunately, since this is Windows, and since stdin is open in text mode, all "\r\n" byte combinations are read as "\n".
Since I couldn't think of any other good solutions to this problem, I tried adding a new primitive function (set-mode). I gave it a shot and it seems to be working well.
Code: Select all
#ifdef WINCC
CELL * p_setmode(CELL * params)
{
UINT handle;
UINT mode;
int result;
params = getInteger(params, &handle);
getInteger(params, &mode);
if (mode == 0)
result = setmode( handle, O_TEXT );
else if (mode == 1)
result = setmode( handle, O_BINARY );
else
return(nilCell);
if (result == O_TEXT)
return(stuffInteger(0));
else if (result == O_BINARY)
return(stuffInteger(1));
else
return(nilCell);
}
#endif