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