diff options
| author | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:29:19 +0300 |
|---|---|---|
| committer | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:29:19 +0300 |
| commit | 85f60af1bb558bc7248fb64528c5bba92e504adf (patch) | |
| tree | ddb4ab72a5ca33b668b34ecdb09fe284c5644677 /corebinutils/sh/testcmd.c | |
| parent | 96be0a182e0b889a9daf43c04a0b835aa604d280 (diff) | |
| parent | 126b33a9db9b44a56f2c62d18346746ec1330766 (diff) | |
| download | Project-Tick-85f60af1bb558bc7248fb64528c5bba92e504adf.tar.gz Project-Tick-85f60af1bb558bc7248fb64528c5bba92e504adf.zip | |
Add 'corebinutils/sh/' from commit '126b33a9db9b44a56f2c62d18346746ec1330766'
git-subtree-dir: corebinutils/sh
git-subtree-mainline: 96be0a182e0b889a9daf43c04a0b835aa604d280
git-subtree-split: 126b33a9db9b44a56f2c62d18346746ec1330766
Diffstat (limited to 'corebinutils/sh/testcmd.c')
| -rw-r--r-- | corebinutils/sh/testcmd.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/corebinutils/sh/testcmd.c b/corebinutils/sh/testcmd.c new file mode 100644 index 0000000000..d82d3c9e45 --- /dev/null +++ b/corebinutils/sh/testcmd.c @@ -0,0 +1,34 @@ +/* + * Reuse the standalone test(1) parser as the shell builtin entry point. + * The external source now exports main() and exits on syntax errors, so + * provide a wrapper that maps its process-exit path back to a builtin + * return value. + */ + +#include <setjmp.h> +#include <stdio.h> + +static jmp_buf testcmd_jmp; +static int testcmd_status; + +static void +testcmd_exit(int status) +{ + testcmd_status = status; + fflush(NULL); + longjmp(testcmd_jmp, 1); +} + +#define exit testcmd_exit +#define main testcmd_main +#include "../../bin/test/test.c" +#undef main +#undef exit + +int +testcmd(int argc, char **argv) +{ + if (setjmp(testcmd_jmp) != 0) + return testcmd_status; + return testcmd_main(argc, argv); +} |
