Annotation of src/usr.bin/tmux/client-fn.c, Revision 1.3
1.3 ! nicm 1: /* $OpenBSD: client-fn.c,v 1.2 2009/07/26 12:58:44 nicm Exp $ */
1.1 nicm 2:
3: /*
4: * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15: * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16: * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
18:
19: #include <sys/types.h>
20:
21: #include <stdlib.h>
22: #include <string.h>
23:
24: #include "tmux.h"
25:
26: void
27: client_fill_session(struct msg_command_data *data)
28: {
29: char *env, *ptr1, *ptr2, buf[256];
30: size_t len;
31: const char *errstr;
32: long long ll;
33:
34: data->pid = -1;
35: if ((env = getenv("TMUX")) == NULL)
36: return;
37:
38: if ((ptr2 = strrchr(env, ',')) == NULL || ptr2 == env)
39: return;
40: for (ptr1 = ptr2 - 1; ptr1 > env && *ptr1 != ','; ptr1--)
41: ;
42: if (*ptr1 != ',')
43: return;
44: ptr1++;
45: ptr2++;
46:
47: len = ptr2 - ptr1 - 1;
48: if (len > (sizeof buf) - 1)
49: return;
50: memcpy(buf, ptr1, len);
51: buf[len] = '\0';
52:
53: ll = strtonum(buf, 0, LONG_MAX, &errstr);
54: if (errstr != NULL)
55: return;
56: data->pid = ll;
57:
58: ll = strtonum(ptr2, 0, UINT_MAX, &errstr);
59: if (errstr != NULL)
60: return;
61: data->idx = ll;
62: }
63:
64: void
65: client_write_server(
1.3 ! nicm 66: struct client_ctx *cctx, enum msgtype type, void *buf, size_t len)
1.1 nicm 67: {
68: struct hdr hdr;
69:
70: hdr.type = type;
71: hdr.size = len;
72: buffer_write(cctx->srv_out, &hdr, sizeof hdr);
73:
74: if (buf != NULL && len > 0)
75: buffer_write(cctx->srv_out, buf, len);
76: }