Closed luoliwoshang closed 1 month ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 97.47%. Comparing base (
9ea88fe
) to head (e9177c8
). Report is 8 commits behind head on main.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
please review @visualfc. If os.Errno has bugs, it means os.Stdout/Stderr also has bugs.
please review @visualfc. If os.Errno has bugs, it means os.Stdout/Stderr also has bugs.
os.Stdout/Stderr/Stdin works normally both in macos & linux
package main
import (
"io"
"fmt"
"os"
)
func main() {
fmt.Println("Message 1")
fmt.Fprintln(os.Stdout, "Message 2")
fmt.Fprintln(os.Stderr, "Message 3")
input, err := io.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintf(os.Stderr, "Error reading input: %v\n", err)
return
}
fmt.Fprintf(os.Stdout, "You entered:\n%s", input)
}
root@be00d9b1c2c9:~/llgo/_demo/stdout# echo "Hello, World!" | llgo run demo.go
Message 1
Message 2
Message 3
You entered:
Hello, World!
root@be00d9b1c2c9:~/llgo/_demo/stdout# echo "Hello, World!" | go run demo.go
Message 1
Message 2
Message 3
You entered:
Hello, World!
please review @visualfc. If os.Errno has bugs, it means os.Stdout/Stderr also has bugs.
/usr/include/stdio.h
/* Standard streams. */
extern FILE *stdin; /* Standard input stream. */
extern FILE *stdout; /* Standard output stream. */
extern FILE *stderr; /* Standard error output stream. */
/* C89/C99 say they're macros. Make them happy. */
#define stdin stdin
#define stdout stdout
#define stderr stderr
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
linux