aboutsummaryrefslogtreecommitdiff
path: root/tests/unistd/ttyname.c
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-07-23 05:49:48 +0300
committermax99x <max99x@gmail.com>2011-07-23 05:49:48 +0300
commit136756f734ecf14a28736900075d561e981e973e (patch)
treecf33472ea6550c6486ec7722facf34d98a16a51d /tests/unistd/ttyname.c
parent586d229ec311daa5e89781eb6da822989e677789 (diff)
Added unistd tests; fixed a lot of unistd bugs and deficiencies.
Diffstat (limited to 'tests/unistd/ttyname.c')
-rw-r--r--tests/unistd/ttyname.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/unistd/ttyname.c b/tests/unistd/ttyname.c
new file mode 100644
index 00000000..7080be5d
--- /dev/null
+++ b/tests/unistd/ttyname.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int main() {
+ char buffer[256];
+ int d = open("/device", O_RDWR);
+ int f = open("/", O_RDONLY);
+ char* result;
+
+ result = ctermid(buffer);
+ if (result) {
+ printf("ctermid: %s\n", result);
+ } else {
+ printf("ctermid errno: %d\n", errno);
+ errno = 0;
+ }
+
+ if (ttyname_r(d, buffer, 256) == 0) {
+ printf("ttyname_r(d, ..., 256): %s\n", buffer);
+ } else {
+ printf("ttyname_r(d, ..., 256) errno: %d\n", errno);
+ errno = 0;
+ }
+
+ if (ttyname_r(d, buffer, 2) == 0) {
+ printf("ttyname_r(d, ..., 2): %s\n", buffer);
+ } else {
+ printf("ttyname_r(d, ..., 2) errno: %d\n", errno);
+ errno = 0;
+ }
+
+ result = ttyname(d);
+ if (result) {
+ printf("ttyname(d): %s\n", result);
+ } else {
+ printf("ttyname(d) errno: %d\n", errno);
+ errno = 0;
+ }
+
+ result = ttyname(f);
+ if (result) {
+ printf("ttyname(f): %s\n", result);
+ } else {
+ printf("ttyname(f) errno: %d\n", errno);
+ errno = 0;
+ }
+
+ return 0;
+}