mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 13:07:26 +01:00
b6ed95750b
Closes #2451
27 lines
553 B
Go
27 lines
553 B
Go
// SPDX-License-Identifier: MIT
|
|
// SPDX-FileCopyrightText: 2014 Eric Woroshow
|
|
|
|
//go:build darwin || windows
|
|
|
|
package gl
|
|
|
|
import (
|
|
"runtime"
|
|
)
|
|
|
|
// cStr takes a Go string (with or without null-termination)
|
|
// and returns the C counterpart.
|
|
//
|
|
// The returned free function must be called once you are done using the string
|
|
// in order to free the memory.
|
|
func cStr(str string) (cstr *byte, free func()) {
|
|
bs := []byte(str)
|
|
if len(bs) == 0 || bs[len(bs)-1] != 0 {
|
|
bs = append(bs, 0)
|
|
}
|
|
return &bs[0], func() {
|
|
runtime.KeepAlive(bs)
|
|
bs = nil
|
|
}
|
|
}
|