XMMS2
|
00001 #ifndef __XMMS_UTILS_H__ 00002 #define __XMMS_UTILS_H__ 00003 00004 #include <stdio.h> 00005 00006 #include "xmmsc/xmmsc_stdbool.h" 00007 00008 #define XMMS_STRINGIFY_NOEXPAND(x) #x 00009 #define XMMS_STRINGIFY(x) XMMS_STRINGIFY_NOEXPAND(x) 00010 00011 #define x_return_if_fail(expr) if (!(expr)) { fprintf (stderr, "Failed in file " __FILE__ " on row %d\n", __LINE__); return; } 00012 #define x_return_val_if_fail(expr, val) if (!(expr)) { fprintf (stderr, "Failed in file " __FILE__ " on row %d\n", __LINE__); return val; } 00013 #define x_return_null_if_fail(expr) x_return_val_if_fail (expr, NULL) 00014 #define x_oom() do { fprintf(stderr, "Out of memory in " __FILE__ "on row %d\n", __LINE__); } while (0) 00015 #define x_new0(type, num) calloc (1, sizeof (type) * (num)) 00016 #define x_new(type, num) malloc (sizeof (type) * (num)) 00017 #define x_malloc0(size) calloc (1, size) 00018 #define x_malloc(size) malloc (size) 00019 00020 /* This is not nice but there's no very clean way around the ugly warnings, 00021 * glibc does about the same but on compile time (this could be moved to waf?) */ 00022 #if defined(__x86_64__) 00023 # define XPOINTER_TO_INT(p) ((int) (long) (p)) 00024 # define XPOINTER_TO_UINT(p) ((unsigned int) (unsigned long) (p)) 00025 # define XINT_TO_POINTER(i) ((void *) (long) (i)) 00026 # define XUINT_TO_POINTER(u) ((void *) (unsigned long) (u)) 00027 #else 00028 # define XPOINTER_TO_INT(p) ((int) (p)) 00029 # define XPOINTER_TO_UINT(p) ((unsigned int) (p)) 00030 # define XINT_TO_POINTER(i) ((void *) (i)) 00031 # define XUINT_TO_POINTER(u) ((void *) (u)) 00032 #endif 00033 00034 #ifndef MIN 00035 # define MIN(a, b) (((a) < (b)) ? (a) : (b)) 00036 #endif 00037 00038 #ifndef X_N_ELEMENTS 00039 # define X_N_ELEMENTS(a) (sizeof (a) / sizeof ((a)[0])) 00040 #endif 00041 00042 #define XMMS_PATH_MAX 255 00043 00044 /* 9667 is XMMS written on a phone */ 00045 #define XMMS_DEFAULT_TCP_PORT 9667 00046 00047 const char *xmms_userconfdir_get (char *buf, int len); 00048 const char *xmms_usercachedir_get (char *buf, int len); 00049 const char *xmms_default_ipcpath_get (char *buf, int len); 00050 const char *xmms_fallback_ipcpath_get (char *buf, int len); 00051 bool xmms_sleep_ms (int n); 00052 00053 #endif /* __XMMS_UTILS_H__ */