]> git.sur5r.net Git - i3/i3/blob - src/util.c
Move stuff to include/ and src/
[i3/i3] / src / util.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5
6 #include "i3.h"
7
8 /*
9  * Starts the given application with the given args.
10  *
11  */
12 void start_application(const char *path, const char *args) {
13         pid_t pid;
14         if ((pid = vfork()) == 0) {
15                 /* This is the child */
16                 char *argv[2];
17                 /* TODO: For now, we ignore args. Later on, they should be parsed
18                    correctly (like in the shell?) */
19                 argv[0] = strdup(path);
20                 argv[1] = NULL;
21                 execve(path, argv, environment);
22                 /* not reached */
23         }
24 }
25
26 /*
27  * Checks a generic cookie for errors and quits with the given message if there
28  * was an error.
29  *
30  */
31 void check_error(xcb_connection_t *connection, xcb_void_cookie_t cookie, char *err_message) {
32         xcb_generic_error_t *error = xcb_request_check(connection, cookie);
33         if (error != NULL) {
34                 fprintf(stderr, "ERROR: %s : %d\n", err_message , error->error_code);
35                 xcb_disconnect(connection);
36                 exit(-1);
37         }
38 }