summaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/powerpc/aix/tcsetattr.c
blob: b7330a3def3d29c2d9a2649a415d161d92fd0d1c (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* Copyright (C) 2000-2013 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#include <errno.h>
#include <termios.h>
#include "aix-termios.h"

int
tcsetattr (fd, optional_actions, linuxtermios_p)
     int fd;
     int optional_actions;
     const struct termios *linuxtermios_p;
{
  struct aixtermios aixtermios;
  int result;

  /* `optional_actions' does not have to be changed, AIX uses the
     same values as Linux.  */

  aixtermios.c_cc[AIX_VINTR] = linuxtermios_p->c_cc[VINTR];
  aixtermios.c_cc[AIX_VQUIT] = linuxtermios_p->c_cc[VQUIT];
  aixtermios.c_cc[AIX_VERASE] = linuxtermios_p->c_cc[VERASE];
  aixtermios.c_cc[AIX_VKILL] = linuxtermios_p->c_cc[VKILL];
  aixtermios.c_cc[AIX_VEOF] = linuxtermios_p->c_cc[VEOF];
  // XXX VMIN has the same value as VEOF !?
  aixtermios.c_cc[AIX_VEOL] = linuxtermios_p->c_cc[VEOL];
  // XXX VTIME has the same value as VEOL !?
  aixtermios.c_cc[AIX_VEOL2] = linuxtermios_p->c_cc[VEOL2];
  aixtermios.c_cc[AIX_VSTART] = linuxtermios_p->c_cc[VSTART];
  aixtermios.c_cc[AIX_VSTOP] = linuxtermios_p->c_cc[VSTOP];
  aixtermios.c_cc[AIX_VSUSP] = linuxtermios_p->c_cc[VSUSP];
  aixtermios.c_cc[AIX_VDSUSP] = 0; // XXX No Linux equivalent !?
  aixtermios.c_cc[AIX_VREPRINT] = linuxtermios_p->c_cc[VREPRINT];
  aixtermios.c_cc[AIX_VDISCARD] = linuxtermios_p->c_cc[VDISCARD];
  aixtermios.c_cc[AIX_VWERASE] = linuxtermios_p->c_cc[VWERASE];
  aixtermios.c_cc[AIX_VLNEXT] = linuxtermios_p->c_cc[VLNEXT];

  /* AIX has not all the speeds (the high one) Linux supports.  The
     symbol names and values used for the speeds are fortunately the
     same.  */
  if ((linuxtermios_p->c_cflag & CBAUD) > B38400)
    {
      __set_errno (EINVAL);
      return -1;
    }

  aixtermios.c_c_flag = linuxtermios_p->c_cflag & CBAUD;

  /* Only the IUCLC, IXANY, and IMAXBEL values are different in the
     c_iflag member.  */
  aixtermios.c_iflag = linuxtermios_p->c_iflag & 0x7ff;
  if (linuxtermios_p->c_iflag & IXANY)
    aixtermios.c_iflag |= AIX_IXANY;
  if (linuxtermios_p->c_iflag & IUCLC)
    aixtermios.c_iflag |= AIX_IUCLC;
  if (linuxtermios_p->c_iflag & IMAXBEL)
    aixtermios.c_iflag |= AIX_IMAXBEL;

  /* Many of the c_oflag files differ.  Bummer.  */
  aixtermios.c_oflag = (linuxtermios_p->c_oflag
			& (OPOST | OCRNL | ONOCR | ONLRET | OFILL
			   | OFDEL | TABDLY));
  if (linuxtermios_p->c_oflag & OLCUC)
    aixtermios.c_oflag |= AIX_OLCUC;
  if (linuxtermios_p->c_oflag & ONLCR)
    aixtermios.c_oflag |= AIX_ONLCR;
  if (linuxtermios_p->c_oflag & NLDLY)
    {
      if ((linuxtermios_p->c_oflag & NLDLY) >= NL2)
	{
	  __set_errno (EINVAL);
	  return -1;
	}

      if (linuxtermios_p->c_oflag & NLDLY)
	aixtermios.c_oflag |= AIX_NL1;
    }
  if (linuxtermios_p->c_oflag & TABDLY)
    {
#define offset 2
#if TAB1 >> offset != AIX_TAB1 || TAB3 >> offset != AIX_TAB3
# error "Check the offset"
#endif
      aixtermios.c_oflag |= (linuxtermios_p->c_oflag >> offset) & AIX_TABDLY;
#undef offset
    }
  if (linuxtermios_p->c_oflag & FFDLY)
    aixtermios.c_oflag |= AIX_FF1;
  if (linuxtermios_p->c_oflag & BSDLY)
    aixtermios.c_oflag |= AIX_BS1;
  if (linuxtermios_p->c_oflag & VTDLY)
    aixtermios.c_oflag |= AIX_VT1;

  /* A lot of the c_cflag member is also different.  */
  if (linuxtermios_p->c_cflag & CSIZE)
    {
#define offset 4
#if CSIZE >> offset != AIX_CSIZE
# error "Check the offset"
#endif
      aixtermios.c_cflag |= (linuxtermios_p->c_cflag >> offset) & AIX_CSIZE;
#undef offset
    }

  if (linuxtermios_p->c_cflag & STOPB)
    aixtermios.c_cflag |= AIX_STOPB;
  if (linuxtermios_p->c_cflag & CREAD)
    aixtermios.c_cflag |= AIX_CREAD;
  if (linuxtermios_p->c_cflag & PARENB)
    aixtermios.c_cflag |= AIX_PARENB;
  if (linuxtermios_p->c_cflag & PARODD)
    aixtermios.c_cflag |= AIX_PARODD;
  if (linuxtermios_p->c_cflag & HUPCL)
    aixtermios.c_cflag |= AIX_HUPCL;
  if (linuxtermios_p->c_cflag & CLOCAL)
    aixtermios.c_cflag |= AIX_CLOCAL;

  /* The c_lflag is information is also different.  */
  aixtermios.c_lflag = 0;
  if (linuxtermios_p->c_lflag & ISIG)
    aixtermios.c_lflag |= AIX_ISIG;
  if (linuxtermios_p->c_lflag & ICANON)
    aixtermios.c_lflag |= AIX_ICANON;
  if (linuxtermios_p->c_lflag & XCASE)
    aixtermios.c_lflag |= AIX_XCASE;
  if (linuxtermios_p->c_lflag & ECHO)
    aixtermios.c_lflag |= AIX_ECHO;
  if (linuxtermios_p->c_lflag & ECHOE)
    aixtermios.c_lflag |= AIX_ECHOE;
  if (linuxtermios_p->c_lflag & ECHOK)
    aixtermios.c_lflag |= AIX_ECHOK;
  if (linuxtermios_p->c_lflag & ECHONL)
    aixtermios.c_lflag |= AIX_ECHONL;
  if (linuxtermios_p->c_lflag & NOFLSH)
    aixtermios.c_lflag |= AIX_NOFLSH;
  if (linuxtermios_p->c_lflag & TOSTOP)
    aixtermios.c_lflag |= AIX_TOSTOP;
  if (linuxtermios_p->c_lflag & ECHOCTL)
    aixtermios.c_lflag |= AIX_ECHOCTL;
  if (linuxtermios_p->c_lflag & ECHOPRT)
    aixtermios.c_lflag |= AIX_ECHOPRT;
  if (linuxtermios_p->c_lflag & ECHOKE)
    aixtermios.c_lflag |= AIX_ECHOKE;
  if (linuxtermios_p->c_lflag & FLUSHO)
    aixtermios.c_lflag |= AIX_FLUSHO;
  if (linuxtermios_p->c_lflag & PENDIN)
    aixtermios.c_lflag |= AIX_PENDIN;
  if (linuxtermios_p->c_lflag & IEXTEN)
    aixtermios.c_lflag |= AIX_IEXTEN;

  result = /* XXX syscall */;

  // Convert error here or in syscall.

  return result;
}