aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMango0x45 <thomasvoss@live.com>2021-01-18 21:57:58 +0000
committerMango0x45 <thomasvoss@live.com>2021-01-18 21:57:58 +0000
commitb35df7c07c59f553de4fa2903dc3185136a45f1d (patch)
treeeae31364fd1a6a06c513813134aadc21e717a53b /utils
parent660f1b7a2cdc32e90f33bfa6630ea7529001cc13 (diff)
downloadsteve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.tar
steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.tar.gz
steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.tar.bz2
steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.tar.lz
steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.tar.xz
steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.tar.zst
steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.zip
Search for BC in the PATH
Diffstat (limited to 'utils')
-rw-r--r--utils/math.c64
-rw-r--r--utils/math.h16
2 files changed, 40 insertions, 40 deletions
diff --git a/utils/math.c b/utils/math.c
index 25ae645..0eb1dc3 100644
--- a/utils/math.c
+++ b/utils/math.c
@@ -21,43 +21,43 @@ bool timeout = false, child_done = false;
void timeout_hander(int UNUSED(sig))
{
- timeout = true;
+ timeout = true;
}
void child_handler(int UNUSED(sig))
{
- child_done = true;
+ child_done = true;
}
int main(void)
{
- pid_t pid = fork();
- switch (pid) {
- case 0:
- execl("/bin/bc", "", "-q", "bc_funcs/lib.bc", "bc_funcs/init.bc",
- FILE_NAME, "bc_funcs/exit.bc", NULL);
- fallthrough;
- case -1:
- perror("calc");
- return EXIT_FAILURE;
- default:
- /* Setup signal handlers after fork so the child doesnt inherit them */
- signal(SIGALRM, timeout_hander);
- signal(SIGCHLD, child_handler);
- alarm(TIMEOUT);
- pause();
-
- /*
- * Wait for either the child process to terminate, or for 5 seconds to
- * have passed
- */
- if (timeout) {
- puts("Error: 5 second timeout reached");
- kill(pid, 9);
- }
-
- break;
- }
-
- return EXIT_SUCCESS;
-} \ No newline at end of file
+ pid_t pid = fork();
+ switch (pid) {
+ case 0:
+ execlp("bc", "bc", "-q", "bc_funcs/lib.bc", "bc_funcs/init.bc",
+ FILE_NAME, "bc_funcs/exit.bc", NULL);
+ fallthrough;
+ case -1:
+ perror("calc");
+ return EXIT_FAILURE;
+ default:
+ /* Setup signal handlers after fork so the child doesnt inherit them */
+ signal(SIGALRM, timeout_hander);
+ signal(SIGCHLD, child_handler);
+ alarm(TIMEOUT);
+ pause();
+
+ /*
+ * Wait for either the child process to terminate, or for 5 seconds to
+ * have passed
+ */
+ if (timeout) {
+ puts("Error: 5 second timeout reached");
+ kill(pid, 9);
+ }
+
+ break;
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/utils/math.h b/utils/math.h
index edfb9ee..561205a 100644
--- a/utils/math.h
+++ b/utils/math.h
@@ -3,24 +3,24 @@
/* Suppress unused parameter warnings */
#ifdef __GNUC__
-# define UNUSED(x) UNUSED_##x __attribute__((__unused__))
+# define UNUSED(x) UNUSED_##x __attribute__((__unused__))
#else
-# define UNUSED(x) UNUSED_##x
+# define UNUSED(x) UNUSED_##x
#endif
/* Fallthrough pseudo-keyword macro */
#if __has_attribute(__fallthrough__)
-# define fallthrough __attribute__((__fallthrough__))
+# define fallthrough __attribute__((__fallthrough__))
#else
-# define fallthrough \
- do { \
- } while (0) /* fallthrough */
+# define fallthrough \
+ do { \
+ } while (0) /* fallthrough */
#endif
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
-#define FILE_NAME "bc_input.bc"
-#define TIMEOUT 5
+#define FILE_NAME "bc_input.bc"
+#define TIMEOUT 5
/* Signal handlers */
void timeout_hander(int sig);