Skip to content

Commit d55f3bc

Browse files
committed
Remove expect/actual statSizeOrNull
1 parent aaa7e26 commit d55f3bc

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

runtime/runtime-core/mingw/src/aws/smithy/kotlin/runtime/util/SystemDefaultProviderMingw.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ package aws.smithy.kotlin.runtime.util
88
import aws.sdk.kotlin.crt.util.osVersionFromKernel
99
import kotlinx.cinterop.*
1010
import platform.posix.environ
11-
import platform.posix.stat
12-
13-
@OptIn(ExperimentalForeignApi::class)
14-
internal actual fun statSizeOrNull(path: String): Long? = memScoped {
15-
val st = alloc<stat>()
16-
if (stat(path, st.ptr) != 0) return null
17-
st.st_size.toLong()
18-
}
1911

2012
public actual object SystemDefaultProvider : SystemDefaultProviderBase() {
2113
actual override val filePathSeparator: String = "\\"

runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/util/SystemDefaultProviderBase.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,25 @@ import kotlinx.cinterop.*
1010
import kotlinx.coroutines.withContext
1111
import platform.posix.*
1212

13-
// Required because stat->st_size has varying widths across platforms
14-
// Without this, get an error:
15-
// "The declaration is using numbers with different bit widths in least two actual platforms. Such types shall not be used in user-defined 'expect fun' signature"
16-
internal expect fun statSizeOrNull(path: String): Long?
17-
1813
@OptIn(ExperimentalForeignApi::class)
1914
public abstract class SystemDefaultProviderBase : PlatformProvider {
2015
override fun getenv(key: String): String? = platform.posix.getenv(key)?.toKString()
2116

17+
2218
override suspend fun readFileOrNull(path: String): ByteArray? = withContext(SdkDispatchers.IO) {
2319
try {
24-
val size = statSizeOrNull(path) ?: return@withContext null
20+
val size = memScoped {
21+
val statResult = alloc<stat>()
22+
if (stat(path, statResult.ptr) != 0) return@withContext null
23+
@OptIn(UnsafeNumber::class)
24+
statResult.st_size.convert<Int>()
25+
}
26+
2527
val file = fopen(path, "rb") ?: return@withContext null
2628

2729
try {
2830
// Read file content
29-
val buffer = ByteArray(size.toInt()).pin()
31+
val buffer = ByteArray(size).pin()
3032
val rc = fread(buffer.addressOf(0), 1uL, size.toULong(), file)
3133
if (rc == size.toULong()) buffer.get() else null
3234
} finally {

runtime/runtime-core/posix/src/aws/smithy/kotlin/runtime/util/SystemDefaultProviderPosix.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,9 @@ package aws.smithy.kotlin.runtime.util
66

77
import aws.smithy.platform.posix.get_environ_ptr
88
import kotlinx.cinterop.*
9-
import platform.posix.stat
109
import platform.posix.uname
1110
import platform.posix.utsname
1211

13-
@OptIn(ExperimentalForeignApi::class)
14-
internal actual fun statSizeOrNull(path: String): Long? = memScoped {
15-
val st = alloc<stat>()
16-
if (stat(path, st.ptr) != 0) return null
17-
st.st_size.toLong()
18-
}
19-
2012
@OptIn(ExperimentalForeignApi::class)
2113
public actual object SystemDefaultProvider : SystemDefaultProviderBase() {
2214
actual override val filePathSeparator: String = "/"

0 commit comments

Comments
 (0)