XMMS2
xmmsc_util.h
Go to the documentation of this file.
1 #ifndef __XMMS_UTILS_H__
2 #define __XMMS_UTILS_H__
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 
7 #include "xmmsc/xmmsc_stdbool.h"
8 
9 #define XMMS_STRINGIFY_NOEXPAND(x) #x
10 #define XMMS_STRINGIFY(x) XMMS_STRINGIFY_NOEXPAND(x)
11 
12 #define x_return_if_fail(expr) if (!(expr)) { fprintf (stderr, "Failed in file " __FILE__ " on row %d\n", __LINE__); return; }
13 #define x_return_val_if_fail(expr, val) if (!(expr)) { fprintf (stderr, "Failed in file " __FILE__ " on row %d\n", __LINE__); return val; }
14 #define x_return_null_if_fail(expr) x_return_val_if_fail (expr, NULL)
15 #define x_oom() do { fprintf(stderr, "Out of memory in " __FILE__ "on row %d\n", __LINE__); } while (0)
16 #define x_new0(type, num) calloc (1, sizeof (type) * (num))
17 #define x_new(type, num) malloc (sizeof (type) * (num))
18 #define x_malloc0(size) calloc (1, size)
19 #define x_malloc(size) malloc (size)
20 
21 /* This is not nice but there's no very clean way around the ugly warnings,
22  * glibc does about the same but on compile time (this could be moved to waf?) */
23 #if defined(__x86_64__)
24 # define XPOINTER_TO_INT(p) ((int) (long) (p))
25 # define XPOINTER_TO_UINT(p) ((unsigned int) (unsigned long) (p))
26 # define XINT_TO_POINTER(i) ((void *) (long) (i))
27 # define XUINT_TO_POINTER(u) ((void *) (unsigned long) (u))
28 #else
29 # define XPOINTER_TO_INT(p) ((int) (p))
30 # define XPOINTER_TO_UINT(p) ((unsigned int) (p))
31 # define XINT_TO_POINTER(i) ((void *) (i))
32 # define XUINT_TO_POINTER(u) ((void *) (u))
33 #endif
34 
35 #ifndef MIN
36 # define MIN(a, b) (((a) < (b)) ? (a) : (b))
37 #endif
38 
39 #ifndef X_N_ELEMENTS
40 # define X_N_ELEMENTS(a) (sizeof (a) / sizeof ((a)[0]))
41 #endif
42 
43 #define XMMS_PATH_MAX 255
44 
45 /* 9667 is XMMS written on a phone */
46 #define XMMS_DEFAULT_TCP_PORT 9667
47 
48 const char *xmms_userconfdir_get (char *buf, int len);
49 const char *xmms_usercachedir_get (char *buf, int len);
50 const char *xmms_default_ipcpath_get (char *buf, int len);
51 const char *xmms_fallback_ipcpath_get (char *buf, int len);
52 bool xmms_sleep_ms (int n);
53 
54 #endif /* __XMMS_UTILS_H__ */
const char * xmms_usercachedir_get(char *buf, int len)
Get the absolute path to the user cache dir.
Definition: utils_unix.c:67
bool xmms_sleep_ms(int n)
Sleep for n milliseconds.
Definition: utils_unix.c:114
const char * xmms_default_ipcpath_get(char *buf, int len)
Get the default connection path.
Definition: utils.c:35
const char * xmms_userconfdir_get(char *buf, int len)
Get the absolute path to the user config dir.
Definition: utils_unix.c:80
const char * xmms_fallback_ipcpath_get(char *buf, int len)
Get the fallback connection path (if XMMS_PATH is not accessible)
Definition: utils_unix.c:93