Reused C macroses by defining bridges to them in def file
This commit is contained in:
@@ -203,22 +203,15 @@ class IOException: RuntimeException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val errno: Int
|
val errno: Int
|
||||||
get() = __error()!!.pointed.value
|
get() = interop_errno()
|
||||||
|
|
||||||
fun FD_ZERO(set: fd_set) {
|
fun FD_ZERO(set: fd_set): Unit = interop_FD_ZERO(set.ptr)
|
||||||
memset(set.fds_bits, 0, sizeOf<fd_set>())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FD_SET(bit: Int, set: fd_set) {
|
fun FD_SET(bit: Int, set: fd_set): Unit = interop_FD_SET(bit, set.ptr)
|
||||||
set.fds_bits[bit / 32] = set.fds_bits[bit / 32] or (1 shl (bit % 32))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FD_ISSET(bit: Int, set: fd_set): Boolean {
|
fun FD_ISSET(bit: Int, set: fd_set) = interop_FD_ISSET(bit, set.ptr) != 0
|
||||||
return set.fds_bits[bit / 32] and (1 shl (bit % 32)) != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not available through interop because declared as macro:
|
fun htons(value: Short) = interop_htons(value.toInt()).toShort()
|
||||||
fun htons(value: Short) = ((value.toInt() ushr 8) or (value.toInt() shl 8)).toShort()
|
|
||||||
|
|
||||||
fun getUnixError() = strerror(errno)!!.toKString()
|
fun getUnixError() = strerror(errno)!!.toKString()
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,24 @@
|
|||||||
headers = sys/socket.h sys/errno.h sys/select.h fcntl.h netdb.h stdio.h string.h unistd.h stdlib.h netinet/in.h
|
headers = sys/socket.h sys/errno.h sys/select.h fcntl.h netdb.h stdio.h string.h unistd.h stdlib.h netinet/in.h
|
||||||
excludeDependentModules.osx = true
|
excludeDependentModules.osx = true
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
static int interop_errno() {
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int interop_htons(int x) {
|
||||||
|
return htons(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void interop_FD_ZERO(fd_set *set) {
|
||||||
|
FD_ZERO(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void interop_FD_SET(int bit, fd_set *set) {
|
||||||
|
FD_SET(bit, set);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int interop_FD_ISSET(int bit, fd_set *set) {
|
||||||
|
return FD_ISSET(bit, set);
|
||||||
|
}
|
||||||
|
|||||||
@@ -64,24 +64,21 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not available through interop because declared as macro:
|
val errno: Int
|
||||||
fun htons(value: Short) = ((value.toInt() ushr 8) or (value.toInt() shl 8)).toShort()
|
get() = interop_errno()
|
||||||
|
|
||||||
fun throwUnixError(): Nothing {
|
fun htons(value: Short) = interop_htons(value.toInt()).toShort()
|
||||||
perror(null) // TODO: store error message to exception instead.
|
|
||||||
throw Error("UNIX call failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun Int.ensureUnixCallResult(predicate: (Int) -> Boolean): Int {
|
inline fun Int.ensureUnixCallResult(predicate: (Int) -> Boolean): Int {
|
||||||
if (!predicate(this)) {
|
if (!predicate(this)) {
|
||||||
throwUnixError()
|
throw Error(strerror(errno)!!.toKString())
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun Long.ensureUnixCallResult(predicate: (Long) -> Boolean): Long {
|
inline fun Long.ensureUnixCallResult(predicate: (Long) -> Boolean): Long {
|
||||||
if (!predicate(this)) {
|
if (!predicate(this)) {
|
||||||
throwUnixError()
|
throw Error(strerror(errno)!!.toKString())
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@@ -1,2 +1,12 @@
|
|||||||
headers = sys/socket.h netdb.h stdio.h string.h unistd.h stdlib.h netinet/in.h
|
headers = sys/socket.h sys/errno.h netdb.h stdio.h string.h unistd.h stdlib.h netinet/in.h
|
||||||
excludeDependentModules.osx = true
|
excludeDependentModules.osx = true
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
static int interop_errno() {
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int interop_htons(int x) {
|
||||||
|
return htons(x);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user