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