Fixes for the MSC build
[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 # if defined(HAVE_W32CE_SYSTEM) && defined(_MSC_VER)
32 #  include <winsock2.h>
33 # endif
34 # include <windows.h>
35 # include <io.h>
36
37 #else /*!HAVE_W32_SYSTEM*/
38
39 # ifdef HAVE_SYS_SELECT_H
40 #  include <sys/select.h>
41 # else
42 #  ifdef HAVE_SYS_TIME_H
43 #   include <sys/time.h>
44 #  endif
45 # endif
46 # ifdef HAVE_SYS_TYPES_H
47 #  include <sys/types.h>
48 # endif
49 # include <sys/socket.h>
50
51 #endif  /*!HAVE_W32_SYSTEM*/
52
53
54 \f
55 /* Define _ATH_EXT_SYM_PREFIX if you want to give all external symbols
56    a prefix.  */
57 #define _ATH_EXT_SYM_PREFIX _gpgme_
58
59 #ifdef _ATH_EXT_SYM_PREFIX
60 #define _ATH_PREFIX1(x,y) x ## y
61 #define _ATH_PREFIX2(x,y) _ATH_PREFIX1(x,y)
62 #define _ATH_PREFIX(x) _ATH_PREFIX2(_ATH_EXT_SYM_PREFIX,x)
63 #define ath_mutex_init _ATH_PREFIX(ath_mutex_init)
64 #define ath_mutex_destroy _ATH_PREFIX(ath_mutex_destroy)
65 #define ath_mutex_lock _ATH_PREFIX(ath_mutex_lock)
66 #define ath_mutex_unlock _ATH_PREFIX(ath_mutex_unlock)
67 #define ath_read _ATH_PREFIX(ath_read)
68 #define ath_write _ATH_PREFIX(ath_write)
69 #define ath_select _ATH_PREFIX(ath_select)
70 #define ath_waitpid _ATH_PREFIX(ath_waitpid)
71 #define ath_connect _ATH_PREFIX(ath_connect)
72 #define ath_accept _ATH_PREFIX(ath_accept)
73 #define ath_sendmsg _ATH_PREFIX(ath_sendmsg)
74 #define ath_recvmsg _ATH_PREFIX(ath_recvmsg)
75 #endif
76
77 \f
78 typedef void *ath_mutex_t;
79 #define ATH_MUTEX_INITIALIZER 0;
80
81 uintptr_t ath_self (void);
82
83 /* Functions for mutual exclusion.  */
84 int ath_mutex_init (ath_mutex_t *mutex);
85 int ath_mutex_destroy (ath_mutex_t *mutex);
86 int ath_mutex_lock (ath_mutex_t *mutex);
87 int ath_mutex_unlock (ath_mutex_t *mutex);
88
89 /* Replacement for the POSIX functions, which can be used to allow
90    other (user-level) threads to run.  */
91 ssize_t ath_read (int fd, void *buf, size_t nbytes);
92 ssize_t ath_write (int fd, const void *buf, size_t nbytes);
93 ssize_t ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
94                     struct timeval *timeout);
95 ssize_t ath_waitpid (pid_t pid, int *status, int options);
96 int ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr);
97 int ath_connect (int s, const struct sockaddr *addr, socklen_t length);
98 int ath_sendmsg (int s, const struct msghdr *msg, int flags);
99 int ath_recvmsg (int s, struct msghdr *msg, int flags);
100
101 #endif  /* ATH_H */