424e3456bac22794dd38e1013b289ab784462b72
[gpgme.git] / src / ath.h
1 /* ath.h - Interfaces for thread-safeness library.
2    Copyright (C) 2002, 2003, 2004 g10 Code GmbH
3
4    This file is part of GPGME.
5  
6    GPGME is free software; you can redistribute it and/or modify it
7    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    GPGME 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    Lesser General Public License for more details.
15    
16    You should have received a copy of the GNU Lesser General Public
17    License along with this program; 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 HAVE_STDINT_H
25 #include <stdint.h>
26 #endif
27 #ifdef HAVE_W32_SYSTEM
28   /* fixme: Check how we did it in libgcrypt.  */
29   struct msghdr { int dummy; };
30   typedef int socklen_t;
31 # include <windows.h>
32 # include <io.h>
33
34 #else /*!HAVE_W32_SYSTEM*/
35
36 # ifdef HAVE_SYS_SELECT_H
37 #  include <sys/select.h>
38 # else
39 #  ifdef HAVE_SYS_TIME_H
40 #   include <sys/time.h>
41 #  endif
42 # endif
43 # ifdef HAVE_SYS_TYPES_H
44 #  include <sys/types.h>
45 # endif
46 # include <sys/socket.h>
47
48 #endif  /*!HAVE_W32_SYSTEM*/
49
50
51 \f
52 /* Define _ATH_EXT_SYM_PREFIX if you want to give all external symbols
53    a prefix.  */
54 #define _ATH_EXT_SYM_PREFIX _gpgme_
55
56 #ifdef _ATH_EXT_SYM_PREFIX
57 #define _ATH_PREFIX1(x,y) x ## y
58 #define _ATH_PREFIX2(x,y) _ATH_PREFIX1(x,y)
59 #define _ATH_PREFIX(x) _ATH_PREFIX2(_ATH_EXT_SYM_PREFIX,x)
60 #define ath_mutex_init _ATH_PREFIX(ath_mutex_init)
61 #define ath_mutex_destroy _ATH_PREFIX(ath_mutex_destroy)
62 #define ath_mutex_lock _ATH_PREFIX(ath_mutex_lock)
63 #define ath_mutex_unlock _ATH_PREFIX(ath_mutex_unlock)
64 #define ath_read _ATH_PREFIX(ath_read)
65 #define ath_write _ATH_PREFIX(ath_write)
66 #define ath_select _ATH_PREFIX(ath_select)
67 #define ath_waitpid _ATH_PREFIX(ath_waitpid)
68 #define ath_connect _ATH_PREFIX(ath_connect)
69 #define ath_accept _ATH_PREFIX(ath_accept)
70 #define ath_sendmsg _ATH_PREFIX(ath_sendmsg)
71 #define ath_recvmsg _ATH_PREFIX(ath_recvmsg)
72 #endif
73
74 \f
75 typedef void *ath_mutex_t;
76 #define ATH_MUTEX_INITIALIZER 0;
77
78 uintptr_t ath_self (void);
79
80 /* Functions for mutual exclusion.  */
81 int ath_mutex_init (ath_mutex_t *mutex);
82 int ath_mutex_destroy (ath_mutex_t *mutex);
83 int ath_mutex_lock (ath_mutex_t *mutex);
84 int ath_mutex_unlock (ath_mutex_t *mutex);
85
86 /* Replacement for the POSIX functions, which can be used to allow
87    other (user-level) threads to run.  */
88 ssize_t ath_read (int fd, void *buf, size_t nbytes);
89 ssize_t ath_write (int fd, const void *buf, size_t nbytes);
90 ssize_t ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
91                     struct timeval *timeout);
92 ssize_t ath_waitpid (pid_t pid, int *status, int options);
93 int ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr);
94 int ath_connect (int s, const struct sockaddr *addr, socklen_t length);
95 int ath_sendmsg (int s, const struct msghdr *msg, int flags);
96 int ath_recvmsg (int s, struct msghdr *msg, int flags);
97
98 #endif  /* ATH_H */