This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Retarget _sys_open and disable file buffering

I use the FlashFS and therefore, I have a Retarget.c, in which the most _sys_ functions are programmed to wrap the stdio functions to the flash-fs library.

I like to create a virtual file, for which I also wrap the special functionality with the _sys_ functions in Retarget.c. I defined a reserved name for fopen and I assign a special handle in _sys_open to a file opened with that special name.
For this virtual file, I should disable buffering [setbuf(pF, NULL)]. But the problem is, that setbuf uses the FILE *ptr and not the internal handle. And from inside the retarget wrapper functions, I do not know the FILE *ptr.

I could do

FILE *pF = fopen ("VIRTUALFILE", "r");
setbuf (pF, NULL);


but the problem is, that I like to have an abstraction layer, which does not allow to know at level of fopen, whether it is the special file or not. Yes, I could compare the name first and dependent, I do the setbuf(), but that is not the way an abstraction should work... we should be able to do this in _sys_open, but how?

Thanks in advance for your help! - Adrian

0