In Linux command stty
we can set the N characters minimum for a completed read using the option min.
Is there a way to set these options [ min and time] using fcntl() or any C API's.
The stty
command is merely a command that accesses the termios interface (of a serial terminal).
Programmatically you can use tcgetattr() and tcsetattr().
See Setting Terminal Modes Properly
and Serial Programming Guide for POSIX Operating Systems
Sample C code that sets the deciseconds and minimum-count for a raw read of an open serial terminal:
int set_time_and_min(int fd, int time, int min)
{
struct termios settings;
int result;
result = tcgetattr(fd, &settings);
if (result < 0) {
perror("error in tcgetattr");
return -1;
}
settings.c_cc[VTIME] = time;
settings.c_cc[VMIN] = min;
result = tcsetattr(fd, TCSANOW, &settings);
if (result < 0) {
perror("error in tcsetattr");
return -2;
}
return 0;
}
I checked the fcntl() and open() man , but couldn't find a matching flag.
The man page to reference is termios(3).
Of course the VMIN and VTIME values are only effective when using blocking noncanonical I/O. See Linux Blocking vs. non Blocking Serial Read