Fix the del_word function to delete left one word & retain cursor pos
[luakit.git] / common / util.h
blob4f548e32fa5dbd1090a6ce789ee48e9750f1f135
1 /*
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>
27 #include <string.h>
28 #include <unistd.h>
30 /* Useful macros */
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 #ifdef DEBUG_MESSAGES
42 #define debug(string, ...) _debug(__LINE__, __FUNCTION__, string, ##__VA_ARGS__)
43 void _debug(int, const gchar *, const gchar *, ...);
45 #else
47 #define debug(string, ...)
49 #endif
51 /* A NULL resistant strlen. Unlike it's libc sibling, l_strlen returns a
52 * ssize_t, and supports its argument being NULL. */
53 static inline ssize_t l_strlen(const gchar *s) {
54 return s ? strlen(s) : 0;
57 #define p_clear(p, count) ((void)memset((p), 0, sizeof(*(p)) * (count)))
59 gboolean file_exists(const gchar*);
61 #endif
62 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80