Why do stdio functions (fgetc, fgets, getc, getchar) always return EOF in RHEL 8 and later?
Issue
- Different return value of fgetc(3) and sibling functions, since RHEL 8
-
The following code (
test1.c
) works on RHEL 7 but not on RHEL 8 and later#include <stdio.h> int main(int argc, char *argv[]) { char buffer[1024]; char *str; FILE *fptr_w = fopen("data", "w"); FILE *fptr_r = fopen("data", "r"); fprintf(fptr_w, "%s", "Hello, world!"); str = fgets(buffer, 1024, fptr_r); printf("s = %s\n", str); fflush(fptr_w); str = fgets(buffer, 1024, fptr_r); printf("s = %s\n", str); return 0; }
-
Result on RHEL 7:
$ cc -o test1 test1.c $ ./test1 s = (null) s = Hello, world!
-
Result on RHEL 8:
$ cc -o tes1t test1.c $ ./test1 s = (null) s = (null)
Environment
- Red Hat Enterprise Linux (RHEL) 8 and later
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.