Skip to content

Commit

Permalink
Merge pull request #946 from Kijewski/native-write
Browse files Browse the repository at this point in the history
native: don't use RIOT read/write in UART
  • Loading branch information
LudwigKnuepfer committed Apr 9, 2014
2 parents fd7217b + 0b75a11 commit 9f24ae2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions boards/native/drivers/native-uart0.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int uart0_puts(char *astring, int length)

while (
(length - offset > 0) && (
(nwritten = write(
(nwritten = _native_write(
STDOUT_FILENO,
astring+offset,
length-offset)
Expand Down Expand Up @@ -168,7 +168,7 @@ void handle_uart_in()

DEBUG("handle_uart_in\n");

nread = read(STDIN_FILENO, buf, sizeof(buf));
nread = _native_read(STDIN_FILENO, buf, sizeof(buf));
if (nread == -1) {
err(1, "handle_uart_in(): read()");
}
Expand Down
2 changes: 2 additions & 0 deletions cpu/native/include/native_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ extern char **_native_argv;
extern fd_set _native_rfds;
#endif

ssize_t _native_read(int fd, void *buf, size_t count);
ssize_t _native_write(int fd, const void *buf, size_t count);

/**
* register interrupt handler handler for interrupt sig
Expand Down
2 changes: 1 addition & 1 deletion cpu/native/net/tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ int8_t send_buf(radio_packet_t *packet)

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

if ((nsent = write(_native_tap_fd, buf, to_send)) == -1) {;
if ((nsent = _native_write(_native_tap_fd, buf, to_send)) == -1) {;
warn("write");
return -1;
}
Expand Down
37 changes: 18 additions & 19 deletions cpu/native/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void *realloc(void *ptr, size_t size)
return r;
}

ssize_t read(int fd, void *buf, size_t count)
ssize_t _native_read(int fd, void *buf, size_t count)
{
ssize_t r;

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

ssize_t write(int fd, const void *buf, size_t count)
ssize_t _native_write(int fd, const void *buf, size_t count)
{
ssize_t r;

_native_syscall_enter();
//real_write(fd, "real_write: ", 12);
r = real_write(fd, buf, count);
_native_syscall_leave();

return r;
}

int putchar(int c) {
write(STDOUT_FILENO, &c, 1);
_native_write(STDOUT_FILENO, &c, 1);
return 0;
}

int puts(const char *s)
{
int r;
r = write(STDOUT_FILENO, (char*)s, strlen(s));
r = _native_write(STDOUT_FILENO, (char*)s, strlen(s));
putchar('\n');
return r;
}
Expand Down Expand Up @@ -213,7 +212,7 @@ int printf(const char *format, ...)
if ((m = make_message(format, argp)) == NULL) {
err(EXIT_FAILURE, "malloc");
}
r = write(STDOUT_FILENO, m, strlen(m));
r = _native_write(STDOUT_FILENO, m, strlen(m));
va_end(argp);
free(m);

Expand All @@ -229,7 +228,7 @@ int vprintf(const char *format, va_list argp)
if ((m = make_message(format, argp)) == NULL) {
err(EXIT_FAILURE, "malloc");
}
r = write(STDOUT_FILENO, m, strlen(m));
r = _native_write(STDOUT_FILENO, m, strlen(m));
free(m);

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

if ((m = make_message(fmt, args)) == NULL) {
write(STDERR_FILENO, "malloc\n", 7);
_native_write(STDERR_FILENO, "malloc\n", 7);
exit(EXIT_FAILURE);
}
write(STDERR_FILENO, _progname, strlen(_progname));
write(STDERR_FILENO, ": ", 2);
write(STDERR_FILENO, m, strlen(m));
write(STDERR_FILENO, ": ", 2);
write(STDERR_FILENO, e, strlen(e));
write(STDERR_FILENO, "\n", 1);
_native_write(STDERR_FILENO, _progname, strlen(_progname));
_native_write(STDERR_FILENO, ": ", 2);
_native_write(STDERR_FILENO, m, strlen(m));
_native_write(STDERR_FILENO, ": ", 2);
_native_write(STDERR_FILENO, e, strlen(e));
_native_write(STDERR_FILENO, "\n", 1);
free(m);
}

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

if ((m = make_message(fmt, args)) == NULL) {
write(STDERR_FILENO, "malloc\n", 7);
_native_write(STDERR_FILENO, "malloc\n", 7);
exit(EXIT_FAILURE);
}
write(STDERR_FILENO, _progname, strlen(_progname));
write(STDERR_FILENO, ": ", 2);
write(STDERR_FILENO, m, strlen(m));
write(STDERR_FILENO, "\n", 1);
_native_write(STDERR_FILENO, _progname, strlen(_progname));
_native_write(STDERR_FILENO, ": ", 2);
_native_write(STDERR_FILENO, m, strlen(m));
_native_write(STDERR_FILENO, "\n", 1);
free(m);
}

Expand Down

0 comments on commit 9f24ae2

Please sign in to comment.