gets.c revision 110085
1228753Smm/*- 2228753Smm * Copyright (c) 1990, 1993 3228753Smm * The Regents of the University of California. All rights reserved. 4228753Smm * 5228753Smm * This code is derived from software contributed to Berkeley by 6228753Smm * Chris Torek. 7228753Smm * 8228753Smm * Redistribution and use in source and binary forms, with or without 9228753Smm * modification, are permitted provided that the following conditions 10228753Smm * are met: 11228753Smm * 1. Redistributions of source code must retain the above copyright 12228753Smm * notice, this list of conditions and the following disclaimer. 13228753Smm * 2. Redistributions in binary form must reproduce the above copyright 14228753Smm * notice, this list of conditions and the following disclaimer in the 15228753Smm * documentation and/or other materials provided with the distribution. 16228753Smm * 3. All advertising materials mentioning features or use of this software 17228753Smm * must display the following acknowledgement: 18228753Smm * This product includes software developed by the University of 19228753Smm * California, Berkeley and its contributors. 20228753Smm * 4. Neither the name of the University nor the names of its contributors 21228753Smm * may be used to endorse or promote products derived from this software 22228753Smm * without specific prior written permission. 23228753Smm * 24228753Smm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25228753Smm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26228753Smm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27228763Smm * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28228753Smm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29228753Smm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30228753Smm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31228753Smm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32228753Smm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33232153Smm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34228753Smm * SUCH DAMAGE. 35228753Smm */ 36228753Smm 37228753Smm#if defined(LIBC_SCCS) && !defined(lint) 38228753Smmstatic char sccsid[] = "@(#)gets.c 8.1 (Berkeley) 6/4/93"; 39228753Smm#endif /* LIBC_SCCS and not lint */ 40228753Smm#include <sys/cdefs.h> 41228753Smm__FBSDID("$FreeBSD: head/lib/libc/stdio/gets.c 110085 2003-01-30 12:00:26Z tjr $"); 42228753Smm 43228753Smm#include "namespace.h" 44228753Smm#include <stdio.h> 45228753Smm#include <sys/cdefs.h> 46228753Smm#include "un-namespace.h" 47302001Smm#include "libc_private.h" 48302001Smm#include "local.h" 49302001Smm 50302001Smm__warn_references(gets, "warning: this program uses gets(), which is unsafe."); 51228753Smm 52228753Smmchar * 53228753Smmgets(buf) 54228753Smm char *buf; 55228753Smm{ 56228753Smm int c; 57228753Smm char *s; 58228753Smm 59228753Smm FLOCKFILE(stdin); 60228753Smm ORIENT(stdin, -1); 61228753Smm for (s = buf; (c = __sgetc(stdin)) != '\n';) 62228753Smm if (c == EOF) 63228753Smm if (s == buf) { 64228753Smm FUNLOCKFILE(stdin); 65228753Smm return (NULL); 66228753Smm } else 67228753Smm break; 68228753Smm else 69228753Smm *s++ = c; 70232153Smm *s = 0; 71232153Smm FUNLOCKFILE(stdin); 72232153Smm return (buf); 73232153Smm} 74228753Smm