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