diff --git a/c/os/_os/os.c b/c/os/_os/os.c new file mode 100644 index 00000000..af3c5085 --- /dev/null +++ b/c/os/_os/os.c @@ -0,0 +1,9 @@ +#include + +int llgo_clearenv() { + extern char **environ; + if (environ != NULL) { + *environ = NULL; + } + return 0; +} diff --git a/c/os/os.go b/c/os/os.go index 0d7d2001..7950f996 100644 --- a/c/os/os.go +++ b/c/os/os.go @@ -28,7 +28,8 @@ import ( ) const ( - LLGoPackage = "decl" + LLGoFiles = "_os/os.c" + LLGoPackage = "link" ) const ( @@ -150,9 +151,6 @@ func Putenv(env *c.Char) c.Int //go:linkname Unsetenv C.unsetenv func Unsetenv(name *c.Char) c.Int -//go:linkname Clearenv C.clearenv -func Clearenv() - // ----------------------------------------------------------------------------- //go:linkname Fchdir C.fchdir diff --git a/c/os/os_linux.go b/c/os/os_linux.go new file mode 100644 index 00000000..b58dc1e2 --- /dev/null +++ b/c/os/os_linux.go @@ -0,0 +1,24 @@ +//go:build linux + +/* + * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package os + +import "C" + +//go:linkname Clearenv C.clearenv +func Clearenv() diff --git a/c/os/os_other.go b/c/os/os_other.go new file mode 100644 index 00000000..138195fd --- /dev/null +++ b/c/os/os_other.go @@ -0,0 +1,24 @@ +//go:build !linux + +/* + * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package os + +import "C" + +//go:linkname Clearenv C.llgo_clearenv +func Clearenv()