Skip to content

Commit 004584f

Browse files
committed
fix: define all errno consts
Signed-off-by: Christian Stewart <[email protected]>
1 parent 4ab6935 commit 004584f

File tree

7 files changed

+849
-207
lines changed

7 files changed

+849
-207
lines changed

gs/syscall/constants.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Essential syscall constants
2+
export const O_RDONLY = 0
3+
export const O_WRONLY = 1
4+
export const O_RDWR = 2
5+
export const O_APPEND = 8
6+
export const O_CREATE = 64
7+
export const O_EXCL = 128
8+
export const O_SYNC = 256
9+
export const O_TRUNC = 512
10+
11+
export const Stdin = 0
12+
export const Stdout = 1
13+
export const Stderr = 2
14+
15+
export const SIGINT = 2
16+
export const SIGTERM = 15
17+
18+
// File mode constants
19+
export const S_IFMT = 0o170000
20+
export const S_IFREG = 0o100000
21+
export const S_IFDIR = 0o040000
22+
export const S_IFLNK = 0o120000
23+
export const S_IFBLK = 0o060000
24+
export const S_IFCHR = 0o020000
25+
export const S_IFIFO = 0o010000
26+
export const S_IFSOCK = 0o140000
27+
export const S_ISUID = 0o004000
28+
export const S_ISGID = 0o002000
29+
export const S_ISVTX = 0o001000

gs/syscall/env.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as $ from '@goscript/builtin/index.js'
2+
3+
// Environment variable functions using Node.js/browser APIs
4+
export function Getenv(key: string): [string, boolean] {
5+
if (typeof process !== 'undefined' && process.env) {
6+
const value = process.env[key]
7+
return value !== undefined ? [value, true] : ['', false]
8+
}
9+
return ['', false]
10+
}
11+
12+
export function Setenv(key: string, value: string): $.GoError {
13+
if (typeof process !== 'undefined' && process.env) {
14+
process.env[key] = value
15+
return null
16+
}
17+
return { Error: () => 'setenv not supported' }
18+
}
19+
20+
export function Unsetenv(key: string): $.GoError {
21+
if (typeof process !== 'undefined' && process.env) {
22+
delete process.env[key]
23+
return null
24+
}
25+
return { Error: () => 'unsetenv not supported' }
26+
}
27+
28+
export function Clearenv(): void {
29+
if (typeof process !== 'undefined' && process.env) {
30+
for (const key in process.env) {
31+
delete process.env[key]
32+
}
33+
}
34+
}
35+
36+
export function Environ(): $.Slice<string> {
37+
if (typeof process !== 'undefined' && process.env) {
38+
const env: string[] = []
39+
for (const [key, value] of Object.entries(process.env)) {
40+
if (value !== undefined) {
41+
env.push(`${key}=${value}`)
42+
}
43+
}
44+
return $.arrayToSlice(env)
45+
}
46+
return $.arrayToSlice([])
47+
}

0 commit comments

Comments
 (0)