OSDN Git Service

NOEXIT(thingy()) wrapper to turn xwrap() functions into warning versions.
authorRob Landley <rob@landley.net>
Sun, 8 Nov 2015 22:47:52 +0000 (16:47 -0600)
committerRob Landley <rob@landley.net>
Sun, 8 Nov 2015 22:47:52 +0000 (16:47 -0600)
Also WOULD_EXIT(x, thingy()) to set a variable to 1 or 0 showing whether or
not thingy() tried to exit. I'd love to be able to do "x = NOEXIT(thingy());"
but haven't figured out a syntax to make that work yet...

lib/lib.h

index ad59989..301c50f 100644 (file)
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -256,5 +256,16 @@ void names_to_pid(char **names, int (*callback)(pid_t pid, char *name));
 pid_t xvforkwrap(pid_t pid);
 #define XVFORK() xvforkwrap(vfork())
 
+#define WOULD_EXIT(y, x) { jmp_buf _noexit; \
+  int _noexit_res; \
+  toys.rebound = &_noexit; \
+  _noexit_res = setjmp(_noexit); \
+  if (!_noexit_res) do {x;} while(0); \
+  toys.rebound = 0; \
+  y = _noexit_res; \
+}
+
+#define NOEXIT(x) WOULD_EXIT(_noexit_res, x)
+
 // Functions in need of further review/cleanup
 #include "lib/pending.h"