-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# C's errno is actually a macro that expands to a function call. | ||
# See also _windows_startup.jou | ||
declare __errno_location() -> int* | ||
|
||
def set_errno(value: int) -> void: | ||
*__errno_location() = value | ||
|
||
def get_errno() -> int: | ||
return *__errno_location() | ||
|
||
# Convert an error code into a string. Do not modify or free() the returned string. | ||
declare strerror(errno_value: int) -> byte* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import "stdlib/io.jou" | ||
import "stdlib/errno.jou" | ||
|
||
def main() -> int: | ||
# Avoid printing strerror(0) because it is platform-specific | ||
printf("%d\n", get_errno()) # Output: 0 | ||
|
||
fopen("this does not exist.txt", "r") | ||
printf("%d %s\n", get_errno(), strerror(get_errno())) # Output: 2 No such file or directory | ||
|
||
set_errno(0) | ||
printf("%d\n", get_errno()) # Output: 0 | ||
|
||
set_errno(2) | ||
printf("%d %s\n", get_errno(), strerror(get_errno())) # Output: 2 No such file or directory | ||
|
||
return 0 |