summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2014-03-23 23:15:59 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2014-03-23 23:15:59 +0000
commit15f4b66570ccd026d6e07c4b4990ce4ea88d04db (patch)
treefc8813df5692cbc7e178ad6d3dc4d20f162883ab /lib/libc
parent762ab64a7afb120e33cf244876d831e03064212b (diff)
c11 compliance: remove gets()
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdio/Makefile.inc5
-rw-r--r--lib/libc/stdio/fgets.365
-rw-r--r--lib/libc/stdio/gets.c59
3 files changed, 12 insertions, 117 deletions
diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc
index 802e96b568b..cc18c817475 100644
--- a/lib/libc/stdio/Makefile.inc
+++ b/lib/libc/stdio/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.24 2013/03/28 16:37:13 eric Exp $
+# $OpenBSD: Makefile.inc,v 1.25 2014/03/23 23:15:58 tedu Exp $
# stdio sources
.PATH: ${LIBCSRCDIR}/stdio
@@ -9,7 +9,7 @@ SRCS+= asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c fgetc.c \
fgetln.c fgetpos.c fgets.c fileno.c findfp.c flags.c fmemopen.c \
fopen.c fprintf.c fpurge.c fputc.c fputs.c fread.c freopen.c fscanf.c \
fseek.c fsetpos.c ftell.c funopen.c fvwrite.c fwalk.c fwrite.c \
- getc.c getchar.c gets.c getw.c makebuf.c mktemp.c open_memstream.c \
+ getc.c getchar.c getw.c makebuf.c mktemp.c open_memstream.c \
open_wmemstream.c perror.c printf.c putc.c putchar.c puts.c putw.c \
refill.c remove.c rewind.c rget.c scanf.c setbuf.c setbuffer.c \
setvbuf.c snprintf.c sprintf.c sscanf.c stdio.c tempnam.c tmpfile.c \
@@ -29,7 +29,6 @@ MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fmemopen.3 fopen.3 fputs.3 \
MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3
MLINKS+=fflush.3 fpurge.3
-MLINKS+=fgets.3 gets.3
MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3
MLINKS+=fputs.3 puts.3
MLINKS+=fread.3 fwrite.3
diff --git a/lib/libc/stdio/fgets.3 b/lib/libc/stdio/fgets.3
index 56d6a703148..1e956610ea2 100644
--- a/lib/libc/stdio/fgets.3
+++ b/lib/libc/stdio/fgets.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: fgets.3,v 1.31 2013/07/17 05:42:11 schwarze Exp $
+.\" $OpenBSD: fgets.3,v 1.32 2014/03/23 23:15:58 tedu Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -31,19 +31,16 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: July 17 2013 $
+.Dd $Mdocdate: March 23 2014 $
.Dt FGETS 3
.Os
.Sh NAME
-.Nm fgets ,
-.Nm gets
+.Nm fgets
.Nd get a line from a stream
.Sh SYNOPSIS
.In stdio.h
.Ft char *
.Fn fgets "char *str" "int size" "FILE *stream"
-.Ft char *
-.Fn gets "char *str"
.Sh DESCRIPTION
The
.Fn fgets
@@ -61,36 +58,17 @@ The string will be NUL-terminated if
succeeds; otherwise the contents of
.Fa str
are undefined.
-.Pp
-The
-.Fn gets
-function is equivalent to
-.Fn fgets
-with an infinite
-.Ar size
-and a
-.Fa stream
-of
-.Em stdin ,
-except that the newline character (if any) is not stored in the string.
-It is the caller's responsibility to ensure that the input line,
-if any, is sufficiently short to fit in the string.
.Sh RETURN VALUES
Upon successful completion,
.Fn fgets
-and
-.Fn gets
-return
-a pointer to the string.
+returns a pointer to the string.
If end-of-file or an error occurs before any characters are read,
-they return
+it returns
.Dv NULL .
The
.Fn fgets
-and
-.Fn gets
-functions
-do not distinguish between end-of-file and error, and callers must use
+function does not distinguish between end-of-file and error,
+and callers must use
.Xr feof 3
and
.Xr ferror 3
@@ -130,29 +108,18 @@ for any of the errors specified for the routines
.Xr read 2 ,
or
.Xr malloc 3 .
-.Pp
-The function
-.Fn gets
-may also fail and set
-.Va errno
-for any of the errors specified for the routine
-.Xr getchar 3 .
.Sh SEE ALSO
.Xr feof 3 ,
.Xr ferror 3 ,
.Xr fgetln 3
.Sh STANDARDS
-The functions
+The function
.Fn fgets
-and
-.Fn gets
-conform to
+conforms to
.St -ansiC .
.Sh HISTORY
-The functions
+The function
.Fn fgets
-and
-.Fn gets
first appeared in
.At v7 .
.Sh CAVEATS
@@ -229,15 +196,3 @@ char buf[1024];
if (fgets(buf, sizeof(buf), fp) != NULL)
buf[strcspn(buf, "\en")] = '\e0';
.Ed
-.Sh BUGS
-Since it is usually impossible to ensure that the next input line
-is less than some arbitrary length, and because overflowing the
-input buffer is almost invariably a security violation, programs
-should
-.Em NEVER
-use
-.Fn gets .
-The
-.Fn gets
-function exists purely to conform to
-.St -ansiC .
diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c
deleted file mode 100644
index c2e1b50574e..00000000000
--- a/lib/libc/stdio/gets.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* $OpenBSD: gets.c,v 1.12 2009/11/09 00:18:27 kurt Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include "local.h"
-
-__warn_references(gets,
- "warning: gets() is very unsafe; consider using fgets()");
-
-char *
-gets(char *buf)
-{
- int c;
- char *s;
-
- FLOCKFILE(stdin);
- for (s = buf; (c = getchar_unlocked()) != '\n';)
- if (c == EOF)
- if (s == buf) {
- FUNLOCKFILE(stdin);
- return (NULL);
- } else
- break;
- else
- *s++ = c;
- *s = '\0';
- FUNLOCKFILE(stdin);
- return (buf);
-}