-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathutil.c
73 lines (59 loc) · 1.2 KB
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* See LICENSE file for copyright and license details. */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xcb/xcb.h>
#include "util.h"
int
pscanf(const char *path, const char *fmt, ...)
{
FILE *fp;
va_list ap;
int n;
if (!(fp = fopen(path, "r"))) {
return -1;
}
va_start(ap, fmt);
n = vfscanf(fp, fmt, ap);
va_end(ap);
fclose(fp);
return (n == EOF) ? -1 : n;
}
void
list_init(list_head *head, list_head *prev, list_head *next)
{
next->prev = head;
head->next = next;
head->prev = prev;
prev->next = head;
}
void
list_add(list_head *head, list_head *entry)
{
list_init(entry, head, head->next);
}
void
list_add_tail(list_head *head, list_head *entry)
{
list_init(entry, head->prev, head);
}
void
list_del(list_head *head)
{
list_head *prev = head->prev;
list_head *next = head->next;
next->prev = prev;
prev->next = next;
}
xcb_atom_t
xcb_atom_get(xcb_connection_t *xcb, const char *name, bool only_exists)
{
xcb_atom_t atom;
xcb_intern_atom_reply_t *atom_reply;
if (!(atom_reply = xcb_intern_atom_reply(xcb, xcb_intern_atom(xcb, only_exists, strlen(name), name), NULL)))
return 0;
atom = atom_reply->atom;
free(atom_reply);
return atom;
}