Rev 4921 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 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 | /* |
||
19 | FUNCTION |
||
6099 | serge | 20 | < |
4349 | Serge | 21 | |
22 | INDEX |
||
23 | fputs |
||
24 | INDEX |
||
6099 | serge | 25 | fputs_unlocked |
26 | INDEX |
||
4349 | Serge | 27 | _fputs_r |
6099 | serge | 28 | INDEX |
29 | _fputs_unlocked_r |
||
4349 | Serge | 30 | |
31 | ANSI_SYNOPSIS |
||
32 | #include |
||
4921 | Serge | 33 | int fputs(const char *restrict <[s]>, FILE *restrict <[fp]>); |
4349 | Serge | 34 | |
6099 | serge | 35 | #define _GNU_SOURCE |
4349 | Serge | 36 | #include |
6099 | serge | 37 | int fputs_unlocked(const char *restrict <[s]>, FILE *restrict <[fp]>); |
38 | |||
39 | #include |
||
4921 | Serge | 40 | int _fputs_r(struct _reent *<[ptr]>, const char *restrict <[s]>, FILE *restrict <[fp]>); |
4349 | Serge | 41 | |
6099 | serge | 42 | #include |
43 | int _fputs_unlocked_r(struct _reent *<[ptr]>, const char *restrict <[s]>, FILE *restrict <[fp]>); |
||
44 | |||
4349 | Serge | 45 | TRAD_SYNOPSIS |
46 | #include |
||
47 | int fputs(<[s]>, <[fp]>) |
||
48 | char *<[s]>; |
||
49 | FILE *<[fp]>; |
||
50 | |||
6099 | serge | 51 | #define _GNU_SOURCE |
4349 | Serge | 52 | #include |
6099 | serge | 53 | int fputs_unlocked(<[s]>, <[fp]>) |
54 | char *<[s]>; |
||
55 | FILE *<[fp]>; |
||
56 | |||
57 | #include |
||
4349 | Serge | 58 | int _fputs_r(<[ptr]>, <[s]>, <[fp]>) |
59 | struct _reent *<[ptr]>; |
||
60 | char *<[s]>; |
||
61 | FILE *<[fp]>; |
||
62 | |||
6099 | serge | 63 | #include |
64 | int _fputs_unlocked_r(<[ptr]>, <[s]>, <[fp]>) |
||
65 | struct _reent *<[ptr]>; |
||
66 | char *<[s]>; |
||
67 | FILE *<[fp]>; |
||
68 | |||
4349 | Serge | 69 | DESCRIPTION |
70 | < |
||
71 | to the file or stream identified by <[fp]>. |
||
72 | |||
6099 | serge | 73 | < |
74 | < |
||
75 | protected by flockfile() (or ftrylockfile()) and funlockfile(). This |
||
76 | function may safely be used in a multi-threaded program if and only |
||
77 | if they are called while the invoking thread owns the (FILE *) |
||
78 | object, as is the case after a successful call to the flockfile() or |
||
79 | ftrylockfile() functions. If threads are disabled, then |
||
80 | < |
||
4349 | Serge | 81 | |
6099 | serge | 82 | <<_fputs_r>> and <<_fputs_unlocked_r>> are simply reentrant versions of the |
83 | above that take an additional reentrant struct pointer argument: <[ptr]>. |
||
84 | |||
4349 | Serge | 85 | RETURNS |
86 | If successful, the result is <<0>>; otherwise, the result is < |
||
87 | |||
88 | PORTABILITY |
||
89 | ANSI C requires < |
||
90 | success must be <<0>>; any non-negative value is permitted. |
||
91 | |||
6099 | serge | 92 | < |
93 | |||
4349 | Serge | 94 | Supporting OS subroutines required: < |
95 | < |
||
96 | */ |
||
97 | |||
98 | #include <_ansi.h> |
||
99 | #include |
||
100 | #include |
||
101 | #include "fvwrite.h" |
||
102 | #include "local.h" |
||
103 | |||
6099 | serge | 104 | #ifdef __IMPL_UNLOCKED__ |
105 | #define _fputs_r _fputs_unlocked_r |
||
106 | #define fputs fputs_unlocked |
||
107 | #endif |
||
108 | |||
4349 | Serge | 109 | /* |
110 | * Write the given string to the given file. |
||
111 | */ |
||
112 | int |
||
113 | _DEFUN(_fputs_r, (ptr, s, fp), |
||
114 | struct _reent * ptr _AND |
||
4921 | Serge | 115 | char _CONST *__restrict s _AND |
116 | FILE *__restrict fp) |
||
4349 | Serge | 117 | { |
4921 | Serge | 118 | #ifdef _FVWRITE_IN_STREAMIO |
4349 | Serge | 119 | int result; |
120 | struct __suio uio; |
||
121 | struct __siov iov; |
||
122 | |||
123 | iov.iov_base = s; |
||
124 | iov.iov_len = uio.uio_resid = strlen (s); |
||
125 | uio.uio_iov = &iov; |
||
126 | uio.uio_iovcnt = 1; |
||
127 | |||
128 | CHECK_INIT(ptr, fp); |
||
129 | |||
4921 | Serge | 130 | _newlib_flockfile_start (fp); |
4349 | Serge | 131 | ORIENT (fp, -1); |
132 | result = __sfvwrite_r (ptr, fp, &uio); |
||
4921 | Serge | 133 | _newlib_flockfile_end (fp); |
4349 | Serge | 134 | return result; |
4921 | Serge | 135 | #else |
136 | _CONST char *p = s; |
||
137 | |||
138 | CHECK_INIT(ptr, fp); |
||
139 | |||
140 | _newlib_flockfile_start (fp); |
||
141 | ORIENT (fp, -1); |
||
142 | /* Make sure we can write. */ |
||
143 | if (cantwrite (ptr, fp)) |
||
144 | goto error; |
||
145 | |||
146 | while (*p) |
||
147 | { |
||
148 | if (__sputc_r (ptr, *p++, fp) == EOF) |
||
149 | goto error; |
||
150 | } |
||
151 | _newlib_flockfile_exit (fp); |
||
152 | return 0; |
||
153 | |||
154 | error: |
||
155 | _newlib_flockfile_end (fp); |
||
156 | return EOF; |
||
157 | #endif |
||
4349 | Serge | 158 | } |
159 | |||
160 | #ifndef _REENT_ONLY |
||
161 | int |
||
162 | _DEFUN(fputs, (s, fp), |
||
4921 | Serge | 163 | char _CONST *__restrict s _AND |
164 | FILE *__restrict fp) |
||
4349 | Serge | 165 | { |
166 | return _fputs_r (_REENT, s, fp); |
||
167 | } |
||
168 | #endif /* !_REENT_ONLY */ |