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/programs/u8sum/CMakeLists.txt
Normal file
8
userspace/programs/u8sum/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(u8sum ${SOURCES})
|
||||
banan_link_library(u8sum libc)
|
||||
|
||||
install(TARGETS u8sum OPTIONAL)
|
||||
29
userspace/programs/u8sum/main.cpp
Normal file
29
userspace/programs/u8sum/main.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
FILE* fp = fopen(argv[i], "r");
|
||||
if (fp == nullptr)
|
||||
{
|
||||
perror("fopen");
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t sum = 0;
|
||||
|
||||
uint8_t buffer[1024];
|
||||
while (size_t ret = fread(buffer, 1, sizeof(buffer), fp))
|
||||
for (size_t j = 0; j < ret; j++)
|
||||
sum += buffer[j];
|
||||
|
||||
if (ferror(fp))
|
||||
perror("fread");
|
||||
else
|
||||
printf("%s: %02x\n", argv[i], sum);
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user