146092Sbostic /*- 2*61180Sbostic * Copyright (c) 1990, 1993 3*61180Sbostic * The Regents of the University of California. All rights reserved. 446092Sbostic * 546092Sbostic * This code is derived from software contributed to Berkeley by 646092Sbostic * Chris Torek. 746092Sbostic * 846092Sbostic * %sccs.include.redist.c% 946092Sbostic */ 1046092Sbostic 1126656Sdonn #if defined(LIBC_SCCS) && !defined(lint) 12*61180Sbostic static char sccsid[] = "@(#)gets.c 8.1 (Berkeley) 06/04/93"; 1346092Sbostic #endif /* LIBC_SCCS and not lint */ 1422137Smckusick 1546092Sbostic #include <unistd.h> 1646092Sbostic #include <stdio.h> 172022Swnj 182022Swnj char * gets(buf)1946092Sbosticgets(buf) 2046092Sbostic char *buf; 212022Swnj { 2246092Sbostic register int c; 2346092Sbostic register char *s; 2446092Sbostic static int warned; 2546092Sbostic static char w[] = 2646092Sbostic "warning: this program uses gets(), which is unsafe.\r\n"; 272022Swnj 2846092Sbostic if (!warned) { 2946092Sbostic (void) write(STDERR_FILENO, w, sizeof(w) - 1); 3046092Sbostic warned = 1; 3146092Sbostic } 3246092Sbostic for (s = buf; (c = getchar()) != '\n';) 3346092Sbostic if (c == EOF) 3446092Sbostic if (s == buf) 3546092Sbostic return (NULL); 3646092Sbostic else 3746092Sbostic break; 3846092Sbostic else 3946092Sbostic *s++ = c; 4046092Sbostic *s = 0; 4146092Sbostic return (buf); 422022Swnj } 43