make it possible to compile new versions of db that load against
[unix-history] / usr / src / lib / libc / stdio / gets.c
CommitLineData
411867e7 1/*-
7860c229
KB
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
411867e7
KB
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * %sccs.include.redist.c%
9 */
10
2ce81398 11#if defined(LIBC_SCCS) && !defined(lint)
7860c229 12static char sccsid[] = "@(#)gets.c 8.1 (Berkeley) %G%";
411867e7 13#endif /* LIBC_SCCS and not lint */
b8f253e8 14
411867e7
KB
15#include <unistd.h>
16#include <stdio.h>
c3d4b9ff
BJ
17
18char *
411867e7
KB
19gets(buf)
20 char *buf;
c3d4b9ff 21{
411867e7
KB
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";
c3d4b9ff 27
411867e7
KB
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);
c3d4b9ff 42}