puts.c revision 165903
190075Sobrien/*-
2102780Skan * Copyright (c) 1990, 1993
390075Sobrien *	The Regents of the University of California.  All rights reserved.
490075Sobrien *
590075Sobrien * This code is derived from software contributed to Berkeley by
690075Sobrien * Chris Torek.
790075Sobrien *
890075Sobrien * Redistribution and use in source and binary forms, with or without
990075Sobrien * modification, are permitted provided that the following conditions
1090075Sobrien * are met:
1190075Sobrien * 1. Redistributions of source code must retain the above copyright
1290075Sobrien *    notice, this list of conditions and the following disclaimer.
1390075Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1490075Sobrien *    notice, this list of conditions and the following disclaimer in the
1590075Sobrien *    documentation and/or other materials provided with the distribution.
1690075Sobrien * 4. Neither the name of the University nor the names of its contributors
1790075Sobrien *    may be used to endorse or promote products derived from this software
1890075Sobrien *    without specific prior written permission.
1990075Sobrien *
2090075Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2190075Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2290075Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2390075Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2490075Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2590075Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2690075Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2790075Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2890075Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2990075Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3090075Sobrien * SUCH DAMAGE.
31102780Skan */
32102780Skan
3390075Sobrien#if defined(LIBC_SCCS) && !defined(lint)
3490075Sobrienstatic char sccsid[] = "@(#)puts.c	8.1 (Berkeley) 6/4/93";
3590075Sobrien#endif /* LIBC_SCCS and not lint */
3690075Sobrien#include <sys/cdefs.h>
3790075Sobrien__FBSDID("$FreeBSD: head/lib/libc/stdio/puts.c 165903 2007-01-09 00:28:16Z imp $");
3890075Sobrien
3990075Sobrien#include "namespace.h"
4090075Sobrien#include <stdio.h>
4190075Sobrien#include <string.h>
4290075Sobrien#include "un-namespace.h"
4390075Sobrien#include "fvwrite.h"
4490075Sobrien#include "libc_private.h"
4590075Sobrien#include "local.h"
4690075Sobrien
47102780Skan/*
4890075Sobrien * Write the given string to stdout, appending a newline.
4990075Sobrien */
5090075Sobrienint
5190075Sobrienputs(s)
5290075Sobrien	char const *s;
5390075Sobrien{
5490075Sobrien	int retval;
5590075Sobrien	size_t c = strlen(s);
5690075Sobrien	struct __suio uio;
5790075Sobrien	struct __siov iov[2];
5890075Sobrien
5990075Sobrien	iov[0].iov_base = (void *)s;
6090075Sobrien	iov[0].iov_len = c;
6190075Sobrien	iov[1].iov_base = "\n";
6290075Sobrien	iov[1].iov_len = 1;
6390075Sobrien	uio.uio_resid = c + 1;
6490075Sobrien	uio.uio_iov = &iov[0];
6590075Sobrien	uio.uio_iovcnt = 2;
6690075Sobrien	FLOCKFILE(stdout);
6790075Sobrien	ORIENT(stdout, -1);
6890075Sobrien	retval = __sfvwrite(stdout, &uio) ? EOF : '\n';
6990075Sobrien	FUNLOCKFILE(stdout);
7090075Sobrien	return (retval);
7190075Sobrien}
7290075Sobrien