Tiny Core Base > Raspberry Pi
Disable blinking cursor in terminal from C program.
Rich:
Hi AlexM
This looks wrong:
--- Code: ---console_fd = open(tty_n, O_RDWR);
if (!console_fd) {
fprintf(stderr,"Could not open console.\n");
exit(1);
}
--- End code ---
According to the man page:
--- Quote ---RETURN VALUE
On success, open(), openat(), and creat() return the new file
descriptor (a nonnegative integer). On error, -1 is returned and
errno is set to indicate the error.
--- End quote ---
Found here:
https://man7.org/linux/man-pages/man2/open.2.html#RETURN_VALUE
Your error test should probably look something like this:
--- Code: ---if (console_fd < 0)
{
printf("Could not open console.\n%s\n", strerror(errno));
exit(1);
}
--- End code ---
By the way, ttyname and ioctl both set errno when they fail if you want
a little more detail in your error messages:
https://man7.org/linux/man-pages/man3/ttyname.3.html#RETURN_VALUE
https://man7.org/linux/man-pages/man2/ioctl.2.html#RETURN_VALUE
AlexM:
--- Quote from: Rich on September 18, 2023, 09:09:36 PM ---This looks wrong:
--- Code: ---console_fd = open(tty_n, O_RDWR);
if (!console_fd) {
fprintf(stderr,"Could not open console.\n");
exit(1);
}
--- End code ---
--- End quote ---
Yes, you are absolutely right. Problem is in permissions and error code checking.
Navigation
[0] Message Index
[*] Previous page
Go to full version