Updated copyright year.
[pwmd.git] / src / misc.h
blobd4311973c3799c19a1f85018adbcb779e23a92e9
1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
2 /*
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Ben Kibbey <bjk@luxsci.net>
6 This file is part of pwmd.
8 Pwmd 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 2 of the License, or
11 (at your option) any later version.
13 Pwmd 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 Pwmd. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef MISC_H
22 #define MISC_H
24 #include <pthread.h>
25 #include "rcfile.h"
27 #ifdef HAVE_BACKTRACE
28 #include <execinfo.h>
29 #include <syslog.h>
30 #define BACKTRACE_COUNT 20
31 #define BACKTRACE(fn) { \
32 int n, nptrs; \
33 char **strings; \
34 void *buffer[BACKTRACE_COUNT]; \
35 nptrs = backtrace(buffer, BACKTRACE_COUNT); \
36 strings = backtrace_symbols(buffer, nptrs); \
37 for (n = 0; n < nptrs; n++) \
38 log_write("BACKTRACE: (%s) %i: %s", fn, n, strings[n]); \
40 #endif
42 #define log_write0 log_write
44 #define log_write1(...) { \
45 if (get_key_file_integer("global", "log_level") >= 1) \
46 log_write(__VA_ARGS__); \
49 #define log_write2(...) { \
50 if (get_key_file_integer("global", "log_level") >= 2) \
51 log_write(__VA_ARGS__); \
54 typedef enum {
55 OPTION_TYPE_NOARG,
56 OPTION_TYPE_ARG,
57 OPTION_TYPE_OPTARG,
58 } option_type_t;
60 struct argv_s {
61 const gchar *opt;
62 option_type_t type;
63 gpg_error_t (*func)(gpointer data, gpointer value);
66 gpg_error_t parse_options(gchar **line, struct argv_s *args[], gpointer data);
67 gboolean strv_printf(gchar ***array, const gchar *fmt, ...);
68 gchar **strvcatv(gchar **dst, gchar **src);
69 gboolean valid_filename(const gchar *filename);
70 gchar *print_fmt(gchar *buf, gsize len, const char *fmt, ...);
71 gchar *expand_homedir(gchar *str);
72 gchar **split_input_line(gchar *str, gchar *delim, gint n);
73 gchar *bin2hex(const guchar *data, gsize len);
74 gchar *plus_escape(const gchar *fmt, ...);
75 gchar *strip_texi_and_wrap(const gchar *str);
76 void free_key(void *data);
77 gpg_error_t create_thread(void *(*cb)(void *), void *data,
78 pthread_t *tid, gboolean detached);
79 void cleanup_mutex_cb(void *arg);
80 void cleanup_fd_cb(void *arg);
81 void cleanup_unlink_cb(void *arg);
82 void cleanup_cancel_cb(void *arg);
83 void cleanup_cache_mutex(void *arg);
84 gboolean valid_keygrip(const guchar *data, gsize len);
86 #endif