Skip to content

Commit

Permalink
Fix gets problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Drepper committed Jan 24, 2012
1 parent d220b11 commit b15549e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2012-01-24 Ulrich Drepper <drepper@gmail.com>

* include/stdio.h: Add C++ protection. Add gets declarations and
definitions.
* debug/tst-chk1.c: Don't declare gets here.
* stdio-common/tst-gets.c: Likewise.

2012-01-21 Ulrich Drepper <drepper@gmail.com>

* wcsmbs/uchar.h: Test __STDC_VERSION__.
Expand Down
5 changes: 0 additions & 5 deletions debug/tst-chk1.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
#include <sys/socket.h>
#include <sys/un.h>

__BEGIN_DECLS
/* The <stdio.h> header does not include the declaration for gets
anymore when compiling with _GNU_SOURCE. Provide a copy here. */
extern char *gets (char *__s);
__END_DECLS

#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
Expand Down
22 changes: 22 additions & 0 deletions include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# include <libio/stdio.h>

/* Now define the internal interfaces. */
__BEGIN_DECLS

extern int __fcloseall (void);
extern int __snprintf (char *__restrict __s, size_t __maxlen,
const char *__restrict __format, ...)
Expand Down Expand Up @@ -164,6 +166,26 @@ libc_hidden_proto (__vfprintf_chk)
libc_hidden_proto (__vasprintf_chk)
libc_hidden_proto (__vdprintf_chk)
libc_hidden_proto (__obstack_vprintf_chk)

/* The <stdio.h> header does not include the declaration for gets
anymore when compiling with _GNU_SOURCE. Provide a copy here. */
extern char *gets (char *__s);
# if __USE_FORTIFY_LEVEL > 0
extern char *__gets_chk (char *__str, size_t) __wur;
extern char *__REDIRECT (__gets_warn, (char *__str), gets)
__wur __warnattr ("please use fgets or getline instead, gets can't "
"specify buffer size");

__extern_always_inline __wur char *
gets (char *__str)
{
if (__bos (__str) != (size_t) -1)
return __gets_chk (__str, __bos (__str));
return __gets_warn (__str);
}
# endif

__END_DECLS
# endif

#endif
6 changes: 1 addition & 5 deletions stdio-common/tst-gets.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Tests for gets.
Copyright (C) 2001, 2011 Free Software Foundation, Inc.
Copyright (C) 2001, 2011, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
Expand All @@ -21,10 +21,6 @@
#include <stdio.h>
#include <string.h>

/* The <stdio.h> header does not include the declaration for gets
anymore when compiling with _GNU_SOURCE. Provide a copy here. */
extern char *gets (char *__s);


int
main (void)
Expand Down

0 comments on commit b15549e

Please sign in to comment.