Re: SG_BIG_BUFF woes on Linux

Petter Reinholdtsen (pere@hungry.com)
Tue, 26 Jan 1999 12:20:45 +0100 (MET)

[Gerald Turner]
> This function would indeed be nice, but the value is only used once
> to create this structure:
>
> static struct req
> {
> int fd;
> u_int running:1, done:1;
> SANE_Status status;
> size_t *dst_len;
> void *dst;
> struct
> {
> struct sg_header hdr;
> u_int8_t data[SG_BIG_BUFF];
> }
> cdb;
> struct req *next;
> }
>
> My difficulty here is that with my limited C experience, I can't
> think of a good way to change the data element to be dynamic.

If the layout and allocation routines are changed, this could be a
solution. Define this structure:

static struct req
{
int fd;
u_int running:1, done:1;
SANE_Status status;
size_t *dst_len;
void *dst;
struct req *next;
struct {
struct sg_header hdr;
/* Make sure this is the last element, the real size
is SG_BIG_BUFF and machine dependant */
u_int8_t data[1];
} cdb;
}

And allocate it like this:

struct req *current_req = malloc(sizeof(struct req) - 1 + SG_BIG_BUFF);

Then you can use the structure as normal, and the buffer size is
dynamic.

-- 
##>  Petter Reinholdtsen <##    | pere@td.org.uit.no
 O-  <SCRIPT Language="Javascript">window.close()</SCRIPT>
http://www.hungry.com/~pere/    | Go Mozilla, go! Go!

--
Source code, list archive, and docs: http://www.mostang.com/sane/
To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com