Back to index

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

Go to the source code of this file.


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

Function Documentation

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

Definition at line 34 of file fgets_u_chk.c.

  _IO_size_t count;
  char *result;
  if (n <= 0)
    return NULL;
  /* 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;
  return result;

Here is the call graph for this function: