Drop main() prototype. Syncs with NetBSD-8
[minix.git] / external / bsd / tmux / dist / osdep-darwin.c
blobb7e6b8f05689c416faac3a3bb3341189db14a0f8
1 /* Id */
3 /*
4 * Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
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.
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.
19 #include <sys/types.h>
21 #include <event.h>
22 #include <libproc.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
27 char *osdep_get_name(int, char *);
28 char *osdep_get_cwd(int);
29 struct event_base *osdep_event_init(void);
31 #define unused __attribute__ ((unused))
33 char *
34 osdep_get_name(int fd, unused char *tty)
36 struct proc_bsdinfo bsdinfo;
37 pid_t pgrp;
38 int ret;
40 if ((pgrp = tcgetpgrp(fd)) == -1)
41 return (NULL);
43 ret = proc_pidinfo(pgrp, PROC_PIDTBSDINFO, 0,
44 &bsdinfo, sizeof bsdinfo);
45 if (ret == sizeof bsdinfo && *bsdinfo.pbi_comm != '\0')
46 return (strdup(bsdinfo.pbi_comm));
47 return (NULL);
50 char *
51 osdep_get_cwd(int fd)
53 static char wd[PATH_MAX];
54 struct proc_vnodepathinfo pathinfo;
55 pid_t pgrp;
56 int ret;
58 if ((pgrp = tcgetpgrp(fd)) == -1)
59 return (NULL);
61 ret = proc_pidinfo(pgrp, PROC_PIDVNODEPATHINFO, 0,
62 &pathinfo, sizeof pathinfo);
63 if (ret == sizeof pathinfo) {
64 strlcpy(wd, pathinfo.pvi_cdir.vip_path, sizeof wd);
65 return (wd);
67 return (NULL);
70 struct event_base *
71 osdep_event_init(void)
74 * On OS X, kqueue and poll are both completely broken and don't
75 * work on anything except socket file descriptors (yes, really).
77 setenv("EVENT_NOKQUEUE", "1", 1);
78 setenv("EVENT_NOPOLL", "1", 1);
79 return (event_init());