Skip to content

Commit

Permalink
Split out termios modification
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-level committed Jan 31, 2024
1 parent 3d4853f commit 1aca0f2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ksrpc-sockets/src/linuxX64Main/kotlin/TermiosUtil.linuxX64.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.monkopedia.ksrpc.sockets

import platform.posix.ICANON
import platform.posix.termios

actual fun termios.setICanon() {
c_lflag = c_lflag and ICANON.inv().toUInt()
}
9 changes: 9 additions & 0 deletions ksrpc-sockets/src/macosX64Main/kotlin/TermiosUtil.macosX64.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.monkopedia.ksrpc.sockets

import platform.posix.ICANON
import platform.posix.termios

actual fun termios.setICanon() {
c_lflag = c_lflag and ICANON.inv().toUInt()
}

4 changes: 3 additions & 1 deletion ksrpc-sockets/src/nativeMain/kotlin/TermiosUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ fun initTermios(fd: Int = STDIN_FILENO, old: CPointer<termios>) {
val current = alloc<termios>().ptr
tcgetattr(fd, old)
memcpy(current, old, sizeOf<termios>().toULong())
current.pointed.c_lflag = current.pointed.c_lflag and ICANON.inv().toUInt()
current.pointed.setICanon()
tcsetattr(fd, TCSANOW, current)
}
}

expect fun termios.setICanon()

fun resetTermios(fd: Int = STDIN_FILENO, old: CPointer<termios>) {
tcsetattr(fd, TCSANOW, old)
}

0 comments on commit 1aca0f2

Please sign in to comment.