Back to index

glibc  2.9
fgets_chk.c File Reference
#include "libioP.h"
#include <stdio.h>
#include <sys/param.h>

Go to the source code of this file.


char * __fgets_chk (char *buf, size_t size, int n, _IO_FILE *fp)

Function Documentation

char* __fgets_chk ( char *  buf,
size_t  size,
int  n,
_IO_FILE fp 

Definition at line 34 of file fgets_chk.c.

  _IO_size_t count;
  char *result;
  if (n <= 0)
    return NULL;
  _IO_acquire_lock (fp);
  /* This is very tricky since a file descriptor may be in the
     non-blocking mode. The error flag doesn't mean much in this
     case. We return an error only when there is a new error. */
  int old_error = fp->_IO_file_flags & _IO_ERR_SEEN;
  fp->_IO_file_flags &= ~_IO_ERR_SEEN;
  count = INTUSE(_IO_getline) (fp, buf, MIN ((size_t) n - 1, size), '\n', 1);
  /* If we read in some bytes and errno is EAGAIN, that error will
     be reported for next read. */
  if (count == 0 || ((fp->_IO_file_flags & _IO_ERR_SEEN)
                   && errno != EAGAIN))
    result = NULL;
  else if (count >= size)
    __chk_fail ();
      buf[count] = '\0';
      result = buf;
  fp->_IO_file_flags |= old_error;
  _IO_release_lock (fp);
  return result;

Here is the call graph for this function:

Here is the caller graph for this function: