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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [stdio/] [gets.c] - Blame information for rev 309

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/*
2
 * Copyright (c) 1990 The Regents of the University of California.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms are permitted
6
 * provided that the above copyright notice and this paragraph are
7
 * duplicated in all such forms and that any documentation,
8
 * advertising materials, and other materials related to such
9
 * distribution and use acknowledge that the software was developed
10
 * by the University of California, Berkeley.  The name of the
11
 * University may not be used to endorse or promote products derived
12
 * from this software without specific prior written permission.
13
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
 
18
/*
19
FUNCTION
20
<<gets>>---get character string (obsolete, use <<fgets>> instead)
21
 
22
INDEX
23
        gets
24
INDEX
25
        _gets_r
26
 
27
ANSI_SYNOPSIS
28
        #include <stdio.h>
29
 
30
        char *gets(char *<[buf]>);
31
 
32
        char *_gets_r(struct _reent *<[reent]>, char *<[buf]>);
33
 
34
TRAD_SYNOPSIS
35
        #include <stdio.h>
36
 
37
        char *gets(<[buf]>)
38
        char *<[buf]>;
39
 
40
        char *_gets_r(<[reent]>, <[buf]>)
41
        struct _reent *<[reent]>;
42
        char *<[buf]>;
43
 
44
DESCRIPTION
45
        Reads characters from standard input until a newline is found.
46
        The characters up to the newline are stored in <[buf]>. The
47
        newline is discarded, and the buffer is terminated with a 0.
48
 
49
        This is a @emph{dangerous} function, as it has no way of checking
50
        the amount of space available in <[buf]>. One of the attacks
51
        used by the Internet Worm of 1988 used this to overrun a
52
        buffer allocated on the stack of the finger daemon and
53
        overwrite the return address, causing the daemon to execute
54
        code downloaded into it over the connection.
55
 
56
        The alternate function <<_gets_r>> is a reentrant version.  The extra
57
        argument <[reent]> is a pointer to a reentrancy structure.
58
 
59
 
60
RETURNS
61
        <<gets>> returns the buffer passed to it, with the data filled
62
        in. If end of file occurs with some data already accumulated,
63
        the data is returned with no other indication. If end of file
64
        occurs with no data in the buffer, NULL is returned.
65
 
66
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
67
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
68
*/
69
 
70
#include <_ansi.h>
71
#include <reent.h>
72
#include <stdio.h>
73
 
74
char *
75
_DEFUN(_gets_r, (ptr, buf),
76
       struct _reent *ptr _AND
77
       char *buf)
78
{
79
  register int c;
80
  register char *s = buf;
81
 
82
  __sfp_lock_acquire ();
83
  _flockfile (stdin);
84
  while ((c = __sgetc_r (ptr, stdin)) != '\n')
85
    if (c == EOF)
86
      if (s == buf)
87
        {
88
          _funlockfile (stdin);
89
          __sfp_lock_release ();
90
          return NULL;
91
        }
92
      else
93
        break;
94
    else
95
      *s++ = c;
96
  *s = 0;
97
  _funlockfile (stdin);
98
  __sfp_lock_release ();
99
  return buf;
100
}
101
 
102
#ifndef _REENT_ONLY
103
 
104
char *
105
_DEFUN(gets, (buf),
106
       char *buf)
107
{
108
  return _gets_r (_REENT, buf);
109
}
110
 
111
#endif

powered by: WebSVN 2.1.0

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