Back to index

glibc  2.9
Functions
iogets.c File Reference
#include "libioP.h"
#include <limits.h>

Go to the source code of this file.

Functions

char * _IO_gets (char *buf)

Function Documentation

char* _IO_gets ( char *  buf)

Definition at line 32 of file iogets.c.

{
  _IO_size_t count;
  int ch;
  char *retval;

  _IO_acquire_lock (_IO_stdin);
  ch = _IO_getc_unlocked (_IO_stdin);
  if (ch == EOF)
    {
      retval = NULL;
      goto unlock_return;
    }
  if (ch == '\n')
    count = 0;
  else
    {
      /* 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 = _IO_stdin->_IO_file_flags & _IO_ERR_SEEN;
      _IO_stdin->_IO_file_flags &= ~_IO_ERR_SEEN;
      buf[0] = (char) ch;
      count = INTUSE(_IO_getline) (_IO_stdin, buf + 1, INT_MAX, '\n', 0) + 1;
      if (_IO_stdin->_IO_file_flags & _IO_ERR_SEEN)
       {
         retval = NULL;
         goto unlock_return;
       }
      else
       _IO_stdin->_IO_file_flags |= old_error;
    }
  buf[count] = 0;
  retval = buf;
unlock_return:
  _IO_release_lock (_IO_stdin);
  return retval;
}

Here is the call graph for this function: