diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-07-05 00:56:42 +0200 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-07-05 00:56:42 +0200 |
| commit | 1b2029dbbbfdafb618aca3eccdbbba2512b5b49b (patch) | |
| tree | e9729b2f6ece1819c6def1d736260cf234c3fe87 /kel_rap/c++ | |
| parent | 0283191ec906adaa1cb0738b5cb20044b01bb572 (diff) | |
| download | apps-dev_tools-1b2029dbbbfdafb618aca3eccdbbba2512b5b49b.tar.gz | |
Diffstat (limited to 'kel_rap/c++')
| -rw-r--r-- | kel_rap/c++/SConscript | 32 | ||||
| -rw-r--r-- | kel_rap/c++/kel_rap.cpp | 51 |
2 files changed, 83 insertions, 0 deletions
diff --git a/kel_rap/c++/SConscript b/kel_rap/c++/SConscript new file mode 100644 index 0000000..bfcedae --- /dev/null +++ b/kel_rap/c++/SConscript @@ -0,0 +1,32 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +program_env = env.Clone(); + +program_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +program_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += program_env.sources; +env.headers += program_env.headers; + +## Static lib +objects_static = [] +program_env.add_source_files(objects_static, program_env.sources, shared=False); +env.binary = program_env.Program('#build/kel_rap', [objects_static]); + +# Set Alias +env.Alias('binary', [env.binary]); + +env.targets += ['binary']; + +# Install +env.Install('$prefix/bin/', [env.binary]); diff --git a/kel_rap/c++/kel_rap.cpp b/kel_rap/c++/kel_rap.cpp new file mode 100644 index 0000000..d505125 --- /dev/null +++ b/kel_rap/c++/kel_rap.cpp @@ -0,0 +1,51 @@ +#include <array> +#include <filesystem> +#include <iostream> +#include <string> + +#include <sys/types.h> +#include <sys/wait.h> +#include <unistd.h> + +namespace fs = std::filesystem; + +int main(int argc, char* argv[]) { + if (argc != 2) { + std::cerr << "Usage: " << argv[0] << " <dir>\n"; + return -1; + } + + for (const auto& e : fs::directory_iterator(argv[1])) { + if (!e.is_regular_file()) + continue; + + std::string path = e.path().string(); + + pid_t pid = fork(); + if (pid < 0) { + std::cerr << "fork failed\n"; + return -1; + } + + if (pid == 0) { + std::string path = e.path().string(); + std::array<char*, 2> args{ + path.data(), + nullptr + }; + + execvp(args[0], args.data()); + + std::cerr << "execvp failed: " << path << '\n'; + return -1; + } + + int status; + if (waitpid(pid, &status, 0) < 0) { + std::cerr << "waitpid failed\n"; + return -1; + } + } + + return 0; +} |
