SDL
SDL copied to clipboard
SDL_Process stdin errors with SDL_FlushIO
I'm opening this issue because I'm not sure if there's a particular reason to work that way, but I noticed I can't flush a process input pipe.
#include <SDL3/SDL.h>
int main(void)
{
const char *args[] = { "cat", NULL };
char buf[16] = { '\0' };
SDL_Init(0);
SDL_Process *proc = SDL_CreateProcess(args, true);
SDL_IOStream *in = SDL_GetProcessInput(proc);
SDL_IOStream *out = SDL_GetProcessOutput(proc);
SDL_WriteIO(in, "ab", 2);
bool success = SDL_FlushIO(in); // <-- Here
SDL_Log("Success: %d\n", success);
SDL_Log("%s\n", SDL_GetError());
SDL_Delay(10); // Give the child process some time to pass its stdin to stdout
SDL_ReadIO(out, buf, sizeof(buf));
SDL_Log("'%s'\n", buf);
SDL_KillProcess(proc, false);
SDL_WaitProcess(proc, true, NULL);
SDL_DestroyProcess(proc);
SDL_Quit();
return 0;
}
Output:
Success: 0
Error flushing datastream: Invalid argument
'ab'
Writing to the child process' input seems to automatically flush, so the call to SDL_FlushIO doesn't seem to be necessary. However, would it be better to make that function a successful no-op instead?