os/ossrv/genericopenlibs/cstdlib/LSTDIO/PUTS.C
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSTDIO/PUTS.C	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,113 @@
     1.4 +/* PUTS.C
     1.5 + * 
     1.6 + * Portions Copyright (c) 1990-2006 Nokia Corporation and/or its subsidiary(-ies).
     1.7 + * All rights reserved.
     1.8 + */
     1.9 +
    1.10 +/*
    1.11 + * Copyright (c) 1990 The Regents of the University of California.
    1.12 + * All rights reserved.
    1.13 + *
    1.14 + * Redistribution and use in source and binary forms are permitted
    1.15 + * provided that the above copyright notice and this paragraph are
    1.16 + * duplicated in all such forms and that any documentation,
    1.17 + * advertising materials, and other materials related to such
    1.18 + * distribution and use acknowledge that the software was developed
    1.19 + * by the University of California, Berkeley.  The name of the
    1.20 + * University may not be used to endorse or promote products derived
    1.21 + * from this software without specific prior written permission.
    1.22 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
    1.23 + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
    1.24 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 +FUNCTION
    1.29 +<<puts>>---write a character string
    1.30 +
    1.31 +INDEX
    1.32 +	puts
    1.33 +INDEX
    1.34 +	_puts_r
    1.35 +
    1.36 +ANSI_SYNOPSIS
    1.37 +	#include <stdio.h>
    1.38 +	int puts(const char *<[s]>);
    1.39 +
    1.40 +	int _puts_r(void *<[reent]>, const char *<[s]>);
    1.41 +
    1.42 +TRAD_SYNOPSIS
    1.43 +	#include <stdio.h>
    1.44 +	int puts(<[s]>)
    1.45 +	char *<[s]>;
    1.46 +
    1.47 +	int _puts_r(<[reent]>, <[s]>)
    1.48 +	char *<[reent]>;
    1.49 +	char *<[s]>;
    1.50 +
    1.51 +DESCRIPTION
    1.52 +<<puts>> writes the string at <[s]> (followed by a newline, instead of
    1.53 +the trailing null) to the standard output stream.
    1.54 +
    1.55 +The alternate function <<_puts_r>> is a reentrant version.  The extra
    1.56 +argument <[reent]> is a pointer to a reentrancy structure.
    1.57 +
    1.58 +RETURNS
    1.59 +If successful, the result is a nonnegative integer; otherwise, the
    1.60 +result is <<EOF>>.
    1.61 +
    1.62 +PORTABILITY
    1.63 +ANSI C requires <<puts>>, but does not specify that the result on
    1.64 +success must be <<0>>; any non-negative value is permitted.
    1.65 +
    1.66 +Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
    1.67 +<<lseek>>, <<read>>, <<sbrk>>, <<write>>.  */
    1.68 +
    1.69 +#include <stdio_r.h>
    1.70 +#include <string.h>
    1.71 +#include "FVWRITE.H"
    1.72 +#include "LOCAL.H"
    1.73 +
    1.74 +/**
    1.75 +Writes the given string to stdout, appending a newline.
    1.76 +@return
    1.77 +@param 
    1.78 +*/
    1.79 +EXPORT_C int
    1.80 +_puts_r (struct _reent *ptr, const char * s)
    1.81 +{
    1.82 +  size_t c = strlen (s);
    1.83 +  struct __suio uio;
    1.84 +  struct __siov iov[2];
    1.85 +
    1.86 +  iov[0].iov_base = s;
    1.87 +  iov[0].iov_len = c;
    1.88 +  iov[1].iov_base = "\n";
    1.89 +  iov[1].iov_len = 1;
    1.90 +  uio.uio_resid = c + 1;
    1.91 +  uio.uio_iov = &iov[0];
    1.92 +  uio.uio_iovcnt = 2;
    1.93 +
    1.94 +  return (__sfvwrite (_stdout_r (ptr), &uio) ? EOF : '\n');
    1.95 +}
    1.96 +
    1.97 +#ifndef _REENT_ONLY
    1.98 +/**
    1.99 +Outputs a string to stdout. Copies the string to standard output stream
   1.100 +and appends a new line character (\n).
   1.101 +
   1.102 +@param Null-terminated string to be outputed.
   1.103 +
   1.104 +@return On Success, a non-negative value is returned.
   1.105 +		On Failure, EOF value is returned and errno may be set.
   1.106 +*/
   1.107 +EXPORT_C int
   1.108 +puts (char const * s)
   1.109 +{
   1.110 +  struct _reent *r = _REENT2;
   1.111 +  if (!r)
   1.112 +	return EOF; // Memory for library globals is not allocated (errno not set).
   1.113 +  return _puts_r (r, s);
   1.114 +}
   1.115 +
   1.116 +#endif