ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtdaemon.C
Revision: 1.16
Committed: Sun May 1 13:54:27 2011 UTC (13 years, 1 month ago) by sf-exg
Content type: text/plain
Branch: MAIN
CVS Tags: rel-9_11, rel-9_12
Changes since 1.15: +0 -1 lines
Log Message:
Fix compilation on systems that do not provide a definition for
PATH_MAX, such as GNU/Hurd.

File Contents

# User Rev Content
1 root 1.13 /*----------------------------------------------------------------------*
2 pcg 1.6 * File: rxvtdaemon.C
3     *----------------------------------------------------------------------*
4     *
5     * All portions of code are copyright by their respective author/s.
6 root 1.15 * Copyright (c) 2003-2007 Marc Lehmann <schmorp@schmorp.de>
7 pcg 1.6 *
8     * This program is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation; either version 2 of the License, or
11     * (at your option) any later version.
12     *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with this program; if not, write to the Free Software
20     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21     *----------------------------------------------------------------------*/
22    
23 pcg 1.1 #include <cstdlib>
24     #include <cstring>
25 pcg 1.4 #include <cstdio>
26 pcg 1.1
27 root 1.7 #include <inttypes.h>
28 pcg 1.3 #include <unistd.h>
29 root 1.9 #include <errno.h>
30     #include <sys/types.h>
31 pcg 1.3 #include <sys/utsname.h>
32    
33 pcg 1.1 #include "rxvtdaemon.h"
34    
35 pcg 1.3 char *rxvt_connection::unix_sockname ()
36 pcg 1.1 {
37 pcg 1.3 char name[PATH_MAX];
38     char *path = getenv ("RXVT_SOCKET");
39    
40     if (!path)
41     {
42     struct utsname u;
43     uname (&u);
44    
45     path = getenv ("HOME");
46 root 1.8 snprintf (name, PATH_MAX, "%s/.rxvt-unicode-%s",
47 pcg 1.3 path ? path : "/tmp",
48     u.nodename);
49    
50     path = name;
51     }
52    
53     return strdup (path);
54 pcg 1.1 }
55    
56     void rxvt_connection::send (const char *data, int len)
57     {
58     uint8_t s[2];
59    
60 root 1.11 if (len > 65535)
61     len = 65535;
62    
63 pcg 1.1 s[0] = len >> 8; s[1] = len;
64    
65     write (fd, s, 2);
66     write (fd, data, len);
67     }
68    
69     void rxvt_connection::send (const char *data)
70     {
71     send (data, strlen (data));
72     }
73    
74 pcg 1.2 bool rxvt_connection::recv (auto_str &data, int *len)
75 pcg 1.1 {
76     uint8_t s[2];
77     int l;
78    
79 root 1.10 if (read (fd, s, 2) != 2)
80 pcg 1.1 return false;
81    
82     l = (s[0] << 8) + s[1];
83 root 1.11 if (l > 65535)
84 pcg 1.1 return false;
85    
86     if (len)
87     *len = l;
88    
89     data = new char[l + 1];
90    
91     if (!data)
92     return false;
93    
94 root 1.10 if (read (fd, data, l) != l)
95 pcg 1.1 return false;
96    
97     data[l] = 0;
98    
99     return true;
100     }
101    
102     void rxvt_connection::send (int data)
103     {
104     uint8_t s[4];
105    
106 pcg 1.5 s[0] = data >> 24; s[1] = data >> 16; s[2] = data >> 8; s[3] = data;
107 pcg 1.1
108     write (fd, s, 4);
109     }
110    
111     bool rxvt_connection::recv (int &data)
112     {
113     uint8_t s[4];
114    
115 root 1.10 if (read (fd, s, 4) != 4)
116 pcg 1.1 return false;
117    
118     data = (((((s[0] << 8) | s[1]) << 8) | s[2]) << 8) | s[3];
119    
120     return true;
121     }
122    
123    
124