Rev 1653 | Rev 1787 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1653 | Rev 1719 | ||
---|---|---|---|
Line 25... | Line 25... | ||
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | /** @addtogroup libc |
30 | /** @addtogroup libc |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | /** @file |
33 | /** @file |
34 | */ |
34 | */ |
35 | 35 | ||
Line 71... | Line 71... | ||
71 | 71 | ||
72 | while (i < count) { |
72 | while (i < count) { |
73 | if (async_req_2(streams[0].phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1) < 0) { |
73 | if (async_req_2(streams[0].phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1) < 0) { |
74 | return -1; |
74 | return -1; |
75 | } |
75 | } |
76 | ((char *)buf)[i++] = r0; |
76 | ((char *) buf)[i++] = r0; |
77 | } |
77 | } |
78 | return i; |
78 | return i; |
79 | } |
79 | } |
80 | 80 | ||
81 | static ssize_t write_stdout(void *param, const void *buf, size_t count) |
81 | static ssize_t write_stdout(void *param, const void *buf, size_t count) |
82 | { |
82 | { |
83 | int i; |
83 | int i; |
84 | ipcarg_t r0,r1; |
- | |
85 | 84 | ||
86 | for (i = 0; i < count; i++) |
85 | for (i = 0; i < count; i++) |
87 | async_msg(streams[1].phone, CONSOLE_PUTCHAR, ((const char *)buf)[i]); |
86 | async_msg(streams[1].phone, CONSOLE_PUTCHAR, ((const char *) buf)[i]); |
88 | 87 | ||
89 | return count; |
88 | return count; |
90 | } |
89 | } |
91 | 90 | ||
92 | 91 | ||
93 | - | ||
94 | static stream_t open_stdin(void) |
92 | static stream_t open_stdin(void) |
95 | { |
93 | { |
96 | stream_t stream; |
94 | stream_t stream; |
97 | int phoneid; |
- | |
98 | int res; |
- | |
99 | 95 | ||
100 | if (console_phone < 0) { |
96 | if (console_phone < 0) { |
101 | while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) { |
97 | while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) { |
102 | usleep(10000); |
98 | usleep(10000); |
103 | } |
99 | } |
104 | } |
100 | } |
105 | 101 | ||
106 | stream.r = read_stdin; |
102 | stream.r = read_stdin; |
- | 103 | stream.w = NULL; |
|
107 | stream.param = 0; |
104 | stream.param = 0; |
108 | stream.phone = console_phone; |
105 | stream.phone = console_phone; |
109 | 106 | ||
110 | return stream; |
107 | return stream; |
111 | } |
108 | } |
112 | 109 | ||
113 | static stream_t open_stdout(void) |
110 | static stream_t open_stdout(void) |
114 | { |
111 | { |
115 | stream_t stream; |
112 | stream_t stream; |
116 | int res; |
- | |
117 | 113 | ||
118 | if (console_phone < 0) { |
114 | if (console_phone < 0) { |
119 | while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) { |
115 | while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) { |
120 | usleep(10000); |
116 | usleep(10000); |
121 | } |
117 | } |
122 | } |
118 | } |
123 | 119 | ||
- | 120 | stream.r = NULL; |
|
124 | stream.w = write_stdout; |
121 | stream.w = write_stdout; |
125 | stream.phone = console_phone; |
122 | stream.phone = console_phone; |
126 | stream.param = 0; |
123 | stream.param = 0; |
- | 124 | ||
127 | return stream; |
125 | return stream; |
128 | } |
126 | } |
129 | 127 | ||
130 | static ssize_t write_null(void *param, const void *buf, size_t count) |
128 | static ssize_t write_null(void *param, const void *buf, size_t count) |
131 | { |
129 | { |
Line 137... | Line 135... | ||
137 | { |
135 | { |
138 | int c = 0; |
136 | int c = 0; |
139 | 137 | ||
140 | while (((streams[c].w) || (streams[c].r)) && (c < FDS)) |
138 | while (((streams[c].w) || (streams[c].r)) && (c < FDS)) |
141 | c++; |
139 | c++; |
- | 140 | ||
142 | if (c == FDS) |
141 | if (c == FDS) |
143 | return EMFILE; |
142 | return EMFILE; |
144 | 143 | ||
145 | if (!strcmp(fname, "stdin")) { |
144 | if (!strcmp(fname, "stdin")) { |
146 | streams[c] = open_stdin(); |
145 | streams[c] = open_stdin(); |
Line 154... | Line 153... | ||
154 | 153 | ||
155 | if (!strcmp(fname, "stderr")) { |
154 | if (!strcmp(fname, "stderr")) { |
156 | streams[c].w = write_stderr; |
155 | streams[c].w = write_stderr; |
157 | return c; |
156 | return c; |
158 | } |
157 | } |
- | 158 | ||
159 | if (!strcmp(fname, "null")) { |
159 | if (!strcmp(fname, "null")) { |
160 | streams[c].w = write_null; |
160 | streams[c].w = write_null; |
161 | return c; |
161 | return c; |
162 | } |
162 | } |
- | 163 | ||
- | 164 | return -1; |
|
163 | } |
165 | } |
164 | 166 | ||
165 | 167 | ||
166 | ssize_t write(int fd, const void *buf, size_t count) |
168 | ssize_t write(int fd, const void *buf, size_t count) |
167 | { |
169 | { |
Line 187... | Line 189... | ||
187 | return -1; |
189 | return -1; |
188 | return streams[fd].phone; |
190 | return streams[fd].phone; |
189 | } |
191 | } |
190 | 192 | ||
191 | 193 | ||
192 | /** @} |
194 | /** @} |
193 | */ |
195 | */ |
194 | - | ||
195 | - |