Hi,
i need to reroute both the stdout and stdin streams. I tried the following code.
status = add_device("scia", _MSA, SCI_open, SCI_close, SCI_read, SCI_write, SCI_lseek, SCI_unlink, SCI_rename);
UartOutfp = freopen("scia:in", "r", stdin);
setvbuf(stdin, NULL, _IONBF, 0);
UartInfp = freopen("scia:out", "w", stdout);
setvbuf(stdout, NULL, _IONBF, 0);
I noticed that the second reopen always fails. This is due to the implementation of the function SCI_open from F2837xS_sci_io.c .
The SCI_open function is defined as follows:
int SCI_open(const char * path, unsigned flags, int llv_fd)
{
if(deviceOpen){
return (-1);
}else{
...
deviceOpen = 1;
return (1);
}
Freopen calls SCI_open. So the first call to SCI_open will set deviceOpen to 1 and subsequent calls of the function will return -1. This is why the second call to freopen fails. Is this behavior reasonable?
So do i always return 1 or am i doing something wrong about rerouting the std streams?
Best Regards,
Waldemar Isbrecht