diff --git a/userspace/CMakeLists.txt b/userspace/CMakeLists.txt index facadf4677..85e158a3b7 100644 --- a/userspace/CMakeLists.txt +++ b/userspace/CMakeLists.txt @@ -34,6 +34,7 @@ set(USERSPACE_PROJECTS test-framebuffer test-globals test-mouse + test-popen test-sort test-tcp test-udp diff --git a/userspace/test-popen/CMakeLists.txt b/userspace/test-popen/CMakeLists.txt new file mode 100644 index 0000000000..02c38f23c4 --- /dev/null +++ b/userspace/test-popen/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.26) + +project(test-popen CXX) + +set(SOURCES + main.cpp +) + +add_executable(test-popen ${SOURCES}) +target_compile_options(test-popen PUBLIC -O2 -g) +target_link_libraries(test-popen PUBLIC libc) + +add_custom_target(test-popen-install + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/test-popen ${BANAN_BIN}/ + DEPENDS test-popen +) diff --git a/userspace/test-popen/main.cpp b/userspace/test-popen/main.cpp new file mode 100644 index 0000000000..89d4cede32 --- /dev/null +++ b/userspace/test-popen/main.cpp @@ -0,0 +1,30 @@ +#include +#include + +int main(int argc, char** argv) +{ + if (argc != 2) + { + fprintf(stderr, "usage: %s COMMAND\n", argv[0]); + return 1; + } + + FILE* fp = popen(argv[1], "r"); + if (fp == nullptr) + { + perror("popen"); + return 1; + } + + char buffer[128]; + while (fgets(buffer, sizeof(buffer), fp) != NULL) + printf("%s", buffer); + + if (pclose(fp) == -1) + { + perror("pclose"); + return 1; + } + + return 0; +}