Skip to content

Commit 89e027e

Browse files
committed
pmieconf: switch to using termios API for macOS builds
1 parent 4da79ea commit 89e027e

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

src/pmieconf/io.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,19 @@ promptformore(void)
6666
struct termios ntty;
6767

6868
if (first) {
69-
if (ioctl(0, TCGETA, &otty) < 0) {
70-
fprintf(stderr, "%s: TCGETA ioctl failed: %s\n", pmGetProgname(),
69+
if (tcgetattr(0, &otty) == -1) {
70+
fprintf(stderr, "%s: tcgetattr failed: %s\n", pmGetProgname(),
7171
osstrerror());
7272
exit(1);
7373
}
7474
first = 0;
7575
}
7676

7777
/* put terminal into raw mode so we can read input immediately */
78-
memcpy(&ntty, &otty, sizeof(struct termios));
79-
ntty.c_cc[VMIN] = 1;
80-
ntty.c_cc[VTIME] = 1;
81-
ntty.c_lflag &= ~(ICANON | ECHO);
82-
if (ioctl(0, TCSETAW, &ntty) < 0) {
83-
fprintf(stderr, "%s: TCSETAW ioctl failed: %s\n", pmGetProgname(),
78+
ntty = otty;
79+
cfmakeraw(&ntty);
80+
if (tcsetattr(0, TCSAFLUSH, &ntty) == -1) {
81+
fprintf(stderr, "%s: tcsetattr failed: %s\n", pmGetProgname(),
8482
osstrerror());
8583
exit(1);
8684
}
@@ -122,8 +120,8 @@ promptformore(void)
122120

123121
reset_tty:
124122
#ifdef HAVE_TERMIOS_H
125-
if (ioctl(0, TCSETAW, &otty) < 0) {
126-
fprintf(stderr, "%s: reset TCSETAW ioctl failed: %s\n", pmGetProgname(),
123+
if (tcsetattr(0, TCSAFLUSH, &otty) == -1) {
124+
fprintf(stderr, "%s: reset tcsetattr failed: %s\n", pmGetProgname(),
127125
osstrerror());
128126
exit(1);
129127
}

0 commit comments

Comments
 (0)