os:fix os.Errno 's nil pointer derefer in linux #828
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix #825
The panic was in the use
os.Errno
.in the generate ir in llgo like this demo.
will cause follow error
we can see the marcos define the errno is actually call the__errno_location. in linux
in macos is call __error
so we need another way to get the errno
so,by wrapping the errno macro in a C function, we can obtain the actual errno value through a function call across different platforms.
result
we can get expected result of os.Errno's use
In this demo, when attempting to open a non-existent file, the program uses os.Error to retrieve the actual reason for the operation failure. This tests whether os.Error() is correctly referenced and functioning. The output showing "No such file or directory" confirms that the errno handling is working as expected across different platforms.
macos
❯ llgo run . noexist: stat /var/folders/5j/sgtxqmbn1hbdqtgx5kkp6y700000gn/T/noexist.txt: No such file or directory noexist: open /var/folders/5j/sgtxqmbn1hbdqtgx5kkp6y700000gn/T/noexist.txt: No such file or directory
linux