Add libinput_create_from_path
[platform/upstream/libinput.git] / src / libinput-util.c
1 /*
2  * Copyright © 2008-2011 Kristian Høgsberg
3  * Copyright © 2011 Intel Corporation
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and its
6  * documentation for any purpose is hereby granted without fee, provided that
7  * the above copyright notice appear in all copies and that both that copyright
8  * notice and this permission notice appear in supporting documentation, and
9  * that the name of the copyright holders not be used in advertising or
10  * publicity pertaining to distribution of the software without specific,
11  * written prior permission.  The copyright holders make no representations
12  * about the suitability of this software for any purpose.  It is provided "as
13  * is" without express or implied warranty.
14  *
15  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21  * OF THIS SOFTWARE.
22  */
23
24 /*
25  * This list data structure is verbatim copy from wayland-util.h from the
26  * Wayland project; except that wl_ prefix has been removed.
27  */
28
29 #include "config.h"
30
31 #include <stdarg.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34
35 #include "libinput-util.h"
36 #include "libinput-private.h"
37
38 static FILE *g_log_file = NULL;
39
40 void
41 set_logging_enabled(int enabled)
42 {
43         g_log_file = enabled ? stdout : NULL;
44 }
45
46 void
47 log_info(const char *format, ...)
48 {
49         va_list ap;
50
51         if (g_log_file) {
52                 va_start(ap, format);
53                 vfprintf(g_log_file, format, ap);
54                 va_end(ap);
55         }
56 }
57
58 void
59 list_init(struct list *list)
60 {
61         list->prev = list;
62         list->next = list;
63 }
64
65 void
66 list_insert(struct list *list, struct list *elm)
67 {
68         elm->prev = list;
69         elm->next = list->next;
70         list->next = elm;
71         elm->next->prev = elm;
72 }
73
74 void
75 list_remove(struct list *elm)
76 {
77         elm->prev->next = elm->next;
78         elm->next->prev = elm->prev;
79         elm->next = NULL;
80         elm->prev = NULL;
81 }
82
83 int
84 list_empty(const struct list *list)
85 {
86         return list->next == list;
87 }