~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to system/doc/tutorial/erl_comm.c

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2010-03-09 17:34:57 UTC
  • mfrom: (10.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100309173457-4yd6hlcb2osfhx31
Tags: 1:13.b.4-dfsg-3
Manpages in section 1 are needed even if only arch-dependent packages are
built. So, re-enabled them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* erl_comm.c */
 
2
 
 
3
typedef unsigned char byte;
 
4
 
 
5
read_cmd(byte *buf)
 
6
{
 
7
  int len;
 
8
 
 
9
  if (read_exact(buf, 2) != 2)
 
10
    return(-1);
 
11
  len = (buf[0] << 8) | buf[1];
 
12
  return read_exact(buf, len);
 
13
}
 
14
 
 
15
write_cmd(byte *buf, int len)
 
16
{
 
17
  byte li;
 
18
 
 
19
  li = (len >> 8) & 0xff;
 
20
  write_exact(&li, 1);
 
21
  
 
22
  li = len & 0xff;
 
23
  write_exact(&li, 1);
 
24
 
 
25
  return write_exact(buf, len);
 
26
}
 
27
 
 
28
read_exact(byte *buf, int len)
 
29
{
 
30
  int i, got=0;
 
31
 
 
32
  do {
 
33
    if ((i = read(0, buf+got, len-got)) <= 0)
 
34
      return(i);
 
35
    got += i;
 
36
  } while (got<len);
 
37
 
 
38
  return(len);
 
39
}
 
40
 
 
41
write_exact(byte *buf, int len)
 
42
{
 
43
  int i, wrote = 0;
 
44
 
 
45
  do {
 
46
    if ((i = write(1, buf+wrote, len-wrote)) <= 0)
 
47
      return (i);
 
48
    wrote += i;
 
49
  } while (wrote<len);
 
50
 
 
51
  return (len);
 
52
}