File tree Expand file tree Collapse file tree 3 files changed +24
-18
lines changed
mingw/src/aws/smithy/kotlin/runtime/util
native/src/aws/smithy/kotlin/runtime/util
posix/src/aws/smithy/kotlin/runtime/util Expand file tree Collapse file tree 3 files changed +24
-18
lines changed Original file line number Diff line number Diff line change @@ -10,11 +10,20 @@ import kotlinx.cinterop.*
1010import platform.posix.environ
1111import platform.posix.memcpy
1212
13- internal actual val rawEnvironmentVariables: CPointer <CPointerVarOf <CPointer <ByteVarOf <Byte >>>>? = environ
14-
1513public actual object SystemDefaultProvider : SystemDefaultProviderBase() {
1614 actual override val filePathSeparator: String = " \\ "
1715 actual override fun osInfo (): OperatingSystem = OperatingSystem (OsFamily .Windows , osVersionFromKernel())
16+
17+ actual override fun getAllEnvVars (): Map <String , String > = memScoped {
18+ generateSequence(0 ) { it + 1 }
19+ .map { idx -> environ.get(idx)?.toKString() }
20+ .takeWhile { it != null }
21+ .associate { env ->
22+ val parts = env?.split(" =" , limit = 2 )
23+ check(parts?.size == 2 ) { " Environment entry \" $env \" is malformed" }
24+ parts[0 ] to parts[1 ]
25+ }
26+ }
1827}
1928
2029// The functions below are adapted from C++ SDK:
Original file line number Diff line number Diff line change @@ -10,20 +10,7 @@ import kotlinx.cinterop.*
1010import kotlinx.coroutines.withContext
1111import platform.posix.*
1212
13- internal expect val rawEnvironmentVariables: CPointer <CPointerVarOf <CPointer <ByteVarOf <Byte >>>>?
14-
1513public abstract class SystemDefaultProviderBase : PlatformProvider {
16- override fun getAllEnvVars (): Map <String , String > = memScoped {
17- generateSequence(0 ) { it + 1 }
18- .map { idx -> rawEnvironmentVariables?.get(idx)?.toKString() }
19- .takeWhile { it != null }
20- .associate { env ->
21- val parts = env?.split(" =" , limit = 2 )
22- check(parts?.size == 2 ) { " Environment entry \" $env \" is malformed" }
23- parts[0 ] to parts[1 ]
24- }
25- }
26-
2714 override fun getenv (key : String ): String? = platform.posix.getenv(key)?.toKString()
2815
2916 override suspend fun readFileOrNull (path : String ): ByteArray? = withContext(SdkDispatchers .IO ) {
Original file line number Diff line number Diff line change 55package aws.smithy.kotlin.runtime.util
66
77import kotlinx.cinterop.*
8- import platform.posix.__environ
8+ import aws.smithy. platform.posix.get_environ_ptr
99import platform.posix.uname
1010import platform.posix.utsname
1111
12- internal actual val rawEnvironmentVariables: CPointer <CPointerVarOf <CPointer <ByteVarOf <Byte >>>>? = __environ
13-
1412public actual object SystemDefaultProvider : SystemDefaultProviderBase() {
1513 actual override val filePathSeparator: String = " /"
1614
@@ -39,4 +37,16 @@ public actual object SystemDefaultProvider : SystemDefaultProviderBase() {
3937
4038 return OperatingSystem (family, version)
4139 }
40+
41+ actual override fun getAllEnvVars (): Map <String , String > = memScoped {
42+ val environ = get_environ_ptr()
43+ generateSequence(0 ) { it + 1 }
44+ .map { idx -> environ?.get(idx)?.toKString() }
45+ .takeWhile { it != null }
46+ .associate { env ->
47+ val parts = env?.split(" =" , limit = 2 )
48+ check(parts?.size == 2 ) { " Environment entry \" $env \" is malformed" }
49+ parts[0 ] to parts[1 ]
50+ }
51+ }
4252}
You can’t perform that action at this time.
0 commit comments