sl@0
|
1 |
/* PUTS.C
|
sl@0
|
2 |
*
|
sl@0
|
3 |
* Portions Copyright (c) 1990-2006 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
4 |
* All rights reserved.
|
sl@0
|
5 |
*/
|
sl@0
|
6 |
|
sl@0
|
7 |
/*
|
sl@0
|
8 |
* Copyright (c) 1990 The Regents of the University of California.
|
sl@0
|
9 |
* All rights reserved.
|
sl@0
|
10 |
*
|
sl@0
|
11 |
* Redistribution and use in source and binary forms are permitted
|
sl@0
|
12 |
* provided that the above copyright notice and this paragraph are
|
sl@0
|
13 |
* duplicated in all such forms and that any documentation,
|
sl@0
|
14 |
* advertising materials, and other materials related to such
|
sl@0
|
15 |
* distribution and use acknowledge that the software was developed
|
sl@0
|
16 |
* by the University of California, Berkeley. The name of the
|
sl@0
|
17 |
* University may not be used to endorse or promote products derived
|
sl@0
|
18 |
* from this software without specific prior written permission.
|
sl@0
|
19 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
sl@0
|
20 |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
sl@0
|
21 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
|
sl@0
|
24 |
/*
|
sl@0
|
25 |
FUNCTION
|
sl@0
|
26 |
<<puts>>---write a character string
|
sl@0
|
27 |
|
sl@0
|
28 |
INDEX
|
sl@0
|
29 |
puts
|
sl@0
|
30 |
INDEX
|
sl@0
|
31 |
_puts_r
|
sl@0
|
32 |
|
sl@0
|
33 |
ANSI_SYNOPSIS
|
sl@0
|
34 |
#include <stdio.h>
|
sl@0
|
35 |
int puts(const char *<[s]>);
|
sl@0
|
36 |
|
sl@0
|
37 |
int _puts_r(void *<[reent]>, const char *<[s]>);
|
sl@0
|
38 |
|
sl@0
|
39 |
TRAD_SYNOPSIS
|
sl@0
|
40 |
#include <stdio.h>
|
sl@0
|
41 |
int puts(<[s]>)
|
sl@0
|
42 |
char *<[s]>;
|
sl@0
|
43 |
|
sl@0
|
44 |
int _puts_r(<[reent]>, <[s]>)
|
sl@0
|
45 |
char *<[reent]>;
|
sl@0
|
46 |
char *<[s]>;
|
sl@0
|
47 |
|
sl@0
|
48 |
DESCRIPTION
|
sl@0
|
49 |
<<puts>> writes the string at <[s]> (followed by a newline, instead of
|
sl@0
|
50 |
the trailing null) to the standard output stream.
|
sl@0
|
51 |
|
sl@0
|
52 |
The alternate function <<_puts_r>> is a reentrant version. The extra
|
sl@0
|
53 |
argument <[reent]> is a pointer to a reentrancy structure.
|
sl@0
|
54 |
|
sl@0
|
55 |
RETURNS
|
sl@0
|
56 |
If successful, the result is a nonnegative integer; otherwise, the
|
sl@0
|
57 |
result is <<EOF>>.
|
sl@0
|
58 |
|
sl@0
|
59 |
PORTABILITY
|
sl@0
|
60 |
ANSI C requires <<puts>>, but does not specify that the result on
|
sl@0
|
61 |
success must be <<0>>; any non-negative value is permitted.
|
sl@0
|
62 |
|
sl@0
|
63 |
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
sl@0
|
64 |
<<lseek>>, <<read>>, <<sbrk>>, <<write>>. */
|
sl@0
|
65 |
|
sl@0
|
66 |
#include <stdio_r.h>
|
sl@0
|
67 |
#include <string.h>
|
sl@0
|
68 |
#include "FVWRITE.H"
|
sl@0
|
69 |
#include "LOCAL.H"
|
sl@0
|
70 |
|
sl@0
|
71 |
/**
|
sl@0
|
72 |
Writes the given string to stdout, appending a newline.
|
sl@0
|
73 |
@return
|
sl@0
|
74 |
@param
|
sl@0
|
75 |
*/
|
sl@0
|
76 |
EXPORT_C int
|
sl@0
|
77 |
_puts_r (struct _reent *ptr, const char * s)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
size_t c = strlen (s);
|
sl@0
|
80 |
struct __suio uio;
|
sl@0
|
81 |
struct __siov iov[2];
|
sl@0
|
82 |
|
sl@0
|
83 |
iov[0].iov_base = s;
|
sl@0
|
84 |
iov[0].iov_len = c;
|
sl@0
|
85 |
iov[1].iov_base = "\n";
|
sl@0
|
86 |
iov[1].iov_len = 1;
|
sl@0
|
87 |
uio.uio_resid = c + 1;
|
sl@0
|
88 |
uio.uio_iov = &iov[0];
|
sl@0
|
89 |
uio.uio_iovcnt = 2;
|
sl@0
|
90 |
|
sl@0
|
91 |
return (__sfvwrite (_stdout_r (ptr), &uio) ? EOF : '\n');
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
#ifndef _REENT_ONLY
|
sl@0
|
95 |
/**
|
sl@0
|
96 |
Outputs a string to stdout. Copies the string to standard output stream
|
sl@0
|
97 |
and appends a new line character (\n).
|
sl@0
|
98 |
|
sl@0
|
99 |
@param Null-terminated string to be outputed.
|
sl@0
|
100 |
|
sl@0
|
101 |
@return On Success, a non-negative value is returned.
|
sl@0
|
102 |
On Failure, EOF value is returned and errno may be set.
|
sl@0
|
103 |
*/
|
sl@0
|
104 |
EXPORT_C int
|
sl@0
|
105 |
puts (char const * s)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
struct _reent *r = _REENT2;
|
sl@0
|
108 |
if (!r)
|
sl@0
|
109 |
return EOF; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
110 |
return _puts_r (r, s);
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
#endif
|