Make <sys/ttydefaults.h> more usable.

* TTYDEF_OFLAG referred to the BSD OXTABS constant instead of the Linux XTABS,
  so references to it wouldn't compile.

* CEOL was incorrect (compared to `stty -a`).

* ttydefchars wouldn't compile (removed rather than attempt to fix something
  of unclear utility).

Bug: http://b/63145226
Test: new test
Change-Id: I823e5eaab789cafd2eeea03f77ea553346822f74
diff --git a/libc/include/sys/ttydefaults.h b/libc/include/sys/ttydefaults.h
index 62af84b..4dcc649 100644
--- a/libc/include/sys/ttydefaults.h
+++ b/libc/include/sys/ttydefaults.h
@@ -48,7 +48,7 @@
  * Defaults on "first" open.
  */
 #define	TTYDEF_IFLAG	(BRKINT | ICRNL | IMAXBEL | IXON | IXANY)
-#define TTYDEF_OFLAG	(OPOST | ONLCR | OXTABS)
+#define TTYDEF_OFLAG	(OPOST | ONLCR | XTABS)
 #define TTYDEF_LFLAG	(ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL)
 #define TTYDEF_CFLAG	(CREAD | CS8 | HUPCL)
 #define TTYDEF_SPEED	(B9600)
@@ -58,7 +58,7 @@
  */
 #define CTRL(x)	(x&037)
 #define	CEOF		CTRL('d')
-#define	CEOL		((unsigned char)'\377')	/* XXX avoid _POSIX_VDISABLE */
+#define	CEOL		'\0'	/* XXX avoid _POSIX_VDISABLE */
 #define	CERASE		0177
 #define	CINTR		CTRL('c')
 #define	CSTATUS		CTRL('t')
@@ -80,34 +80,4 @@
 #define CRPRNT		CREPRINT
 #define	CFLUSH		CDISCARD
 
-/* PROTECTED INCLUSION ENDS HERE */
 #endif /* !_SYS_TTYDEFAULTS_H_ */
-
-/*
- * #define TTYDEFCHARS to include an array of default control characters.
- */
-#ifdef TTYDEFCHARS
-const cc_t ttydefchars[NCCS] = {
-	[VEOF] = CEOF,
-	[VEOL] = CEOL,
-	[VEOL2] = CEOL,
-	[VERASE] = CERASE,
-	[VWERASE] = CWERASE,
-	[VKILL] = CKILL,
-	[VREPRINT] = CREPRINT,
-	[7] = _POSIX_VDISABLE,	/* spare */
-	[VINTR] = CINTR,
-	[VQUIT] = CQUIT,
-	[VSUSP] = CSUSP,
-	[VDSUSP] = CDSUSP,
-	[VSTART] = CSTART,
-	[VSTOP] = CSTOP,
-	[VLNEXT] = CLNEXT,
-	[VDISCARD] = CDISCARD,
-	[VMIN] = CMIN,
-	[VTIME] = CTIME,
-	[VSTATUS] = CSTATUS,
-	[19] = _POSIX_VDISABLE,	/* spare */
-};
-#undef TTYDEFCHARS
-#endif
diff --git a/tests/Android.bp b/tests/Android.bp
index 2a5b47e..c1dc7ca 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -134,6 +134,7 @@
         "sys_sysmacros_test.cpp",
         "sys_time_test.cpp",
         "sys_timex_test.cpp",
+        "sys_ttydefaults_test.cpp",
         "sys_types_test.cpp",
         "sys_uio_test.cpp",
         "sys_vfs_test.cpp",
diff --git a/tests/sys_ttydefaults_test.cpp b/tests/sys_ttydefaults_test.cpp
new file mode 100644
index 0000000..fa4f7c7
--- /dev/null
+++ b/tests/sys_ttydefaults_test.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <sys/ttydefaults.h>
+#include <termios.h>
+
+TEST(sys_ttydefaults, flags) {
+  int i;
+  i = TTYDEF_IFLAG;
+  i = TTYDEF_OFLAG;
+  i = TTYDEF_LFLAG;
+  i = TTYDEF_CFLAG;
+  i = TTYDEF_SPEED;
+}
+
+TEST(sys_ttydefaults, correct_CEOL) {
+  ASSERT_EQ(_POSIX_VDISABLE, CEOL);
+}