source: trunk/libs/newlib/src/newlib/libc/stdio/puts.c @ 567

Last change on this file since 567 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 3.0 KB
Line 
1/*
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley.  The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17
18/*
19FUNCTION
20<<puts>>---write a character string
21
22INDEX
23        puts
24INDEX
25        _puts_r
26
27SYNOPSIS
28        #include <stdio.h>
29        int puts(const char *<[s]>);
30
31        int _puts_r(struct _reent *<[reent]>, const char *<[s]>);
32
33DESCRIPTION
34<<puts>> writes the string at <[s]> (followed by a newline, instead of
35the trailing null) to the standard output stream.
36
37The alternate function <<_puts_r>> is a reentrant version.  The extra
38argument <[reent]> is a pointer to a reentrancy structure.
39
40RETURNS
41If successful, the result is a nonnegative integer; otherwise, the
42result is <<EOF>>.
43
44PORTABILITY
45ANSI C requires <<puts>>, but does not specify that the result on
46success must be <<0>>; any non-negative value is permitted.
47
48Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
49<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
50*/
51
52#if defined(LIBC_SCCS) && !defined(lint)
53static char sccsid[] = "%W% (Berkeley) %G%";
54#endif /* LIBC_SCCS and not lint */
55
56#include <_ansi.h>
57#include <reent.h>
58#include <stdio.h>
59#include <string.h>
60#include "fvwrite.h"
61#include "local.h"
62
63/*
64 * Write the given string to stdout, appending a newline.
65 */
66
67int
68_puts_r (struct _reent *ptr,
69       const char * s)
70{
71#ifdef _FVWRITE_IN_STREAMIO
72  int result;
73  size_t c = strlen (s);
74  struct __suio uio;
75  struct __siov iov[2];
76  FILE *fp;
77
78  iov[0].iov_base = s;
79  iov[0].iov_len = c;
80  iov[1].iov_base = "\n";
81  iov[1].iov_len = 1;
82  uio.uio_resid = c + 1;
83  uio.uio_iov = &iov[0];
84  uio.uio_iovcnt = 2;
85
86  _REENT_SMALL_CHECK_INIT (ptr);
87  fp = _stdout_r (ptr);
88  CHECK_INIT (ptr, fp);
89  _newlib_flockfile_start (fp);
90  ORIENT (fp, -1);
91  result = (__sfvwrite_r (ptr, fp, &uio) ? EOF : '\n');
92  _newlib_flockfile_end (fp);
93  return result;
94#else
95  int result = EOF;
96  const char *p = s;
97  FILE *fp;
98  _REENT_SMALL_CHECK_INIT (ptr);
99
100  fp = _stdout_r (ptr);
101  CHECK_INIT (ptr, fp);
102  _newlib_flockfile_start (fp);
103  ORIENT (fp, -1);
104  /* Make sure we can write.  */
105  if (cantwrite (ptr, fp))
106    goto err;
107
108  while (*p)
109    {
110      if (__sputc_r (ptr, *p++, fp) == EOF)
111        goto err;
112    }
113  if (__sputc_r (ptr, '\n', fp) == EOF)
114    goto err;
115
116  result = '\n';
117
118err:
119  _newlib_flockfile_end (fp);
120  return result;
121#endif
122}
123
124#ifndef _REENT_ONLY
125
126int
127puts (char const * s)
128{
129  return _puts_r (_REENT, s);
130}
131
132#endif
Note: See TracBrowser for help on using the repository browser.