-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptycheck.c
81 lines (70 loc) · 1.8 KB
/
ptycheck.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
75
76
77
78
79
80
81
#include <locale.h>
#include <io.h>
#include <stdio.h>
#include <windows.h>
#if _WIN32_WINNT < 0x0600
/* VC 7.1 or earlier doesn't support SAL. */
#if !defined(_MSC_VER) || (_MSC_VER < 1400)
#define __out
#define __in
#define __in_opt
#endif
/* Win32 FileID API Library:
* http://www.microsoft.com/en-us/download/details.aspx?id=22599
* Needed for WinXP. */
#include <fileextd.h>
#endif
#include "iscygpty.h"
const char *get_file_type_name(HANDLE h)
{
int type = GetFileType(h);
switch (type) {
case FILE_TYPE_UNKNOWN:
return "Unknown";
case FILE_TYPE_DISK:
return "Disk";
case FILE_TYPE_CHAR:
return "Char";
case FILE_TYPE_PIPE:
return "Pipe";
}
return "";
}
int main(int argc, char argv[])
{
int istty[3] = {0};
int i;
setlocale(LC_ALL, "");
for (i = 0; i < 3; i++) {
istty[i] = _isatty(i);
}
printf("Is stdin a tty? %s\n", istty[0] ? "yes": "no");
printf("Is stdout a tty? %s\n", istty[1] ? "yes": "no");
printf("Is stderr a tty? %s\n", istty[2] ? "yes": "no");
printf("\n");
for (i = 0; i < 3; i++) {
HANDLE h;
int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * (MAX_PATH - 1);
FILE_NAME_INFO *nameinfo;
const char *type;
h = (HANDLE) _get_osfhandle(i);
nameinfo = malloc(size + sizeof(WCHAR));
if (nameinfo == NULL) {
printf("Not enough memory\n");
exit(1);
}
type = get_file_type_name(h);
if (GetFileInformationByHandleEx(h, FileNameInfo, nameinfo, size)) {
nameinfo->FileName[nameinfo->FileNameLength / sizeof(WCHAR)] = L'\0';
printf("%d (%s): %S, is_cygpty: %d\n", i, type,
nameinfo->FileName, is_cygpty(i));
} else {
printf("%d: GetFileInformationByHandleEx error: %d (%s)\n",
i, GetLastError(), type);
}
free(nameinfo);
}
printf("\n");
printf("Is running on mintty (or other term)? %s\n", is_cygpty_used() ? "yes" : "no");
return 0;
}