1*46092Sbostic /*- 2*46092Sbostic * Copyright (c) 1990 The Regents of the University of California. 3*46092Sbostic * All rights reserved. 4*46092Sbostic * 5*46092Sbostic * This code is derived from software contributed to Berkeley by 6*46092Sbostic * Chris Torek. 7*46092Sbostic * 8*46092Sbostic * %sccs.include.redist.c% 9*46092Sbostic */ 10*46092Sbostic 1126656Sdonn #if defined(LIBC_SCCS) && !defined(lint) 12*46092Sbostic static char sccsid[] = "@(#)gets.c 5.3 (Berkeley) 01/20/91"; 13*46092Sbostic #endif /* LIBC_SCCS and not lint */ 1422137Smckusick 15*46092Sbostic #include <unistd.h> 16*46092Sbostic #include <stdio.h> 172022Swnj 182022Swnj char * 19*46092Sbostic gets(buf) 20*46092Sbostic char *buf; 212022Swnj { 22*46092Sbostic register int c; 23*46092Sbostic register char *s; 24*46092Sbostic static int warned; 25*46092Sbostic static char w[] = 26*46092Sbostic "warning: this program uses gets(), which is unsafe.\r\n"; 272022Swnj 28*46092Sbostic if (!warned) { 29*46092Sbostic (void) write(STDERR_FILENO, w, sizeof(w) - 1); 30*46092Sbostic warned = 1; 31*46092Sbostic } 32*46092Sbostic for (s = buf; (c = getchar()) != '\n';) 33*46092Sbostic if (c == EOF) 34*46092Sbostic if (s == buf) 35*46092Sbostic return (NULL); 36*46092Sbostic else 37*46092Sbostic break; 38*46092Sbostic else 39*46092Sbostic *s++ = c; 40*46092Sbostic *s = 0; 41*46092Sbostic return (buf); 422022Swnj } 43