diff --git a/CMakeLists.txt b/CMakeLists.txt index a8c12e6..1be6a57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 2.6...4.1.1) project(C302 C) SET(CMAKE_BUILD_TYPE "Release") diff --git a/c302.c b/c302.c index 9a53ac9..dcd127f 100644 --- a/c302.c +++ b/c302.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include "c302.h" @@ -31,3 +32,18 @@ int main(int argc, char **argv) { }; return writev(1, (const struct iovec *)&iov, 4) != len+sizeof(uint32_t); } + +static void __attribute__((destructor)) defer_close_fp() { + fflush(stdout); + char buf[256]; + fd_set rfds; + struct timeval tv; + int ret; + FD_ZERO(&rfds); + FD_SET(0, &rfds); + tv.tv_sec = 1; + tv.tv_usec = 0; + if (select(1, &rfds, NULL, NULL, &tv) > 0 && FD_ISSET(0, &rfds)) { + read(0, buf, sizeof(buf)); + } +}