Skip to content

Commit 135455c

Browse files
authored
Use the new LINUX constant in stdlib (#1270)
1 parent 17c0f8a commit 135455c

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

stdlib/errno.jou

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ if WINDOWS:
44
declare _errno() -> int*
55
elif MACOS:
66
declare __error() -> int*
7+
elif LINUX:
8+
declare __errno_location() -> int*
79
elif NETBSD:
810
declare __errno() -> int*
911
else:
10-
declare __errno_location() -> int*
12+
assert False # unsupported system
1113

1214

1315
@public
@@ -16,10 +18,12 @@ def set_errno(value: int) -> None:
1618
*_errno() = value
1719
elif MACOS:
1820
*__error() = value
21+
elif LINUX:
22+
*__errno_location() = value
1923
elif NETBSD:
2024
*__errno() = value
2125
else:
22-
*__errno_location() = value
26+
assert False
2327

2428

2529
@public
@@ -28,10 +32,12 @@ def get_errno() -> int:
2832
return *_errno()
2933
elif MACOS:
3034
return *__error()
35+
elif LINUX:
36+
return *__errno_location()
3137
elif NETBSD:
3238
return *__errno()
3339
else:
34-
return *__errno_location()
40+
assert False
3541

3642

3743
# Convert an error code into a string. Do not modify or free() the returned string.

stdlib/io.jou

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,17 @@ elif MACOS:
7070
declare global __stdinp: FILE*
7171
declare global __stdoutp: FILE*
7272
declare global __stderrp: FILE*
73+
elif LINUX:
74+
declare global stdin: FILE*
75+
declare global stdout: FILE*
76+
declare global stderr: FILE*
7377
elif NETBSD:
7478
if IS_32BIT:
7579
declare global __sF: byte[88][3] # sizeof(FILE) == 88
7680
else:
7781
declare global __sF: byte[152][3] # sizeof(FILE) == 152
7882
else:
79-
declare global stdin: FILE*
80-
declare global stdout: FILE*
81-
declare global stderr: FILE*
83+
assert False # unsupported system
8284

8385
# Returns stdin, the special file for reading keyboard input from terminal.
8486
@public
@@ -87,10 +89,12 @@ def get_stdin() -> FILE*:
8789
return __acrt_iob_func(0)
8890
elif MACOS:
8991
return __stdinp
92+
elif LINUX:
93+
return stdin
9094
elif NETBSD:
9195
return &__sF[0] as FILE*
9296
else:
93-
return stdin
97+
assert False
9498

9599
# Returns stdout, the special file for printing to terminal.
96100
@public
@@ -99,10 +103,12 @@ def get_stdout() -> FILE*:
99103
return __acrt_iob_func(1)
100104
elif MACOS:
101105
return __stdoutp
106+
elif LINUX:
107+
return stdout
102108
elif NETBSD:
103109
return &__sF[1] as FILE*
104110
else:
105-
return stdout
111+
assert False
106112

107113
# Returns stderr, the special file for showing error and warning messages.
108114
#
@@ -117,10 +123,12 @@ def get_stderr() -> FILE*:
117123
return __acrt_iob_func(2)
118124
elif MACOS:
119125
return __stderrp
126+
elif LINUX:
127+
return stderr
120128
elif NETBSD:
121129
return &__sF[2] as FILE*
122130
else:
123-
return stderr
131+
assert False
124132

125133
# Open/close a file for reading or writing. Mode can be e.g. "r", "w",
126134
# "a", "rb", "wb" or "ab". The meanings of these modes are as in many

0 commit comments

Comments
 (0)