Skip to content

Commit 9f24ae2

Browse files
Merge pull request #946 from Kijewski/native-write
native: don't use RIOT read/write in UART
2 parents fd7217b + 0b75a11 commit 9f24ae2

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

boards/native/drivers/native-uart0.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int uart0_puts(char *astring, int length)
5757

5858
while (
5959
(length - offset > 0) && (
60-
(nwritten = write(
60+
(nwritten = _native_write(
6161
STDOUT_FILENO,
6262
astring+offset,
6363
length-offset)
@@ -168,7 +168,7 @@ void handle_uart_in()
168168

169169
DEBUG("handle_uart_in\n");
170170

171-
nread = read(STDIN_FILENO, buf, sizeof(buf));
171+
nread = _native_read(STDIN_FILENO, buf, sizeof(buf));
172172
if (nread == -1) {
173173
err(1, "handle_uart_in(): read()");
174174
}

cpu/native/include/native_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ extern char **_native_argv;
6161
extern fd_set _native_rfds;
6262
#endif
6363

64+
ssize_t _native_read(int fd, void *buf, size_t count);
65+
ssize_t _native_write(int fd, const void *buf, size_t count);
6466

6567
/**
6668
* register interrupt handler handler for interrupt sig

cpu/native/net/tap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ int8_t send_buf(radio_packet_t *packet)
219219

220220
DEBUG("send_buf: trying to send %d bytes\n", to_send);
221221

222-
if ((nsent = write(_native_tap_fd, buf, to_send)) == -1) {;
222+
if ((nsent = _native_write(_native_tap_fd, buf, to_send)) == -1) {;
223223
warn("write");
224224
return -1;
225225
}

cpu/native/syscalls.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void *realloc(void *ptr, size_t size)
141141
return r;
142142
}
143143

144-
ssize_t read(int fd, void *buf, size_t count)
144+
ssize_t _native_read(int fd, void *buf, size_t count)
145145
{
146146
ssize_t r;
147147

@@ -152,27 +152,26 @@ ssize_t read(int fd, void *buf, size_t count)
152152
return r;
153153
}
154154

155-
ssize_t write(int fd, const void *buf, size_t count)
155+
ssize_t _native_write(int fd, const void *buf, size_t count)
156156
{
157157
ssize_t r;
158158

159159
_native_syscall_enter();
160-
//real_write(fd, "real_write: ", 12);
161160
r = real_write(fd, buf, count);
162161
_native_syscall_leave();
163162

164163
return r;
165164
}
166165

167166
int putchar(int c) {
168-
write(STDOUT_FILENO, &c, 1);
167+
_native_write(STDOUT_FILENO, &c, 1);
169168
return 0;
170169
}
171170

172171
int puts(const char *s)
173172
{
174173
int r;
175-
r = write(STDOUT_FILENO, (char*)s, strlen(s));
174+
r = _native_write(STDOUT_FILENO, (char*)s, strlen(s));
176175
putchar('\n');
177176
return r;
178177
}
@@ -213,7 +212,7 @@ int printf(const char *format, ...)
213212
if ((m = make_message(format, argp)) == NULL) {
214213
err(EXIT_FAILURE, "malloc");
215214
}
216-
r = write(STDOUT_FILENO, m, strlen(m));
215+
r = _native_write(STDOUT_FILENO, m, strlen(m));
217216
va_end(argp);
218217
free(m);
219218

@@ -229,7 +228,7 @@ int vprintf(const char *format, va_list argp)
229228
if ((m = make_message(format, argp)) == NULL) {
230229
err(EXIT_FAILURE, "malloc");
231230
}
232-
r = write(STDOUT_FILENO, m, strlen(m));
231+
r = _native_write(STDOUT_FILENO, m, strlen(m));
233232
free(m);
234233

235234
return r;
@@ -243,15 +242,15 @@ void vwarn(const char *fmt, va_list args)
243242
e = strerror(errno);
244243

245244
if ((m = make_message(fmt, args)) == NULL) {
246-
write(STDERR_FILENO, "malloc\n", 7);
245+
_native_write(STDERR_FILENO, "malloc\n", 7);
247246
exit(EXIT_FAILURE);
248247
}
249-
write(STDERR_FILENO, _progname, strlen(_progname));
250-
write(STDERR_FILENO, ": ", 2);
251-
write(STDERR_FILENO, m, strlen(m));
252-
write(STDERR_FILENO, ": ", 2);
253-
write(STDERR_FILENO, e, strlen(e));
254-
write(STDERR_FILENO, "\n", 1);
248+
_native_write(STDERR_FILENO, _progname, strlen(_progname));
249+
_native_write(STDERR_FILENO, ": ", 2);
250+
_native_write(STDERR_FILENO, m, strlen(m));
251+
_native_write(STDERR_FILENO, ": ", 2);
252+
_native_write(STDERR_FILENO, e, strlen(e));
253+
_native_write(STDERR_FILENO, "\n", 1);
255254
free(m);
256255
}
257256

@@ -260,13 +259,13 @@ void vwarnx(const char *fmt, va_list args)
260259
char *m;
261260

262261
if ((m = make_message(fmt, args)) == NULL) {
263-
write(STDERR_FILENO, "malloc\n", 7);
262+
_native_write(STDERR_FILENO, "malloc\n", 7);
264263
exit(EXIT_FAILURE);
265264
}
266-
write(STDERR_FILENO, _progname, strlen(_progname));
267-
write(STDERR_FILENO, ": ", 2);
268-
write(STDERR_FILENO, m, strlen(m));
269-
write(STDERR_FILENO, "\n", 1);
265+
_native_write(STDERR_FILENO, _progname, strlen(_progname));
266+
_native_write(STDERR_FILENO, ": ", 2);
267+
_native_write(STDERR_FILENO, m, strlen(m));
268+
_native_write(STDERR_FILENO, "\n", 1);
270269
free(m);
271270
}
272271

0 commit comments

Comments
 (0)