/
ptytest.c
74 lines (74 loc) · 1.75 KB
/
ptytest.c
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
/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) */
#include <stdio.h>
#ifdef HAVE_STDLIB_H
# ifdef HAVE_GETPT
# define _GNU_SOURCE
# endif
# include <stdlib.h>
#endif
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#include <sys/stat.h>
#include <errno.h>
main ()
{
int pty, checkerror;
FILE *a, *f = fopen ("conftestval", "w");
struct stat statbuf;
extern int errno;
if (!f)
exit (1);
/* presume that S_IXOTH is required for people to access devices */
if (stat ("/dev", &statbuf) < 0)
checkerror = 0;
else
checkerror = ((statbuf.st_mode & S_IXOTH) == S_IXOTH) ? 1 : 0;
#if defined(__sgi) || defined(sgi) || defined(__sgi__)
if (stat ("/dev/ptc", &statbuf) >= 0)
# ifdef HAVE__GETPTY
fprintf (f, "SGI4");
# else
fprintf (f, "SGI3");
# endif
else
fprintf (f, "SGI4");
exit (0);
#endif
#ifdef _SCO_DS
if (stat ("/dev/ttyp20", &statbuf) == 0) {
fprintf (f, "SCO");
exit (0);
}
#endif
/* HPUX: before ptmx */
pty = open ("/dev/ptym/clone", O_RDWR);
if (pty >= 0 || (checkerror && errno == EACCES)) {
fprintf (f, "HPUX");
exit (0);
}
#if defined(HAVE_GRANTPT) && defined(HAVE_UNLOCKPT)
# ifdef HAVE_GETPT
pty = getpt ();
if (pty >= 0 || errno == EACCES) {
fprintf (f, "GLIBC");
exit (0);
}
# endif
#ifndef S_IFCHR
#define S_IFCHR 0020000
#endif
if (stat ("/dev/ptmx", &statbuf) >= 0 && ((statbuf.st_mode & S_IFCHR) == S_IFCHR))
if (stat ("/dev/pts/0", &statbuf) >= 0 && ((statbuf.st_mode & S_IFCHR) == S_IFCHR)
&& ((pty = open ("/dev/ptmx", O_RDWR)) >= 0 || (checkerror && errno == EACCES))) {
fprintf (f, "USG");
exit (0);
}
#endif
if (stat ("/dev/ttyp20", &statbuf) == 0) {
fprintf (f, "SCO");
exit (0);
}
fprintf (f, "BSD");
exit (0);
}