summaryrefslogtreecommitdiff
path: root/klibc/include/termios.h
blob: 08a5e56855e17e551df0998a97e35c7d5a890eeb (plain)
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
82
83
84
85
86
/*
 * termios.h
 */

#ifndef _TERMIOS_H
#define _TERMIOS_H

#include <klibc/extern.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <linux/termios.h>

/* Redefine these so the magic constants == the ioctl number to use. */
#undef TCSANOW
#undef TCSADRAIN
#undef TCSAFLUSH
#define TCSANOW	   TCSETS
#define TCSADRAIN  TCSETSW
#define TCSAFLUSH  TCSETSF

static __inline__ int tcgetattr(int __fd, struct termios *__s)
{
  return ioctl(__fd, TCGETS, __s);
}

static __inline__ int tcsetattr(int __fd, int __opt, const struct termios *__s)
{
  return ioctl(__fd, __opt, (void *)__s);
}

static __inline__ int tcflow(int __fd, int __action)
{
  return ioctl(__fd, TCXONC, (void *)(intptr_t)__action);
}

static __inline__ int tcflush(int __fd, int __queue)
{
  return ioctl(__fd, TCFLSH, (void *)(intptr_t)__queue);
}

static __inline__ pid_t tcgetpgrp(int __fd)
{
  pid_t __p;
  return ioctl(__fd, TIOCGPGRP, &__p) ? (pid_t)-1 : __p;
}

static __inline__ pid_t tcgetsid(int __fd)
{
  pid_t __p;
  return ioctl(__fd, TIOCGSID, &__p) ? (pid_t)-1 : __p;
}  

static __inline__ int tcsendbreak(int __fd, int __duration)
{
  return ioctl(__fd, TCSBRKP, (void *)(uintptr_t)__duration);
}

static __inline__ int tcsetpgrp(int __fd, pid_t __p)
{
  return ioctl(__fd, TIOCSPGRP, &__p);
}

static __inline__ speed_t cfgetospeed(const struct termios *__s)
{
  return (speed_t)(__s->c_cflag & CBAUD);
}

static __inline__ speed_t cfgetispeed(const struct termios *__s)
{
  return (speed_t)(__s->c_cflag & CBAUD);
}

static __inline__ int cfsetospeed(struct termios *__s, speed_t __v)
{
  __s->c_cflag = (__s->c_cflag & ~CBAUD) | (__v & CBAUD);
  return 0;
}

static __inline__ int cfsetispeed(struct termios *__s, speed_t __v)
{
  __s->c_cflag = (__s->c_cflag & ~CBAUD) | (__v & CBAUD);
  return 0;
}

#endif /* _TERMIOS_H */