Translated message

A translation of this page exists in English.

RHEL 8 以降、stdio 関数 (fgetc、fgets、getc、getchar) が常に EOF を返すのはなぜですか?

Solution In Progress - Updated -

Issue

  • RHEL 8 以降で、fgetc(3) やそれと同種の関数の戻り値が異なります。
  • 次のコード (test1.c) は RHEL 7 では動作しますが、RHEL 8 以降では動作しません。

    #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;
    }
    
  • RHEL 7 での結果:

    $ cc -o test1 test1.c
    $ ./test1
    s = (null)
    s = Hello, world!
    
  • RHEL 8 での結果:

    $ cc -o tes1t test1.c
    $ ./test1
    s = (null)
    s = (null)
    

Environment

  • Red Hat Enterprise Linux (RHEL) 8 以降

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content