<div dir="ltr"><div style>The following C function is a wrapper for the `read' system call.</div><div style>It returns a pair that contains the number of bytes read and the data. </div><div style>Is this the right way to initialize a u8vector from C?</div>
<div style><br></div><div> ___SCMOBJ read_bytes (int fd, size_t count)</div><div> {</div><div> void *data = malloc (count);</div><div> ___SCMOBJ result;</div><div><br></div><div> if (data == NULL)</div><div> result = ___make_pair (___BOOLEAN (0), ___BOOLEAN (0), ___STILL);</div>
<div> else</div><div> {</div><div> int r = read (fd, data, count);</div><div> ___SCMOBJ retcode;</div><div> ___SCMOBJ ___err;</div><div> ___BEGIN_SFUN_INT_TO_SCMOBJ (r, retcode, 1);</div><div>
___END_SFUN_INT_TO_SCMOBJ (r, retcode, 1);</div><div> if (r == 0)</div><div> result = ___make_pair (retcode, ___BOOLEAN (0), ___STILL);</div><div> else if (r > 0)</div><div> {</div><div>
___SCMOBJ data_vect;</div><div> data_vect = ___alloc_scmobj(___sU8VECTOR, count, ___STILL);</div><div> ___EXT (___release_scmobj) (data_vect);</div><div> memcpy (___BODY (data_vect), data, r);</div>
<div> result = ___make_pair (retcode, data_vect, ___STILL);</div><div> }</div><div> else </div><div> result = ___make_pair (retcode, ___BOOLEAN (0), ___STILL);</div><div> free (data);</div>
<div> ___release_scmobj (result);</div><div> }</div><div> return result;</div><div> }</div><div><br></div><div style>Thanks,</div><div style><br></div><div style>--Vijay</div></div>