diff --git a/include/stdbool.h b/include/stdbool.h
index 59cce7a961..4175a0f9ad 100644
--- a/include/stdbool.h
+++ b/include/stdbool.h
@@ -2,12 +2,12 @@
#define _STDBOOL_H
#ifndef __cplusplus
-typedef _Bool bool;
+#define bool _Bool
#define true 1
#define false 0
#else /* __cplusplus */
-typedef bool _Bool;
#if __cplusplus < 201103L
+#define bool bool
#define false false
#define true true
#endif /*__cplusplus < 201103L*/
@@ -15,5 +15,4 @@ typedef bool _Bool;
#define __bool_true_false_are_defined 1
-
#endif /* _STDBOOL_H */
diff --git a/tests/stdlib/ptsname.c b/tests/stdlib/ptsname.c
index 82d2687d84..d7489401a7 100644
--- a/tests/stdlib/ptsname.c
+++ b/tests/stdlib/ptsname.c
@@ -16,12 +16,14 @@
License along with the GNU C Library; if not, see
. */
+#define _XOPEN_SOURCE 600
#include
#include
#include
#include
#include
#include
+#include
#define DEV_TTY "/dev/tty"
#define PTSNAME_EINVAL "./ptsname-einval"
@@ -29,21 +31,20 @@
int do_single_test(int fd, char * buf, size_t buflen, int expected_err) {
int ret = ptsname_r(fd, buf, buflen);
- int err = errno;
if (expected_err == 0) {
if (ret != 0) {
printf("ptsname_r: expected: return = 0\n");
- printf(" got: return = %d, errno = %d (%s)\n",
- ret, err, strerror(err));
+ printf(" got: return = %d (%s)\n",
+ ret, strerror(ret));
return 1;
}
} else {
- if (ret == 0 || errno != expected_err) {
- printf("ptsname_r: expected: return = %d, errno = %d (%s)\n",
- -1, expected_err, strerror(expected_err));
- printf(" got: return = %d, errno = %d (%s)\n",
- ret, err, strerror(err));
+ if (ret == 0 || ret != expected_err) {
+ printf("ptsname_r: expected: return = %d (%s)\n",
+ expected_err, strerror(expected_err));
+ printf(" got: return = %d (%s)\n",
+ ret, strerror(ret));
return 1;
}
}
@@ -52,18 +53,26 @@ int do_single_test(int fd, char * buf, size_t buflen, int expected_err) {
}
int main(void) {
- char buf[512] = {0};
+ char buf[TTY_NAME_MAX] = {0};
int result = 0;
errno = 0;
/* Tests with a real PTS master. */
int fd = posix_openpt(O_RDWR);
- if (fd != -1) {
- result |= do_single_test(fd, buf, sizeof(buf), 0);
- result |= do_single_test(fd, buf, 1, ERANGE);
- close(fd);
- } else
+ if (fd == -1) {
printf("posix_openpt (O_RDWR) failed\nerrno %d (%s)\n",
errno, strerror(errno));
+ }
+ errno = 0;
+ if (grantpt(fd) == -1) {
+ printf("grantpt(%d) failed\nerrno %d (%s)\n", fd, errno, strerror(errno));
+ }
+ errno = 0;
+ if (unlockpt(fd) == -1) {
+ printf("unlockpt(%d) failed\nerrno %d (%s)\n", fd, errno, strerror(errno));
+ }
+ result |= do_single_test(fd, buf, sizeof(buf), 0);
+ result |= do_single_test(fd, buf, 1, ERANGE);
+ close(fd);
// TODO: open(DEV_TTY, O_RDONLY) gives error on CI
// /* Test with a terminal device which is not a PTS master. */
@@ -77,13 +86,18 @@ int main(void) {
/* Test with a file. */
fd = open(PTSNAME_EINVAL, O_RDWR | O_CREAT, 0600);
- if (fd != -1) {
- result |= do_single_test(fd, buf, sizeof(buf), ENOTTY);
- close(fd);
- unlink(PTSNAME_EINVAL);
- } else
+ grantpt(fd); // grantpt() is a no-op on Linux and Redox but is needed for POSIX compliance.
+ errno = 0;
+ if (unlockpt(fd) != -1 && errno != EINVAL) {
+ printf("unlockpt(%d) did not return an expected errno\ngot errno %d (%s)\n", fd, errno, strerror(errno));
+ }
+ if (fd == -1) {
printf("open (\"%s\", O_RDWR | OCREAT) failed\nerrno %d (%s)\n",
PTSNAME_EINVAL, errno, strerror(errno));
+ }
+ result |= do_single_test(fd, buf, sizeof(buf), ENOTTY);
+ close(fd);
+ unlink(PTSNAME_EINVAL);
return result;
-}
\ No newline at end of file
+}