Back to index

glibc  2.9
tst-ttyname_r.c
Go to the documentation of this file.
00001 #include <errno.h>
00002 #include <error.h>
00003 #include <fcntl.h>
00004 #include <stdio.h>
00005 #include <unistd.h>
00006 
00007 static void do_prepare (void);
00008 #define PREPARE(argc, argv) do_prepare ()
00009 static int do_test (void);
00010 #define TEST_FUNCTION do_test ()
00011 #include <test-skeleton.c>
00012 
00013 static int temp_fd;
00014 
00015 static void
00016 do_prepare (void)
00017 {
00018   char *temp_file;
00019   temp_fd = create_temp_file ("tst-ttyname_r.", &temp_file);
00020   if (temp_fd == -1)
00021     error (1, errno, "cannot create temporary file");
00022 }
00023 
00024 static int
00025 do_test (void)
00026 {
00027   int ret = 0;
00028   char buf[sysconf (_SC_TTY_NAME_MAX) + 1];
00029   int res = ttyname_r (-1, buf, sizeof (buf));
00030   if (res != EBADF)
00031     {
00032       printf ("1st ttyname_r returned with res %d\n", res);
00033       ret++;
00034     }
00035   res = ttyname_r (temp_fd, buf, sizeof (buf));
00036   if (res != ENOTTY)
00037     {
00038       printf ("2nd ttyname_r returned with res %d\n", res);
00039       ret++;
00040     }
00041   return ret;
00042 }