BuildSystem: Cleanup userspace directory layout
userspace programs are now in userspace/programs userspace tests are now in userspace/tests This makes listing userspace projects much cleaner. Libraries were already separated to their own directory, so other programs should also.
This commit is contained in:
8
userspace/tests/test-popen/CMakeLists.txt
Normal file
8
userspace/tests/test-popen/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(test-popen ${SOURCES})
|
||||
banan_link_library(test-popen libc)
|
||||
|
||||
install(TARGETS test-popen OPTIONAL)
|
||||
30
userspace/tests/test-popen/main.cpp
Normal file
30
userspace/tests/test-popen/main.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user