BULK: Change syntax to drop "7:command ".
[pwmd.git] / src / util-misc.h
blob407ecd4ad245d49a16e299ba6924f3e1ddc4506b
1 /*
2 Copyright (C) 2006-2018 Ben Kibbey <bjk@luxsci.net>
4 This file is part of pwmd.
6 Pwmd is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
11 Pwmd is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef UTIL_MISC_H
20 #define UTIL_MISC_H
22 #include <pthread.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <wchar.h>
26 #include <pwd.h>
27 #include <netinet/in.h>
28 #include "rcfile.h"
30 #ifdef HAVE_BACKTRACE
31 #include <execinfo.h>
32 #include <syslog.h>
33 #define BACKTRACE_COUNT 20
34 #define BACKTRACE(fn) do { \
35 int n, nptrs; \
36 char **strings; \
37 void *buffer[BACKTRACE_COUNT]; \
38 nptrs = backtrace(buffer, BACKTRACE_COUNT); \
39 strings = backtrace_symbols(buffer, nptrs); \
40 for (n = 0; n < nptrs; n++) \
41 log_write("BACKTRACE: (%s) %i: %s", fn, n, strings[n]); \
42 } while (0)
43 #endif
45 #define log_write0 log_write
47 #define log_write1(...) do { \
48 if (log_level >= 1) \
49 log_write(__VA_ARGS__); \
50 } while (0)
52 #define log_write2(...) do { \
53 if (log_level >= 2) \
54 log_write(__VA_ARGS__); \
55 } while (0)
57 typedef enum
59 OPTION_TYPE_NOARG,
60 OPTION_TYPE_ARG,
61 OPTION_TYPE_OPTARG,
62 } option_type_t;
64 struct argv_s
66 const char *opt;
67 option_type_t type;
68 gpg_error_t (*func) (void *data, void *value);
71 typedef struct
73 size_t len;
74 void *buf;
75 } membuf_t;
77 char *home_directory;
78 int log_level;
80 gpg_error_t parse_options (char **line, struct argv_s *args[], void *data,
81 int more);
82 int valid_filename (const char *filename);
83 char *expand_homedir (char *str);
84 char *bin2hex (const unsigned char *data, size_t len);
85 char *gnupg_escape (const char *str);
86 char *strip_texi_and_wrap (const char *str, int html);
87 void free_key (void *data);
88 gpg_error_t create_thread (void *(*cb) (void *), void *data,
89 pthread_t * tid, int detached);
90 void release_mutex_cb (void *arg);
91 void close_fd_cb (void *arg);
92 gpg_error_t get_checksum (const char *filename, unsigned char **r_crc,
93 size_t * r_crclen);
94 gpg_error_t get_checksum_memory (void *data, size_t size,
95 unsigned char **r_crc, size_t *r_crclen);
96 char *get_username (uid_t);
97 char *get_home_dir ();
98 struct passwd *get_pwd_struct (const char *user, uid_t uid, struct passwd *,
99 char **buf, gpg_error_t *);
100 wchar_t *str_to_wchar (const char *str);
101 void *get_in_addr (struct sockaddr *sa);
102 gpg_error_t open_check_file (const char *, int *, struct stat *, int);
104 #endif