OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc2/] [newlib/] [libc/] [stdio/] [gets.c] - Diff between revs 207 and 520

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 520
/*
/*
 * Copyright (c) 1990 The Regents of the University of California.
 * Copyright (c) 1990 The Regents of the University of California.
 * All rights reserved.
 * All rights reserved.
 *
 *
 * Redistribution and use in source and binary forms are permitted
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * distribution and use acknowledge that the software was developed
 * by the University of California, Berkeley.  The name of the
 * by the University of California, Berkeley.  The name of the
 * University may not be used to endorse or promote products derived
 * University may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 * from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */
 */
 
 
/*
/*
FUNCTION
FUNCTION
<<gets>>---get character string (obsolete, use <<fgets>> instead)
<<gets>>---get character string (obsolete, use <<fgets>> instead)
 
 
INDEX
INDEX
        gets
        gets
INDEX
INDEX
        _gets_r
        _gets_r
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <stdio.h>
        #include <stdio.h>
 
 
        char *gets(char *<[buf]>);
        char *gets(char *<[buf]>);
 
 
        char *_gets_r(struct _reent *<[reent]>, char *<[buf]>);
        char *_gets_r(struct _reent *<[reent]>, char *<[buf]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <stdio.h>
        #include <stdio.h>
 
 
        char *gets(<[buf]>)
        char *gets(<[buf]>)
        char *<[buf]>;
        char *<[buf]>;
 
 
        char *_gets_r(<[reent]>, <[buf]>)
        char *_gets_r(<[reent]>, <[buf]>)
        struct _reent *<[reent]>;
        struct _reent *<[reent]>;
        char *<[buf]>;
        char *<[buf]>;
 
 
DESCRIPTION
DESCRIPTION
        Reads characters from standard input until a newline is found.
        Reads characters from standard input until a newline is found.
        The characters up to the newline are stored in <[buf]>. The
        The characters up to the newline are stored in <[buf]>. The
        newline is discarded, and the buffer is terminated with a 0.
        newline is discarded, and the buffer is terminated with a 0.
 
 
        This is a @emph{dangerous} function, as it has no way of checking
        This is a @emph{dangerous} function, as it has no way of checking
        the amount of space available in <[buf]>. One of the attacks
        the amount of space available in <[buf]>. One of the attacks
        used by the Internet Worm of 1988 used this to overrun a
        used by the Internet Worm of 1988 used this to overrun a
        buffer allocated on the stack of the finger daemon and
        buffer allocated on the stack of the finger daemon and
        overwrite the return address, causing the daemon to execute
        overwrite the return address, causing the daemon to execute
        code downloaded into it over the connection.
        code downloaded into it over the connection.
 
 
        The alternate function <<_gets_r>> is a reentrant version.  The extra
        The alternate function <<_gets_r>> is a reentrant version.  The extra
        argument <[reent]> is a pointer to a reentrancy structure.
        argument <[reent]> is a pointer to a reentrancy structure.
 
 
 
 
RETURNS
RETURNS
        <<gets>> returns the buffer passed to it, with the data filled
        <<gets>> returns the buffer passed to it, with the data filled
        in. If end of file occurs with some data already accumulated,
        in. If end of file occurs with some data already accumulated,
        the data is returned with no other indication. If end of file
        the data is returned with no other indication. If end of file
        occurs with no data in the buffer, NULL is returned.
        occurs with no data in the buffer, NULL is returned.
 
 
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
*/
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <reent.h>
#include <reent.h>
#include <stdio.h>
#include <stdio.h>
 
 
char *
char *
_DEFUN(_gets_r, (ptr, buf),
_DEFUN(_gets_r, (ptr, buf),
       struct _reent *ptr _AND
       struct _reent *ptr _AND
       char *buf)
       char *buf)
{
{
  register int c;
  register int c;
  register char *s = buf;
  register char *s = buf;
 
 
  __sfp_lock_acquire ();
  __sfp_lock_acquire ();
  _flockfile (stdin);
  _flockfile (stdin);
  while ((c = __sgetc_r (ptr, stdin)) != '\n')
  while ((c = __sgetc_r (ptr, stdin)) != '\n')
    if (c == EOF)
    if (c == EOF)
      if (s == buf)
      if (s == buf)
        {
        {
          _funlockfile (stdin);
          _funlockfile (stdin);
          __sfp_lock_release ();
          __sfp_lock_release ();
          return NULL;
          return NULL;
        }
        }
      else
      else
        break;
        break;
    else
    else
      *s++ = c;
      *s++ = c;
  *s = 0;
  *s = 0;
  _funlockfile (stdin);
  _funlockfile (stdin);
  __sfp_lock_release ();
  __sfp_lock_release ();
  return buf;
  return buf;
}
}
 
 
#ifndef _REENT_ONLY
#ifndef _REENT_ONLY
 
 
char *
char *
_DEFUN(gets, (buf),
_DEFUN(gets, (buf),
       char *buf)
       char *buf)
{
{
  return _gets_r (_REENT, buf);
  return _gets_r (_REENT, buf);
}
}
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.