[sane-devel] Last call for new backends
Tue, 15 Apr 2003 23:32:24 +0200
On Wed, Apr 16, 2003 at 01:56:56AM +1000, Martijn van Oosterhout wrote:
> I guess I wasn't clear. Many of the commands sent to the scanner consist of
> integers (both 2 and 4 byte) and sometimes they are big endian, sometimes
> little endian. So, the code has hton(l|s) in places and not in others.
I have seen that in the code now.
> To solve that we'd have to go through the entire code base checking that the
> right bytes appear in the right places in each structure (maybe do away
> with the structures altogether). That's a bit of work and I'd rather do that
> when I have someone who can actually *test* the result.
Yes, no problem.
> Actually, params.xres = htons( xres ) would probably work fine on most
> architectures. It's the more insidious little accesses that'll trip you up.
I had to use an #ifdef for the __attribute__ (packed) for the
structures so it won't be used on non-gcc compilers. So if there are
alihnment issues on some systems, the struct may nor work even if the
endianess is ok.
In my backends I usually create such buffers manually which is more
ugly but safe:
command = command_byte;
command = (some_value >> 16) & 0xff;
command = (some_value >> 8) & 0xff;
command = (some_value >> 0) & 0xff;