1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*
* Copyright (C) 2010-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef SYSTEM_H
#define SYSTEM_H
#include <gnutls_int.h>
#include <time.h>
#include <sys/time.h>
#ifndef _WIN32
#include <sys/uio.h> /* for writev */
#else
#include <windows.h> /* for Sleep */
#endif
#ifdef _POSIX_PATH_MAX
# define GNUTLS_PATH_MAX _POSIX_PATH_MAX
#else
# define GNUTLS_PATH_MAX 256
#endif
int system_errno(gnutls_transport_ptr_t);
#ifdef _WIN32
ssize_t system_write(gnutls_transport_ptr_t ptr, const void *data,
size_t data_size);
#else
#define HAVE_WRITEV
ssize_t system_writev(gnutls_transport_ptr_t ptr, const giovec_t * iovec,
int iovec_cnt);
ssize_t system_writev_nosignal(gnutls_transport_ptr_t ptr, const giovec_t * iovec,
int iovec_cnt);
#endif
ssize_t system_read(gnutls_transport_ptr_t ptr, void *data,
size_t data_size);
#if defined(_WIN32)
# define HAVE_WIN32_LOCKS
#elif defined(HAVE_LIBPTHREAD) || defined(HAVE_PTHREAD_MUTEX_LOCK)
# define HAVE_PTHREAD_LOCKS
#else
# define HAVE_NO_LOCKS
#endif
extern gnutls_time_func gnutls_time;
static inline void millisleep(unsigned int ms)
{
#ifdef _WIN32
Sleep(ms);
#else
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = ms * 1000 * 1000;
nanosleep(&ts, NULL);
#endif
}
/* emulate gnulib's gettime using gettimeofday to avoid linking to
* librt */
inline static void gettime(struct timespec *t)
{
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
clock_gettime(CLOCK_REALTIME, t);
#else
struct timeval tv;
gettimeofday(&tv, NULL);
t->tv_sec = tv.tv_sec;
t->tv_nsec = tv.tv_usec * 1000;
#endif
}
int _gnutls_find_config_path(char *path, size_t max_size);
int _gnutls_ucs2_to_utf8(const void *data, size_t size,
gnutls_datum_t * output, unsigned bigendian);
int gnutls_system_global_init(void);
void gnutls_system_global_deinit(void);
#ifndef _WIN32
# if defined(HAVE_NETINET_IN_H)
# include <netinet/in.h>
# endif
# include <arpa/inet.h>
#else
# define inet_aton _gnutls_inet_aton
int inet_aton(const char *cp, struct in_addr *inp);
#endif
#ifndef HAVE_INET_PTON
# define inet_pton _gnutls_inet_pton
int inet_pton(int af, const char *src, void *dst);
#endif
#ifndef HAVE_INET_NTOP
# define inet_ntop _gnutls_inet_ntop
const char *inet_ntop(int af, const void *src,
char *dst, unsigned size);
#endif
#endif /* SYSTEM_H */
|