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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [stdio/] [gets.c] - Blame information for rev 1773

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

Line No. Rev Author Line
1 1010 ivang
/*
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
/*
20
 
21
FUNCTION
22
        <<gets>>---get character string (obsolete, use <<fgets>> instead)
23
INDEX
24
        gets
25
INDEX
26
        _gets_r
27
 
28
ANSI_SYNOPSIS
29
        #include <stdio.h>
30
 
31
        char *gets(char *<[buf]>);
32
 
33
        char *_gets_r(void *<[reent]>, char *<[buf]>);
34
 
35
TRAD_SYNOPSIS
36
        #include <stdio.h>
37
 
38
        char *gets(<[buf]>)
39
        char *<[buf]>;
40
 
41
        char *_gets_r(<[reent]>, <[buf]>)
42
        char *<[reent]>;
43
        char *<[buf]>;
44
 
45
DESCRIPTION
46
        Reads characters from standard input until a newline is found.
47
        The characters up to the newline are stored in <[buf]>. The
48
        newline is discarded, and the buffer is terminated with a 0.
49
 
50
        This is a @emph{dangerous} function, as it has no way of checking
51
        the amount of space available in <[buf]>. One of the attacks
52
        used by the Internet Worm of 1988 used this to overrun a
53
        buffer allocated on the stack of the finger daemon and
54
        overwrite the return address, causing the daemon to execute
55
        code downloaded into it over the connection.
56
 
57
        The alternate function <<_gets_r>> is a reentrant version.  The extra
58
        argument <[reent]> is a pointer to a reentrancy structure.
59
 
60
 
61
RETURNS
62
        <<gets>> returns the buffer passed to it, with the data filled
63
        in. If end of file occurs with some data already accumulated,
64
        the data is returned with no other indication. If end of file
65
        occurs with no data in the buffer, NULL is returned.
66
 
67
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
68
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
69
*/
70
 
71
#include <stdio.h>
72
 
73
char *
74
_gets_r (ptr, buf)
75
     struct _reent *ptr;
76
     char *buf;
77
{
78
  register int c;
79
  register char *s = buf;
80
 
81
  while ((c = _getchar_r (ptr)) != '\n')
82
    if (c == EOF)
83
      if (s == buf)
84
        return NULL;
85
      else
86
        break;
87
    else
88
      *s++ = c;
89
  *s = 0;
90
  return buf;
91
}
92
 
93
#ifndef _REENT_ONLY
94
 
95
char *
96
gets (buf)
97
     char *buf;
98
{
99
  return _gets_r (_REENT, buf);
100
}
101
 
102
#endif

powered by: WebSVN 2.1.0

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