Skip to content

Commit

Permalink
Fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
DrewCarlson committed Oct 29, 2024
1 parent 54ea2ae commit 1054f16
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
16 changes: 16 additions & 0 deletions src/commonMain/kotlin/ksubprocess/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ public expect object Environment : Map<String, String> {

/** true if the environment keys are case-insensitive */
public val caseInsensitive: Boolean

override fun containsKey(key: String): Boolean

override fun containsValue(value: String): Boolean

override val entries: Set<Map.Entry<String, String>>

override val keys: Set<String>

override val size: Int

override val values: Collection<String>

override fun isEmpty(): Boolean

override fun get(key: String): String?
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/jvmMain/kotlin/ksubprocess/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package ksubprocess
// this is just a thin wrapper around System.getenv()
public actual object Environment : AbstractMap<String, String>(), Map<String, String> {

override fun get(key: String): String? = System.getenv(key)
override fun containsKey(key: String): Boolean = System.getenv(key) != null
actual override fun get(key: String): String? = System.getenv(key)
actual override fun containsKey(key: String): Boolean = System.getenv(key) != null

override val entries: Set<Map.Entry<String, String>>
actual override val entries: Set<Map.Entry<String, String>>
get() = System.getenv().entries

public actual val caseInsensitive: Boolean by lazy {
Expand Down
6 changes: 3 additions & 3 deletions src/linuxMain/kotlin/ksubprocess/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ private data class EnvEntry(override val key: String, override val value: String
public actual object Environment : AbstractMap<String, String>(), Map<String, String> {

// fastpath get and contains through getenv
override fun containsKey(key: String): Boolean = getenv(key) != null
actual override fun containsKey(key: String): Boolean = getenv(key) != null

override fun get(key: String): String? = getenv(key)?.toKString()
actual override fun get(key: String): String? = getenv(key)?.toKString()

// also fastpath entries.contains
override val entries: Set<Map.Entry<String, String>> = object : AbstractSet<Map.Entry<String, String>>() {
actual override val entries: Set<Map.Entry<String, String>> = object : AbstractSet<Map.Entry<String, String>>() {
override fun contains(element: Map.Entry<String, String>): Boolean = get(element.key) == element.value

// only perform full scan if really needed
Expand Down
6 changes: 3 additions & 3 deletions src/windowsMain/kotlin/ksubprocess/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ private data class EnvEntry(override val key: String, override val value: String
@ThreadLocal
public actual object Environment : AbstractMap<String, String>(), Map<String, String> {
// fastpath get and contains through getenv
override fun containsKey(key: String): Boolean = _wgetenv(key.wcstr) != null
actual override fun containsKey(key: String): Boolean = _wgetenv(key.wcstr) != null

override fun get(key: String): String? = _wgetenv(key.wcstr)?.toKString()
actual override fun get(key: String): String? = _wgetenv(key.wcstr)?.toKString()

// also fastpath entries.contains
override val entries: Set<Map.Entry<String, String>> = object : AbstractSet<Map.Entry<String, String>>() {
actual override val entries: Set<Map.Entry<String, String>> = object : AbstractSet<Map.Entry<String, String>>() {
override fun contains(element: Map.Entry<String, String>): Boolean = get(element.key) == element.value

// only perform full scan if really needed
Expand Down

0 comments on commit 1054f16

Please sign in to comment.