failed approach

This commit is contained in:
2020-11-19 18:24:03 +01:00
parent e25fd2f9b9
commit dd4cacb538
324 changed files with 57839 additions and 11 deletions

View File

@ -0,0 +1,36 @@
/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */
#include <gs/util/stdio.h>
#include <unistd.h>
#include <poll.h>
gs_error_t gs_stdio_putchar(int ch)
{
const int res = putchar(ch);
if (res < 0) {
return GS_ERROR_IO;
}
return GS_OK;
}
gs_error_t gs_stdio_getchar_timed(int timeout_ms, int * ch)
{
struct pollfd fds = {STDIN_FILENO, POLLIN, 0};
const int res = poll(&fds, 1, timeout_ms);
if (res == 0) {
return GS_ERROR_TIMEOUT;
}
if ((res > 0) && (fds.revents & POLLIN)) {
int tmp = getchar();
if (tmp >= 0) {
if (ch) {
*ch = tmp;
}
return GS_OK;
}
}
return GS_ERROR_IO;
}