2 * util.h - useful functions
4 * Copyright (C) 2010 Mason Larobina <mason.larobina@gmail.com>
5 * Copyright (C) 2007-2008 Julien Danjou <julien@danjou.info>
6 * Copyright (C) 2006 Pierre Habouzit <madcoder@debian.org>
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef LUAKIT_COMMON_UTIL_H
24 #define LUAKIT_COMMON_UTIL_H
26 #include <glib/gtypes.h>
31 #define NONULL(x) (x ? x : "")
32 #define LENGTH(x) sizeof(x)/sizeof((x)[0])
34 #define fatal(string, ...) _fatal(__LINE__, __FUNCTION__, string, ##__VA_ARGS__)
35 void _fatal(int, const gchar
*, const gchar
*, ...);
37 #define warn(string, ...) _warn(__LINE__, __FUNCTION__, string, ##__VA_ARGS__)
38 void _warn(int, const gchar
*, const gchar
*, ...);
40 #define debug(string, ...) _debug(__LINE__, __FUNCTION__, string, ##__VA_ARGS__)
41 void _debug(int, const gchar
*, const gchar
*, ...);
43 /* A NULL resistant strlen. Unlike it's libc sibling, l_strlen returns a
44 * ssize_t, and supports its argument being NULL. */
45 static inline ssize_t
l_strlen(const gchar
*s
) {
46 return s
? strlen(s
) : 0;
49 #define p_clear(p, count) ((void)memset((p), 0, sizeof(*(p)) * (count)))
51 gboolean
file_exists(const gchar
*);
54 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80