This repository has been archived by the owner on Jul 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b80e2e
commit 8d28eb4
Showing
12 changed files
with
113 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
klock/src/darwinMain/kotlin/com/soywiz/klock/internal/KlockInternal.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.soywiz.klock.internal | ||
|
||
import com.soywiz.klock.* | ||
import com.soywiz.klock.hr.* | ||
import kotlinx.cinterop.* | ||
import platform.CoreFoundation.* | ||
import platform.posix.* | ||
|
||
internal actual object KlockInternal { | ||
actual val currentTime: Double get() = memScoped { | ||
val timeVal = alloc<timeval>() | ||
gettimeofday(timeVal.ptr, null) | ||
val sec = timeVal.tv_sec | ||
val usec = timeVal.tv_usec | ||
((sec * 1_000L) + (usec / 1_000L)).toDouble() | ||
} | ||
|
||
actual val hrNow: HRTimeSpan get() = memScoped { | ||
val timeVal = alloc<timeval>() | ||
gettimeofday(timeVal.ptr, null) | ||
val sec = timeVal.tv_sec | ||
val usec = timeVal.tv_usec | ||
HRTimeSpan.fromSeconds(sec.toInt()) + HRTimeSpan.fromMicroseconds(usec.toInt()) | ||
} | ||
|
||
actual fun sleep(time: HRTimeSpan) { | ||
val micros = time.microsecondsDouble.toLong() | ||
val s = micros / 1_000_000 | ||
val u = micros % 1_000_000 | ||
if (s > 0) platform.posix.sleep(s.convert()) | ||
if (u > 0) platform.posix.usleep(u.convert()) | ||
} | ||
|
||
actual fun localTimezoneOffsetMinutes(time: DateTime): TimeSpan = autoreleasepool { | ||
val tz: CFTimeZoneRef? = CFTimeZoneCopySystem() | ||
val minsFromGMT: CFTimeInterval = CFTimeZoneGetSecondsFromGMT(tz, CFAbsoluteTimeGetCurrent()) / 60.0 | ||
minsFromGMT.minutes | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
korio/src/darwinMain/kotlin/com/soywiz/korio/process/ProcessApple.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
korio/src/nativeMain/kotlin/com/soywiz/korio/process/ProcessNative.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
korio/src/posixInteropMain/kotlin/com/soywiz/korio/posix/PosixExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.soywiz.korio.posix | ||
|
||
import platform.posix.* | ||
import kotlinx.cinterop.* | ||
|
||
internal actual fun posixFread(__ptr: CValuesRef<*>?, __size: Long, __nitems: Long, __stream: CValuesRef<FILE>?): ULong { | ||
return fread(__ptr, __size.convert(), __nitems.convert(), __stream).convert() | ||
} | ||
|
||
internal actual fun posixFwrite(__ptr: CValuesRef<*>?, __size: Long, __nitems: Long, __stream: CValuesRef<FILE>?): ULong { | ||
return fwrite(__ptr, __size.convert(), __nitems.convert(), __stream).convert() | ||
} | ||
|
||
internal actual fun posixFseek(file: CValuesRef<FILE>?, offset: Long, whence: Int): Int { | ||
return fseek(file, offset.convert(), whence.convert()) | ||
} | ||
|
||
internal actual fun posixFtell(file: CValuesRef<FILE>?): ULong { | ||
return ftell(file).convert() | ||
} | ||
|
||
internal actual fun ioctlFionRead(sockfd: Int, ptr: CValuesRef<IntVar>) { | ||
ioctl(sockfd, FIONREAD, ptr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
korio/src/posixMain/kotlin/com/soywiz/korio/posix/PosixExtExpect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.soywiz.korio.posix | ||
|
||
import kotlinx.cinterop.* | ||
import platform.posix.* | ||
|
||
internal expect fun posixFread(__ptr: CValuesRef<*>?, __size: Long, __nitems: Long, __stream: CValuesRef<FILE>?): ULong | ||
internal expect fun posixFwrite(__ptr: CValuesRef<*>?, __size: Long, __nitems: Long, __stream: CValuesRef<FILE>?): ULong | ||
internal expect fun posixFseek(file: CValuesRef<FILE>?, offset: Long, whence: Int): Int | ||
internal expect fun posixFtell(file: CValuesRef<FILE>?): ULong | ||
internal expect fun ioctlFionRead(sockfd: Int, ptr: CValuesRef<IntVar>) |