Update: While reporting this issue to Pexpect: https://github.com/pexpect/pexpect/issues/662 , I found that their own implementation _fork_pty.fork_pty() for Solaris also works on macOS, due to explicit opening /dev/tty in the child process:
		if (pid == 0) {	// child
				int ttyfd = open("/dev/tty", O_WRONLY);
				CHECK(ttyfd != -1);
				CHECK(close(ttyfd) != -1);
[...]
after that (with these 3 lines added after line #26), the output on macOS is:
$ ./a.out
read 64 bytes: 0123456789012345678901234567890123456789012345678901234567890123
read 36 bytes: 456789012345678901234567890123456789
read 0 bytes: