Audacious  $Id:Doxyfile42802007-03-2104:39:00Znenolod$
core.h
Go to the documentation of this file.
1 /*
2  * core.h
3  * Copyright 2011 John Lindgren
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions, and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions, and the following disclaimer in the documentation
13  * provided with the distribution.
14  *
15  * This software is provided "as is" and without any warranty, express or
16  * implied. In no event shall the authors be liable for any damages arising from
17  * the use of this software.
18  */
19 
20 #ifndef LIBAUDCORE_CORE_H
21 #define LIBAUDCORE_CORE_H
22 
23 #undef NULL
24 #ifdef __cplusplus /* *sigh* */
25 #define NULL 0
26 #else
27 #define NULL ((void *) 0)
28 #endif
29 
30 /* "bool_t" means "int" for compatibility with GLib */
31 #undef bool_t
32 #define bool_t int
33 
34 #undef FALSE
35 #define FALSE ((bool_t) 0)
36 #undef TRUE
37 #define TRUE ((bool_t) 1)
38 
39 #undef MIN
40 #define MIN(a,b) ((a) < (b) ? (a) : (b))
41 #undef MAX
42 #define MAX(a,b) ((a) > (b) ? (a) : (b))
43 #undef CLAMP
44 #define CLAMP(a,min,max) ((a) < (min) ? (min) : (a) > (max) ? (max) : (a))
45 
46 #define SPRINTF(s,...) \
47  char s[snprintf (NULL, 0, __VA_ARGS__) + 1]; \
48  snprintf (s, sizeof s, __VA_ARGS__);
49 
50 /* Simple sanity check to catch (1) strings that are still in use after their
51  * reference count has dropped to zero and (2) strings that should have been
52  * pooled but never were. If the check fails, the program is aborted. */
53 #define STR_CHECK(str) do {if ((str) && (str)[-1] != '@') strpool_abort (str);} while (0)
54 
55 /* If the pool contains a copy of <str>, increments its reference count.
56  * Otherwise, adds a copy of <str> to the pool with a reference count of one.
57  * In either case, returns the copy. Because this copy may be shared by other
58  * parts of the code, it should not be modified. If <str> is NULL, simply
59  * returns NULL with no side effects. */
60 char * str_get (const char * str);
61 
62 /* Increments the reference count of <str>, where <str> is the address of a
63  * string already in the pool. Faster than calling str_get() a second time.
64  * Returns <str> for convenience. If <str> is NULL, simply returns NULL with no
65  * side effects. */
66 char * str_ref (char * str);
67 
68 /* Decrements the reference count of <str>, where <str> is the address of a
69  * string in the pool. If the reference count drops to zero, releases the
70  * memory used by <str>. If <str> is NULL, simply returns NULL with no side
71  * effects. */
72 void str_unref (char * str);
73 
74 /* Calls str_get() on the first <len> characters of <str>. If <str> has less
75  * than or equal to <len> characters, equivalent to str_get(). */
76 char * str_nget (const char * str, int len);
77 
78 /* Calls sprintf() internally, then pools the produced string with str_get(). */
79 char * str_printf (const char * format, ...);
80 
81 /* Used by STR_CHECK; should not be called directly. */
82 void strpool_abort (char * str);
83 
84 /* Releases all memory used by the string pool. If strings remain in the pool,
85  * a warning may be printed to stderr in order to reveal memory leaks. */
86 void strpool_shutdown (void);
87 
88 #endif /* LIBAUDCORE_CORE_H */
void strpool_shutdown(void)
Definition: strpool.c:144
int format
Definition: audio.c:132
char * str_printf(const char *format,...)
Definition: strpool.c:116
char * str_ref(char *str)
Definition: strpool.c:74
char * str_nget(const char *str, int len)
Definition: strpool.c:104
void str_unref(char *str)
Definition: strpool.c:89
void strpool_abort(char *str)
Definition: strpool.c:133
char * str_get(const char *str)
Definition: strpool.c:42