Hi Vincent,
This still isn't working because sqFileStdioHandlesIntoFile_WithHandle_IsWritable() doesn't take SQFile by reference (arrays are just pointers to the first element in C, which is why the array of SQFile structures doesn't need to be passed by reference explicitly):
``` sqFileStdioHandlesIntoFile_WithHandle_IsWritable(SQFile *file, HANDLE handle, int isWritable) { file->sessionID = thisSession; file->file = handle; file->writable = isWritable; file->lastOp = 0; /* unused on win32 */ file->isStdioStream = isFileHandleATTY(handle); AddHandleToTable(win32Files, handle); }
sqFileStdioHandlesInto(SQFile files[3]) { sqFileStdioHandlesIntoFile_WithHandle_IsWritable(&files[0], GetStdHandle(STD_INPUT_HANDLE), false); sqFileStdioHandlesIntoFile_WithHandle_IsWritable(&files[1], GetStdHandle(STD_OUTPUT_HANDLE), true); sqFileStdioHandlesIntoFile_WithHandle_IsWritable(&files[2], GetStdHandle(STD_ERROR_HANDLE), true);
return 7; } ```
I think that gets the basic changes you wanted done. But it still leaves stdio in cygwin terminals broken. After a bit more reading it looks like cygwin terminals and Windows ReadConsole() and WriteConsole() functions are fundamentally incompatible.
I don't understand what ReadConsole() and WriteConsole() provide in terms of benefits over FILE* streams, so I can't really comment on the cost of replacing them.
Eliot, what are your thoughts about moving the stdio functionlity to use FILE* streams instead of HANDLE streams?
I think that would allow the VM to use fread(), feof(), and fwrite() to read and write stdio to terminals (cygwin), consoles (windows), pipes and regular files.
Another option may be to leave the existing console functionality and use the connectToFileDescriptor() routine to separately open the stdio streams as FILE* streams. The image can then decide how it wants to interact with stdio.
(we should probably move this conversation to vm-dev and out of this particular PR)
Thanks, Alistair