File: sendpacket.c

package info (click to toggle)
bcron 0.11-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 752 kB
  • sloc: sh: 3,099; ansic: 2,416; makefile: 28
file content (30 lines) | stat: -rw-r--r-- 550 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bglibs/sysdeps.h>
#include <errno.h>
#include <unistd.h>
#include "bcron.h"

static str packet;

int sendpacket(int fd, const str* s)
{
  const char* ptr;
  long wr;
  long len;
  packet.len = 0;
  if (!str_catu(&packet, s->len)
      || !str_catc(&packet, ':')
      || !str_cat(&packet, s)
      || !str_catc(&packet, ',')) {
    errno = ENOMEM;
    return -1;
  }
  len = packet.len;
  ptr = packet.s;
  while (len > 0) {
    if ((wr = write(fd, ptr, len)) <= 0)
      return wr;
    len -= wr;
    ptr += wr;
  }
  return packet.len;
}