File: pty.c

package info (click to toggle)
unison 2.40.102-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,648 kB
  • ctags: 4,884
  • sloc: ml: 29,379; objc: 6,745; ansic: 1,384; makefile: 523; sh: 80
file content (65 lines) | stat: -rw-r--r-- 1,454 bytes parent folder | download | duplicates (5)
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
/* Stub code for controlling terminals on Mac OS X. */

#include <caml/mlvalues.h>
#include <caml/alloc.h>    // alloc_tuple
#include <caml/memory.h>   // Store_field
#include <caml/fail.h>     // failwith
#include <errno.h>         // ENOSYS

extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
extern void uerror (char * cmdname, value arg) Noreturn;

// openpty
#if defined(__linux)
#include <pty.h>
#define HAS_OPENPTY 1
#endif

#if defined(__APPLE__) || defined(__NetBSD__)
#include <util.h>
#define HAS_OPENPTY 1
#endif

#ifdef __FreeBSD__
#include <sys/types.h>
#include <libutil.h>
#define HAS_OPENPTY 1
#endif

#ifdef HAS_OPENPTY

#include <sys/ioctl.h>
#include <sys/types.h>

CAMLprim value setControllingTerminal(value fdVal) {
  int fd = Int_val(fdVal);
  if (ioctl(fd, TIOCSCTTY, (char *) 0) < 0)
    uerror("ioctl", (value) 0);
  return Val_unit;
}

/* c_openpty: unit -> (int * Unix.file_descr) */
CAMLprim value c_openpty() {
  int master,slave;
  value pair;
  if (openpty(&master,&slave,NULL,NULL,NULL) < 0)
    uerror("openpty", (value) 0);
  pair = alloc_tuple(2);
  Store_field(pair,0,Val_int(master));
  Store_field(pair,1,Val_int(slave));
  return pair;
}

#else // not HAS_OPENPTY

#define Nothing ((value) 0)

CAMLprim value setControllingTerminal(value fdVal) {
  unix_error (ENOSYS, "setControllingTerminal", Nothing);
}

CAMLprim value c_openpty() {
  unix_error (ENOSYS, "openpty", Nothing);
}

#endif