for (Con *child = (Con*)-1; (child == (Con*)-1) && ((child = 0), true);) \
TAILQ_FOREACH(child, &((head)->nodes_head), nodes)
+#define NODES_FOREACH_REVERSE(head) \
+ for (Con *child = (Con*)-1; (child == (Con*)-1) && ((child = 0), true);) \
+ TAILQ_FOREACH_REVERSE(child, &((head)->nodes_head), nodes_head, nodes)
+
/* greps the ->nodes of the given head and returns the first node that matches the given condition */
#define GREP_FIRST(dest, head, condition) \
NODES_FOREACH(head) { \
*/
void start_application(const char *command);
+/**
+ * exec()s an i3 utility, for example the config file migration script or
+ * i3-nagbar. This function first searches $PATH for the given utility named,
+ * then falls back to the dirname() of the i3 executable path and then falls
+ * back to the dirname() of the target of /proc/self/exe (on linux).
+ *
+ * This function should be called after fork()ing.
+ *
+ * The first argument of the given argv vector will be overwritten with the
+ * executable name, so pass NULL.
+ *
+ * If the utility cannot be found in any of these locations, it exits with
+ * return code 2.
+ *
+ */
+void exec_i3_utility(char *name, char *argv[]);
+
/**
* Checks a generic cookie for errors and quits with the given message if
* there was an error.
*/
void i3_restart(bool forget_layout);
+#if defined(__OpenBSD__) || defined(__APPLE__)
+
+/*
+ * Taken from FreeBSD
+ * Find the first occurrence of the byte string s in byte string l.
+ *
+ */
+void *memmem(const void *l, size_t l_len, const void *s, size_t s_len);
+
+#endif
+
+#if defined(__APPLE__)
+
+/*
+ * Taken from FreeBSD
+ * Returns a pointer to a new string which is a duplicate of the
+ * string, but only copies at most n characters.
+ *
+ */
+char *strndup(const char *str, size_t n);
+
+#endif
+
#endif