sizeof and subpackages for platform-specific code
This commit is contained in:
parent
12a96d502a
commit
d9d7e3b9c3
@ -0,0 +1,23 @@
|
||||
|
||||
package ru.landgrafhomyak.utility.kotlin_native_interop_stdlib_0
|
||||
|
||||
import kotlinx.cinterop.CVariable
|
||||
import kotlinx.cinterop.ExperimentalForeignApi
|
||||
import kotlinx.cinterop.sizeOf
|
||||
|
||||
|
||||
/**
|
||||
* Returns size of a C type in bytes, but as [unsigned long long][ULong].
|
||||
* @see sizeOf
|
||||
* @see sizeOfUI
|
||||
*/
|
||||
@ExperimentalForeignApi
|
||||
public inline fun <reified T : CVariable> sizeOfUL(): ULong = sizeOf<T>().toULong()
|
||||
|
||||
/**
|
||||
* Returns size of a C type in bytes, but as [unsigned long][UInt].
|
||||
* @see sizeOf
|
||||
* @see sizeOfUL
|
||||
*/
|
||||
@ExperimentalForeignApi
|
||||
public inline fun <reified T : CVariable> sizeOfUI(): UInt = sizeOf<T>().toUInt()
|
||||
@ -1,9 +1,10 @@
|
||||
package ru.landgrafhomyak.utility.kotlin_native_interop_stdlib_0
|
||||
package ru.landgrafhomyak.utility.kotlin_native_interop_stdlib_0.posix
|
||||
|
||||
import kotlinx.cinterop.ExperimentalForeignApi
|
||||
import kotlinx.cinterop.toKStringFromUtf8
|
||||
import platform.posix.errno
|
||||
import platform.posix.strerror
|
||||
import platform.posix.errno as getLastErrno
|
||||
import ru.landgrafhomyak.utility.kotlin_native_interop_stdlib_0.OsException
|
||||
|
||||
public class PosixApiException : OsException {
|
||||
private val errno: Int
|
||||
@ -41,7 +42,7 @@ public class PosixApiException : OsException {
|
||||
throw this.formatFromWindowsErrCode(code)
|
||||
}
|
||||
|
||||
public fun formatFromLastWindowsErr(): PosixApiException = this.formatFromWindowsErrCode(getLastErrno)
|
||||
public fun formatFromLastWindowsErr(): PosixApiException = this.formatFromWindowsErrCode(errno)
|
||||
|
||||
public fun formatFromWindowsErrCode(code: Int): PosixApiException {
|
||||
var err = PosixApiException(errno = code, nativeMessage = null, customMessage = "[errno=${code}]")
|
||||
@ -60,7 +61,7 @@ public class PosixApiException : OsException {
|
||||
if (raw != null) {
|
||||
return raw.toKStringFromUtf8()
|
||||
} else {
|
||||
val strerrErrno = getLastErrno
|
||||
val strerrErrno = errno
|
||||
throw PosixApiException(errno = strerrErrno, nativeMessage = null, "[errno=${strerrErrno}]")
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package ru.landgrafhomyak.utility.kotlin_native_interop_stdlib_0
|
||||
package ru.landgrafhomyak.utility.kotlin_native_interop_stdlib_0.windows
|
||||
|
||||
import kotlinx.cinterop.ByteVar
|
||||
import kotlinx.cinterop.CPointerVar
|
||||
@ -16,6 +16,7 @@ import platform.windows.FormatMessageA
|
||||
import platform.windows.GetLastError
|
||||
import platform.windows.LocalFree
|
||||
import ru.landgrafhomyak.utility.highlevel_try_finally.safeAutoClose1
|
||||
import ru.landgrafhomyak.utility.kotlin_native_interop_stdlib_0.OsException
|
||||
|
||||
public class WindowsApiException : OsException {
|
||||
private val errno: UInt
|
||||
Loading…
Reference in New Issue
Block a user