Search code examples
cstdiolibc

I cannot find the ungetcflag member of FILE structure according to fgetc(FILE*) implementation


This is the implementation of the function int fgetc(FILE* fp) according to this link. mirror.fsf.org

#include <stdio.h>
#include <unistd.h>

/**  fgetc(fp) -- get char from stream */

int fgetc(FILE *fp)
{
    char c;

    if (fp->ungetcflag) {
        fp->ungetcflag = 0;
        return (fp->ungetchar);
    }
    if (read (fp->fd, &c, 1) == 0)
        return (EOF);
    return (c);
}

I tried looking at the definition of FILE in stdio.h and google and I couldn't find the member ungetcflag or ungetchar.

What is the meaning of this?


Solution

  • @Antti Haapala comment good enough for an answer.

    That is one implementation of fgetc(), not the implementation of fgetc)_.
    Specifically it is not the implementation of fgetc() that is your libc, hence the code does not match the FILE definition in your <stdio.h>.