summaryrefslogtreecommitdiffabout
path: root/pwmanager/libcrypt/crypt/ath.h
Unidiff
Diffstat (limited to 'pwmanager/libcrypt/crypt/ath.h') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/libcrypt/crypt/ath.h116
1 files changed, 116 insertions, 0 deletions
diff --git a/pwmanager/libcrypt/crypt/ath.h b/pwmanager/libcrypt/crypt/ath.h
new file mode 100644
index 0000000..d492c2a
--- a/dev/null
+++ b/pwmanager/libcrypt/crypt/ath.h
@@ -0,0 +1,116 @@
1/* ath.h - Thread-safeness library.
2 Copyright (C) 2002, 2003, 2004 g10 Code GmbH
3
4 This file is part of Libgcrypt.
5
6 Libgcrypt is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of
9 the License, or (at your option) any later version.
10
11 Libgcrypt is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with Libgcrypt; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
20
21#ifndef ATH_H
22#define ATH_H
23
24#ifdef _WIN32
25#warning We need to replace these hacks by cleaner code.
26typedef int ssize_t;
27typedef int pid_t;
28#include <windows.h>
29#else
30#include <sys/types.h>
31#include <sys/socket.h>
32#endif
33#include <gpg-error.h>
34
35#include <config.h>
36
37
38/* Define _ATH_EXT_SYM_PREFIX if you want to give all external symbols
39 a prefix. */
40#define _ATH_EXT_SYM_PREFIX _gcry_
41
42#ifdef _ATH_EXT_SYM_PREFIX
43#define _ATH_PREFIX1(x,y) x ## y
44#define _ATH_PREFIX2(x,y) _ATH_PREFIX1(x,y)
45#define _ATH_PREFIX(x) _ATH_PREFIX2(_ATH_EXT_SYM_PREFIX,x)
46#define ath_install _ATH_PREFIX(ath_install)
47#define ath_init _ATH_PREFIX(ath_init)
48#define ath_mutex_init _ATH_PREFIX(ath_mutex_init)
49#define ath_mutex_destroy _ATH_PREFIX(ath_mutex_destroy)
50#define ath_mutex_lock _ATH_PREFIX(ath_mutex_lock)
51#define ath_mutex_unlock _ATH_PREFIX(ath_mutex_unlock)
52#define ath_read _ATH_PREFIX(ath_read)
53#define ath_write _ATH_PREFIX(ath_write)
54#define ath_select _ATH_PREFIX(ath_select)
55#define ath_waitpid _ATH_PREFIX(ath_waitpid)
56#define ath_connect _ATH_PREFIX(ath_connect)
57#define ath_accept _ATH_PREFIX(ath_accept)
58#define ath_sendmsg _ATH_PREFIX(ath_sendmsg)
59#define ath_recvmsg _ATH_PREFIX(ath_recvmsg)
60#endif
61
62
63enum ath_thread_option
64 {
65 ATH_THREAD_OPTION_DEFAULT = 0,
66 ATH_THREAD_OPTION_USER = 1,
67 ATH_THREAD_OPTION_PTH = 2,
68 ATH_THREAD_OPTION_PTHREAD = 3
69 };
70
71struct ath_ops
72{
73 enum ath_thread_option option;
74 int (*init) (void);
75 int (*mutex_init) (void **priv);
76 int (*mutex_destroy) (void *priv);
77 int (*mutex_lock) (void *priv);
78 int (*mutex_unlock) (void *priv);
79 ssize_t (*read) (int fd, void *buf, size_t nbytes);
80 ssize_t (*write) (int fd, const void *buf, size_t nbytes);
81 ssize_t (*select) (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
82 struct timeval *timeout);
83 ssize_t (*waitpid) (pid_t pid, int *status, int options);
84 int (*accept) (int s, struct sockaddr *addr, socklen_t *length_ptr);
85 int (*connect) (int s, struct sockaddr *addr, socklen_t length);
86 int (*sendmsg) (int s, const struct msghdr *msg, int flags);
87 int (*recvmsg) (int s, struct msghdr *msg, int flags);
88};
89
90gpg_err_code_t ath_install (struct ath_ops *ath_ops, int check_only);
91int ath_init (void);
92
93
94/* Functions for mutual exclusion. */
95typedef void *ath_mutex_t;
96#define ATH_MUTEX_INITIALIZER 0
97
98int ath_mutex_init (ath_mutex_t *mutex);
99int ath_mutex_destroy (ath_mutex_t *mutex);
100int ath_mutex_lock (ath_mutex_t *mutex);
101int ath_mutex_unlock (ath_mutex_t *mutex);
102
103
104/* Replacement for the POSIX functions, which can be used to allow
105 other (user-level) threads to run. */
106ssize_t ath_read (int fd, void *buf, size_t nbytes);
107ssize_t ath_write (int fd, const void *buf, size_t nbytes);
108ssize_t ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
109 struct timeval *timeout);
110ssize_t ath_waitpid (pid_t pid, int *status, int options);
111int ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr);
112int ath_connect (int s, struct sockaddr *addr, socklen_t length);
113int ath_sendmsg (int s, const struct msghdr *msg, int flags);
114int ath_recvmsg (int s, struct msghdr *msg, int flags);
115
116 #endif/* ATH_H */