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