You have two choices:
Use fileno()
to obtain the file descriptor associated with the stdio
stream pointer
Don't use <stdio.h>
at all, that way you don't need to worry about flush either - all writes will go to the device immediately, and for character devices the write()
call won't even return until the lower-level IO has completed (in theory).
For device-level IO I'd say it's pretty unusual to use stdio
. I'd strongly recommend using the lower-level open()
, read()
and write()
functions instead (based on your later reply):
int fd = open("/dev/i2c", O_RDWR);
ioctl(fd, IOCTL_COMMAND, args);
write(fd, buf, length);