Discussion:
ptsname_r: don't expect that this function sets errno
(too old to reply)
Bruno Haible
2018-02-24 10:00:01 UTC
Permalink
glibc ptsname_r sets errno when it fails, but this is not specified in
https://www.gnu.org/software/libc/manual/html_node/Allocation.html
and musl libc does not do the same thing. This leads to a test failure
of 'test-ptsname_r' on Alpine Linux 3.7.0.

This patch fixes it.


2018-02-24 Bruno Haible <***@clisp.org>

ptsname_r: Don't expect that this function sets errno.
* tests/test-ptsname_r.c (test_errors): Don't test errno after return
from ptsname_r().
* doc/glibc-functions/ptsname_r.texi: Mention the issue.

diff --git a/doc/glibc-functions/ptsname_r.texi b/doc/glibc-functions/ptsname_r.texi
index 8109085..979a090 100644
--- a/doc/glibc-functions/ptsname_r.texi
+++ b/doc/glibc-functions/ptsname_r.texi
@@ -22,4 +22,8 @@ OSF/1 5.1.

Portability problems not fixed by Gnulib:
@itemize
+@item
+When this functions fails, it provides the error code only as the
+return value, without setting @code{errno}, on some platforms:
+musl libc.
@end itemize
diff --git a/tests/test-ptsname_r.c b/tests/test-ptsname_r.c
index ca313d1..dcbecc4 100644
--- a/tests/test-ptsname_r.c
+++ b/tests/test-ptsname_r.c
@@ -70,7 +70,6 @@ test_errors (int fd, const char *slave)
for (buflen = 0; buflen <= buflen_max; buflen++)
{
memset (buffer, 'X', sizeof buffer);
- errno = 0;
result = ptsname_r (fd, buffer, buflen);
if (buflen > len)
{
@@ -80,17 +79,14 @@ test_errors (int fd, const char *slave)
else
{
ASSERT (result != 0);
- ASSERT (result == errno);
- ASSERT (errno == ERANGE);
+ ASSERT (result == ERANGE);
ASSERT (buffer[0] == 'X');
}
}

- errno = 0;
result = ptsname_r (fd, null_ptr (), 0);
ASSERT (result != 0);
- ASSERT (result == errno);
- ASSERT (errno == EINVAL);
+ ASSERT (result == EINVAL);
}

int
@@ -108,11 +104,9 @@ main (void)
char buffer[256];
int result;

- errno = 0;
result = ptsname_r (-1, buffer, sizeof buffer);
ASSERT (result != 0);
- ASSERT (result == errno);
- ASSERT (errno == EBADF || errno == ENOTTY);
+ ASSERT (result == EBADF || result == ENOTTY);
}

{

Loading...