-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.c
53 lines (42 loc) · 827 Bytes
/
demo.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
#include "libtush.h"
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#define _XOPEN_SOURCE 600
void cmd_tryme()
{
}
static int fd;
int demo_read(char * buf, int cnt)
{
return read(fd, buf, cnt);
}
int demo_write(char * buf, int cnt)
{
return write(fd, buf, cnt);
}
int main()
{
const struct tush_cmd cmds[] = {
{.cmd = "tryme", .desc = "Try Me", .cmd_fn = cmd_tryme},
{}
};
struct tush_t tush = {
.cmds = cmds,
//.read = demo_read,
//.write = demo_write,
};
tush_init(&tush);
fd = posix_openpt(O_RDWR | O_NOCTTY);
if (grantpt(fd)) {
printf("Error on grant\r\n");
return -1;
}
if (unlockpt(fd)) {
printf("Error on unlock\r\n");
return -2;
}
printf("Open console at %s\r\n", ptsname(fd));
tush_go(&tush, demo_read, demo_write);
return 0;
}