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