I'am actually reading the interoperability tutorial in Erlang C and Erlang: Erlang Port example i want to know how the c program works:
The function read_exact(byte *buf, int len) reads exactly len Bytes from stdin and puts them in buf, but i don't undrestand what read_cmd do
read_cmd(byte *buf)
{
int len;
if (read_exact(buf, 2) != 2)
return(-1);
len = (buf[0] << 8) | buf[1];
return read_exact(buf, len);
}
especially this line
len = (buf[0] << 8) | buf[1];
let's take an example: if we run the program and put 12 in the input 12 is coded in ASCII so buf[0]=0x31 and buf[1]=0x32 then len =0x3132 which is equal 12549 in decimal then we pass len to read_exact, that means that we have to read 12549 bytes. Does that make a sense?