[BRLTTY] screen driver in brlapi

Dave Mielke Dave at mielke.cc
Mon Nov 5 17:09:36 EST 2018


[quoted lines by Tage Johansson on 2018/11/05 at 22:23 +0100]

>Here's what I've come up with so far:
...
>    uint8_t header[4];
>    fread(header, 0, sizeof(header), vcsa);

This read won't read anything. The second argument to fread() is the size of
each element, so, in this case, it'd need to be something like:
   sizeof(header[0])

>    fd.fd = fileno(vcsa);
>    fd.events = POLLIN;

Although it's probably not necessary (I'm not sure because I code more
cautiously), fd.revents should also be initialized to 0. Even better, in my
opinion, is to exlicitly clear every single field within the structure before
assigning any fields. There are two ways to do this:

The first way:

   memset(&fd, 0, sizeof(fd));
   fd.fd = vcsa;
   fd.events = POLLIN;

The second way (as part of the declaration):

   struct pollfd fd = {
     .fd = vcsa,
     .events = POLLIN
   };

If you just declare a local variable then its contents aren't initialized to
anything specific, so you can effectively think of it as though each field were
initialized to some random value - actually, it's whatever happened to be there
in memory from before. If, however, you include an initializer then all
uninitialized fields are implicitly initialized to 0.

>    for(int i = 0; i < 30; i++) {
>        int ret = poll(&fd, 1, -1);
>        printf("%d ", fd.revents);
>    }

Since you don't take any action within the loop, it's not surprising that each
and every call returns the very same result (since nothing has changed).

You aren't checking for and reporting any errors. My guess is that the open of
/dev/vcsa is failing because that usually requires being root and/or being a
member of the tty group, and you're probably running as neither.

My recommendation is that you check for errors at every step, and, when they
occur, report them. You can use strerror() to turn an errno value into a
printable, meaningful string.

-- 
I believe the Bible to be the very Word of God: http://Mielke.cc/bible/
Dave Mielke            | 2213 Fox Crescent | WebHome: http://Mielke.cc/
EMail: Dave at Mielke.cc  | Ottawa, Ontario   | Twitter: @Dave_Mielke
Phone: +1 613 726 0014 | Canada  K2A 1H7   |


More information about the BRLTTY mailing list