157718be8SEnji Cooper /* $NetBSD: h_gets.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $ */
257718be8SEnji Cooper 
357718be8SEnji Cooper /*
457718be8SEnji Cooper  * Copyright (c) 2008 The NetBSD Foundation, Inc.
557718be8SEnji Cooper  * All rights reserved.
657718be8SEnji Cooper  *
757718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
857718be8SEnji Cooper  * modification, are permitted provided that the following conditions
957718be8SEnji Cooper  * are met:
1057718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
1157718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
1257718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
1357718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
1457718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
1557718be8SEnji Cooper  *
1657718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1757718be8SEnji Cooper  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1857718be8SEnji Cooper  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1957718be8SEnji Cooper  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2057718be8SEnji Cooper  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2157718be8SEnji Cooper  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2257718be8SEnji Cooper  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2357718be8SEnji Cooper  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2457718be8SEnji Cooper  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2557718be8SEnji Cooper  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2657718be8SEnji Cooper  * POSSIBILITY OF SUCH DAMAGE.
2757718be8SEnji Cooper  */
2857718be8SEnji Cooper 
2957718be8SEnji Cooper #include <sys/cdefs.h>
3057718be8SEnji Cooper __COPYRIGHT("@(#) Copyright (c) 2008\
3157718be8SEnji Cooper  The NetBSD Foundation, inc. All rights reserved.");
3257718be8SEnji Cooper __RCSID("$NetBSD: h_gets.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $");
3357718be8SEnji Cooper 
3457718be8SEnji Cooper #include <stdio.h>
3557718be8SEnji Cooper 
367381dcc9SEd Maste #ifdef __FreeBSD__
37*e5551250SKyle Evans /* _FORTIFY_SOURCE, at the very least, may #define a gets() macro. */
38*e5551250SKyle Evans #undef gets
39*e5551250SKyle Evans 
407381dcc9SEd Maste /*
417381dcc9SEd Maste  * We want to test the gets() implementation, but cannot simply link against
427381dcc9SEd Maste  * the gets symbol because it is not in the default version. (We've made it
437381dcc9SEd Maste  * unavailable by default on FreeBSD because it should not be used.)
447381dcc9SEd Maste  *
457381dcc9SEd Maste  * The next two lines create an unsafe_gets() function that resolves to
467381dcc9SEd Maste  * gets@FBSD_1.0, which we call from our local gets() implementation.
477381dcc9SEd Maste  */
487381dcc9SEd Maste __sym_compat(gets, unsafe_gets, FBSD_1.0);
497381dcc9SEd Maste char *unsafe_gets(char *);
507381dcc9SEd Maste 
gets(char * buf)517381dcc9SEd Maste char *gets(char *buf)
527381dcc9SEd Maste {
537381dcc9SEd Maste 	return unsafe_gets(buf);
547381dcc9SEd Maste }
557381dcc9SEd Maste #endif
567381dcc9SEd Maste 
5757718be8SEnji Cooper int
main(int argc,char * argv[])5857718be8SEnji Cooper main(int argc, char *argv[])
5957718be8SEnji Cooper {
6057718be8SEnji Cooper 	char b[10];
6157718be8SEnji Cooper 	(void)gets(b);
6257718be8SEnji Cooper 	(void)printf("%s\n", b);
6357718be8SEnji Cooper 	return 0;
6457718be8SEnji Cooper }
65