getchar.c revision 249808
1296633Sdes/*- 2124208Sdes * Copyright (c) 1990, 1993 3124208Sdes * The Regents of the University of California. All rights reserved. 4255670Sdes * 5124208Sdes * This code is derived from software contributed to Berkeley by 6255670Sdes * Chris Torek. 7124208Sdes * 8255670Sdes * Redistribution and use in source and binary forms, with or without 9294328Sdes * modification, are permitted provided that the following conditions 10124208Sdes * are met: 11261320Sdes * 1. Redistributions of source code must retain the above copyright 12261320Sdes * notice, this list of conditions and the following disclaimer. 13261320Sdes * 2. Redistributions in binary form must reproduce the above copyright 14261320Sdes * notice, this list of conditions and the following disclaimer in the 15294328Sdes * documentation and/or other materials provided with the distribution. 16294328Sdes * 3. Neither the name of the University nor the names of its contributors 17294328Sdes * may be used to endorse or promote products derived from this software 18294328Sdes * without specific prior written permission. 19294328Sdes * 20294328Sdes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21294328Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22255670Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23294328Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24294328Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25124208Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26261320Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27124208Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28261320Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29124208Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30124208Sdes * SUCH DAMAGE. 31124208Sdes */ 32124208Sdes 33261320Sdes#if defined(LIBC_SCCS) && !defined(lint) 34124208Sdesstatic char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93"; 35261320Sdes#endif /* LIBC_SCCS and not lint */ 36261320Sdes#include <sys/cdefs.h> 37261320Sdes__FBSDID("$FreeBSD: head/lib/libc/stdio/getchar.c 249808 2013-04-23 13:33:13Z emaste $"); 38261320Sdes 39261320Sdes/* 40261320Sdes * A subroutine version of the macro getchar. 41261320Sdes */ 42124208Sdes#include "namespace.h" 43261320Sdes#include <stdio.h> 44261320Sdes#include "un-namespace.h" 45261320Sdes#include "local.h" 46261320Sdes#include "libc_private.h" 47261320Sdes 48261320Sdes#undef getchar 49255670Sdes#undef getchar_unlocked 50261320Sdes 51261320Sdesint 52294328Sdesgetchar() 53261320Sdes{ 54261320Sdes int retval; 55261320Sdes FLOCKFILE(stdin); 56261320Sdes /* Orientation set by __sgetc() when buffer is empty. */ 57261320Sdes /* ORIENT(stdin, -1); */ 58261320Sdes retval = __sgetc(stdin); 59261320Sdes FUNLOCKFILE(stdin); 60294328Sdes return (retval); 61261320Sdes} 62261320Sdes 63261320Sdesint 64261320Sdesgetchar_unlocked(void) 65261320Sdes{ 66261320Sdes 67294328Sdes return (__sgetc(stdin)); 68261320Sdes} 69261320Sdes