getline < directory returns zero
Both the POSIX spec and the OTA man page state that getline returns -1 for an error, but in practice OTA getline returns 0 when attempting to read from a directory. Despite the misleading 0 return value, it prints an error to stderr.
```
$ ./awk --version
awk version 20240728
$ ./awk 'BEGIN { x = (getline < "/"); print x }' # would expect this to print -1
0
./awk: i/o error occurred on /
source line number 1
```
关闭于 2025-01-05 2 条评论