1 /* $NetBSD: ip_send.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
4 * Keith Bostic. All rights reserved.
6 * See the LICENSE file for redistribution information.
11 #include <sys/cdefs.h>
14 static const char sccsid
[] = "Id: ip_send.c,v 8.10 2001/06/25 15:19:25 skimo Exp (Berkeley) Date: 2001/06/25 15:19:25 ";
17 __RCSID("$NetBSD: ip_send.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
20 #include <sys/types.h>
21 #include <sys/queue.h>
23 #include <bitstring.h>
29 #include "../common/common.h"
34 * Construct and send an IP buffer.
36 * PUBLIC: int vi_send __P((int, const char *, IP_BUF *));
39 vi_send(int ofd
, const char *fmt
, IP_BUF
*ipbp
)
50 * Have not created the channel to vi yet? -- RAZ
53 * How is that possible!?!?
55 * We'll soon find out.
58 fprintf(stderr
, "No channel\n");
62 if (blen
== 0 && (bp
= malloc(blen
= 512)) == NULL
)
71 for (; *fmt
!= '\0'; ++fmt
)
73 case '1': /* Value #1. */
74 ilen
= htonl(ipbp
->val1
);
76 case '2': /* Value #2. */
77 ilen
= htonl(ipbp
->val2
);
79 case '3': /* Value #3. */
80 ilen
= htonl(ipbp
->val3
);
81 value
: nlen
+= IPO_INT_LEN
;
83 blen
= blen
* 2 + nlen
;
85 if ((bp
= realloc(bp
, blen
)) == NULL
)
89 memcpy(p
, &ilen
, IPO_INT_LEN
);
92 case 'a': /* String #1. */
93 case 'b': /* String #2. */
94 ilen
= *fmt
== 'a' ? ipbp
->len1
: ipbp
->len2
;
95 nlen
+= IPO_INT_LEN
+ ilen
;
97 blen
= blen
* 2 + nlen
;
99 if ((bp
= realloc(bp
, blen
)) == NULL
)
104 memcpy(p
, &ilen
, IPO_INT_LEN
);
107 memcpy(p
, ipbp
->str1
, ipbp
->len1
);
110 memcpy(p
, ipbp
->str2
, ipbp
->len2
);
115 for (n
= p
- bp
, p
= bp
; n
> 0; n
-= nw
, p
+= nw
)
116 if ((nw
= write(ofd
, p
, n
)) < 0)