textmessage_put.c (526B)
1 /* ISC license. */ 2 3 #include <sys/uio.h> 4 #include <errno.h> 5 #include <stdint.h> 6 #include <skalibs/uint32.h> 7 #include <skalibs/bufalloc.h> 8 #include <skalibs/textmessage.h> 9 10 int textmessage_put (textmessage_sender *ts, char const *s, size_t len) 11 { 12 char pack[4] ; 13 struct iovec v[2] = 14 { 15 { .iov_base = pack, .iov_len = 4 }, 16 { .iov_base = (char *)s, .iov_len = len } 17 } ; 18 if (len > TEXTMESSAGE_MAXLEN) return (errno = EINVAL, 0) ; 19 uint32_pack_big(pack, (uint32_t)len) ; 20 return bufalloc_putv(&ts->out, v, 2) ; 21 }