X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=tests%2Ftest-ptsname_r.c;h=b194303815bef311ac561601bfdbb5fa688a828e;hb=831b84c59ef413c57a36b67344467d66a8a2ba70;hp=5906e2e2a523ebe2663a711de8fe30c010491eb6;hpb=44e24aa42fb9e808f25767f5ce555d6844efc1c8;p=gnulib.git diff --git a/tests/test-ptsname_r.c b/tests/test-ptsname_r.c index 5906e2e2a..b19430381 100644 --- a/tests/test-ptsname_r.c +++ b/tests/test-ptsname_r.c @@ -1,5 +1,5 @@ /* Test of ptsname_r(3). - Copyright (C) 2010-2011 Free Software Foundation, Inc. + Copyright (C) 2010-2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -53,6 +53,12 @@ same_slave (const char *slave_name1, const char *slave_name2) && SAME_INODE (statbuf1, statbuf2))); } +static char * +null_ptr (void) +{ + return NULL; +} + static void test_errors (int fd, const char *slave) { @@ -86,7 +92,7 @@ test_errors (int fd, const char *slave) } errno = 0; - result = ptsname_r (fd, NULL, 0); + result = ptsname_r (fd, null_ptr (), 0); ASSERT (result != 0); ASSERT (result == errno); ASSERT (errno == EINVAL); @@ -98,8 +104,9 @@ main (void) #if HAVE_DECL_ALARM /* Declare failure if test takes too long, by using default abort caused by SIGALRM. */ + int alarm_value = 5; signal (SIGALRM, SIG_DFL); - alarm (5); + alarm (alarm_value); #endif { @@ -145,7 +152,7 @@ main (void) char buffer[256]; int result; - /* Open the controlling tty of the current process. */ + /* Open a pty master. */ fd = open ("/dev/ptmx", O_RDWR | O_NOCTTY); if (fd < 0) { @@ -162,9 +169,35 @@ main (void) close (fd); } +#elif defined _AIX + /* AIX has BSD-style /dev/ptyp[0-9a-f] files, but the modern way to open + a pty is to go through /dev/ptc. */ + { + int fd; + char buffer[256]; + int result; + + /* Open a pty master. */ + fd = open ("/dev/ptc", O_RDWR | O_NOCTTY); + if (fd < 0) + { + fprintf (stderr, "Skipping test: cannot open pseudo-terminal\n"); + return 77; + } + + result = ptsname_r (fd, buffer, sizeof buffer); + ASSERT (result == 0); + ASSERT (memcmp (buffer, "/dev/pts/", 9) == 0); + + test_errors (fd, buffer); + + /* This call hangs on AIX. */ + close (fd); + } + #else - /* Try various master names of MacOS X: /dev/pty[p-w][0-9a-f] */ + /* Try various master names of Mac OS X: /dev/pty[p-w][0-9a-f] */ { int char1; int char2; @@ -190,6 +223,7 @@ main (void) test_errors (fd, buffer); + /* This call hangs on AIX. */ close (fd); } }