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