Not compiling copy because of a silly linker problem on the mac

This commit is contained in:
Tee Teoh
2008-06-02 16:43:16 -04:00
commit 91ff5f6a88
5 changed files with 220 additions and 0 deletions

62
priv/erl_comm.c Normal file
View File

@@ -0,0 +1,62 @@
/* erl_comm.c */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "erl_comm.h"
int read_exact(byte *buf, int len);
int write_exact(byte *buf, int len);
int
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);
}
int
write_cmd(byte *buf, int len)
{
byte li;
li = (len >> 8) & 0xff;
write_exact(&li, 1);
li = len & 0xff;
write_exact(&li, 1);
return write_exact(buf, len);
}
int
read_exact(byte *buf, int len)
{
int i, got=0;
do {
if ((i = read(0, buf+got, len-got)) <= 0)
return(i);
got += i;
} while (got<len);
return(len);
}
int
write_exact(byte *buf, int len)
{
int i, wrote = 0;
do {
if ((i = write(1, buf+wrote, len-wrote)) <= 0)
return (i);
wrote += i;
} while (wrote<len);
return (len);
}