diff options
Diffstat (limited to 'common.h')
-rw-r--r-- | common.h | 44 |
1 files changed, 31 insertions, 13 deletions
@@ -60,6 +60,10 @@ #error Cannot enable c2 debugging without c2 support. #endif +#ifndef COMPTON_VERSION +#define COMPTON_VERSION "unknown" +#endif + // === Includes === // For some special functions @@ -132,6 +136,12 @@ #define MSTR_(s) #s #define MSTR(s) MSTR_(s) +/// @brief Wrapper for gcc branch prediction builtin, for likely branch. +#define likely(x) __builtin_expect(!!(x), 1) + +/// @brief Wrapper for gcc branch prediction builtin, for unlikely branch. +#define unlikely(x) __builtin_expect(!!(x), 0) + /// Print out an error message. #define printf_err(format, ...) \ fprintf(stderr, format "\n", ## __VA_ARGS__) @@ -431,9 +441,13 @@ typedef struct { // === General === /// The configuration file we used. char *config_file; + /// Path to write PID to. + char *write_pid_path; /// The display name we used. NULL means we are using the value of the /// <code>DISPLAY</code> environment variable. char *display; + /// Safe representation of display name. + char *display_repr; /// The backend in use. enum backend backend; /// Whether to avoid using stencil buffer under GLX backend. Might be @@ -986,7 +1000,7 @@ typedef struct _win { /// _NET_WM_OPACITY value opacity_t opacity_prop_client; /// Last window opacity value we set. - long opacity_set; + opacity_t opacity_set; // Fading-related members /// Do not fade if it's false. Change on window type change. @@ -1150,6 +1164,15 @@ allocchk_(const char *func_name, void *ptr) { /// @brief Wrapper of allocchk_(). #define allocchk(ptr) allocchk_(__func__, ptr) +/// @brief Wrapper of malloc(). +#define cmalloc(nmemb, type) ((type *) allocchk(malloc((nmemb) * sizeof(type)))) + +/// @brief Wrapper of calloc(). +#define ccalloc(nmemb, type) ((type *) allocchk(calloc((nmemb), sizeof(type)))) + +/// @brief Wrapper of ealloc(). +#define crealloc(ptr, nmemb, type) ((type *) allocchk(realloc((ptr), (nmemb) * sizeof(type)))) + /** * Return whether a struct timeval value is empty. */ @@ -1310,10 +1333,7 @@ print_timestamp(session_t *ps) { */ static inline char * mstrcpy(const char *src) { - char *str = malloc(sizeof(char) * (strlen(src) + 1)); - - if (!str) - printf_errfq(1, "(): Failed to allocate memory."); + char *str = cmalloc(strlen(src) + 1, char); strcpy(str, src); @@ -1325,10 +1345,7 @@ mstrcpy(const char *src) { */ static inline char * mstrncpy(const char *src, unsigned len) { - char *str = malloc(sizeof(char) * (len + 1)); - - if (!str) - printf_errfq(1, "(): Failed to allocate memory."); + char *str = cmalloc(len + 1, char); strncpy(str, src, len); str[len] = '\0'; @@ -1341,7 +1358,7 @@ mstrncpy(const char *src, unsigned len) { */ static inline char * mstrjoin(const char *src1, const char *src2) { - char *str = malloc(sizeof(char) * (strlen(src1) + strlen(src2) + 1)); + char *str = cmalloc(strlen(src1) + strlen(src2) + 1, char); strcpy(str, src1); strcat(str, src2); @@ -1354,8 +1371,8 @@ mstrjoin(const char *src1, const char *src2) { */ static inline char * mstrjoin3(const char *src1, const char *src2, const char *src3) { - char *str = malloc(sizeof(char) * (strlen(src1) + strlen(src2) - + strlen(src3) + 1)); + char *str = cmalloc(strlen(src1) + strlen(src2) + + strlen(src3) + 1, char); strcpy(str, src1); strcat(str, src2); @@ -1369,7 +1386,8 @@ mstrjoin3(const char *src1, const char *src2, const char *src3) { */ static inline void mstrextend(char **psrc1, const char *src2) { - *psrc1 = realloc(*psrc1, (*psrc1 ? strlen(*psrc1): 0) + strlen(src2) + 1); + *psrc1 = crealloc(*psrc1, (*psrc1 ? strlen(*psrc1): 0) + strlen(src2) + 1, + char); strcat(*psrc1, src2); } |