sl@0: /* PUTS.C sl@0: * sl@0: * Portions Copyright (c) 1990-2006 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: */ sl@0: sl@0: /* sl@0: * Copyright (c) 1990 The Regents of the University of California. sl@0: * All rights reserved. sl@0: * sl@0: * Redistribution and use in source and binary forms are permitted sl@0: * provided that the above copyright notice and this paragraph are sl@0: * duplicated in all such forms and that any documentation, sl@0: * advertising materials, and other materials related to such sl@0: * distribution and use acknowledge that the software was developed sl@0: * by the University of California, Berkeley. The name of the sl@0: * University may not be used to endorse or promote products derived sl@0: * from this software without specific prior written permission. sl@0: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR sl@0: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED sl@0: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. sl@0: */ sl@0: sl@0: /* sl@0: FUNCTION sl@0: <<puts>>---write a character string sl@0: sl@0: INDEX sl@0: puts sl@0: INDEX sl@0: _puts_r sl@0: sl@0: ANSI_SYNOPSIS sl@0: #include <stdio.h> sl@0: int puts(const char *<[s]>); sl@0: sl@0: int _puts_r(void *<[reent]>, const char *<[s]>); sl@0: sl@0: TRAD_SYNOPSIS sl@0: #include <stdio.h> sl@0: int puts(<[s]>) sl@0: char *<[s]>; sl@0: sl@0: int _puts_r(<[reent]>, <[s]>) sl@0: char *<[reent]>; sl@0: char *<[s]>; sl@0: sl@0: DESCRIPTION sl@0: <<puts>> writes the string at <[s]> (followed by a newline, instead of sl@0: the trailing null) to the standard output stream. sl@0: sl@0: The alternate function <<_puts_r>> is a reentrant version. The extra sl@0: argument <[reent]> is a pointer to a reentrancy structure. sl@0: sl@0: RETURNS sl@0: If successful, the result is a nonnegative integer; otherwise, the sl@0: result is <<EOF>>. sl@0: sl@0: PORTABILITY sl@0: ANSI C requires <<puts>>, but does not specify that the result on sl@0: success must be <<0>>; any non-negative value is permitted. sl@0: sl@0: Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, sl@0: <<lseek>>, <<read>>, <<sbrk>>, <<write>>. */ sl@0: sl@0: #include <stdio_r.h> sl@0: #include <string.h> sl@0: #include "FVWRITE.H" sl@0: #include "LOCAL.H" sl@0: sl@0: /** sl@0: Writes the given string to stdout, appending a newline. sl@0: @return sl@0: @param sl@0: */ sl@0: EXPORT_C int sl@0: _puts_r (struct _reent *ptr, const char * s) sl@0: { sl@0: size_t c = strlen (s); sl@0: struct __suio uio; sl@0: struct __siov iov[2]; sl@0: sl@0: iov[0].iov_base = s; sl@0: iov[0].iov_len = c; sl@0: iov[1].iov_base = "\n"; sl@0: iov[1].iov_len = 1; sl@0: uio.uio_resid = c + 1; sl@0: uio.uio_iov = &iov[0]; sl@0: uio.uio_iovcnt = 2; sl@0: sl@0: return (__sfvwrite (_stdout_r (ptr), &uio) ? EOF : '\n'); sl@0: } sl@0: sl@0: #ifndef _REENT_ONLY sl@0: /** sl@0: Outputs a string to stdout. Copies the string to standard output stream sl@0: and appends a new line character (\n). sl@0: sl@0: @param Null-terminated string to be outputed. sl@0: sl@0: @return On Success, a non-negative value is returned. sl@0: On Failure, EOF value is returned and errno may be set. sl@0: */ sl@0: EXPORT_C int sl@0: puts (char const * s) sl@0: { sl@0: struct _reent *r = _REENT2; sl@0: if (!r) sl@0: return EOF; // Memory for library globals is not allocated (errno not set). sl@0: return _puts_r (r, s); sl@0: } sl@0: sl@0: #endif