-
Notifications
You must be signed in to change notification settings - Fork 1
/
im-addr.cpp
78 lines (56 loc) · 1.41 KB
/
im-addr.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <pwd.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include "gcin.h"
char *get_gcin_xim_name();
void get_gcin_im_srv_sock_path(char *outstr, int outstrN)
{
char *disp = getenv("DISPLAY");
int my_uid = getuid();
if (!disp || !strcmp(disp, ":0"))
disp = ":0.0";
char tdisp[64];
strcpy(tdisp, disp);
if (!strchr(disp, ':'))
strcat(tdisp, ":0");
if (!strchr(disp, '.'))
strcat(tdisp, ".0");
char my_dir[128];
struct passwd *pw = getpwuid(my_uid);
snprintf(my_dir, sizeof(my_dir), "/tmp/gcin-%s", pw->pw_name);
struct stat st;
if (stat(my_dir, &st) < 0)
mkdir(my_dir, 0700);
else {
if (st.st_uid != my_uid) {
fprintf(stderr, "please check the permision of dir %s\n", my_dir);
return;
}
}
snprintf(outstr,outstrN, "%s/socket-%s-%s", my_dir, tdisp, get_gcin_xim_name());
}
Atom get_gcin_addr_atom(Display *dpy)
{
if (!dpy) {
dbg("dpy is null\n");
return 0;
}
char *xim_name = get_gcin_xim_name();
char tt[128];
snprintf(tt, sizeof(tt), "GCIN_ADDR_ATOM_%s", xim_name);
Atom atom = XInternAtom(dpy, tt, False);
return atom;
}
Atom get_gcin_sockpath_atom(Display *dpy)
{
if (!dpy) {
dbg("dpy is null\n");
return 0;
}
char *xim_name = get_gcin_xim_name();
char tt[128];
snprintf(tt, sizeof(tt), "GCIN_SOCKPATH_ATOM_%s", xim_name);
Atom atom = XInternAtom(dpy, tt, False);
return atom;
}