1 /*	$OpenBSD: evutil.h,v 1.3 2010/04/22 08:16:44 nicm Exp $	*/
2 
3 /*
4  * Copyright © 2013
5  *	Thorsten “mirabilos” Glaser <tg@mirbsd.org>
6  * Copyright (c) 2007 Niels Provos <provos@citi.umich.edu>
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _EVUTIL_H_
33 #define _EVUTIL_H_ "$MirOS: src/lib/libevent/evutil.h,v 1.3 2013/10/31 20:06:30 tg Exp $"
34 
35 /** @file evutil.h
36 
37   Common convenience functions for cross-platform portability and
38   related socket manipulations.
39 
40  */
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #include <sys/types.h>
47 #include <sys/time.h>
48 
49 #include <inttypes.h>
50 #include <stdarg.h>
51 #include <stdint.h>
52 
53 #define ev_uint64_t uint64_t
54 #define ev_int64_t int64_t
55 #define ev_uint32_t uint32_t
56 #define ev_uint16_t uint16_t
57 #define ev_uint8_t uint8_t
58 
59 int evutil_socketpair(int d, int type, int protocol, int sv[2]);
60 int evutil_make_socket_nonblocking(int sock);
61 
62 #define EVUTIL_CLOSESOCKET(s) close(s)
63 #define EVUTIL_SOCKET_ERROR() (errno)
64 #define EVUTIL_SET_SOCKET_ERROR(errcode)	\
65 	do { errno = (errcode); } while (0)
66 
67 /*
68  * Manipulation functions for struct timeval
69  */
70 #define evutil_timeradd(tvp, uvp, vvp) timeradd((tvp), (uvp), (vvp))
71 #define evutil_timersub(tvp, uvp, vvp) timersub((tvp), (uvp), (vvp))
72 #define evutil_timerclear(tvp) timerclear(tvp)
73 #define	evutil_timercmp(tvp, uvp, cmp) timercmp((tvp), (uvp), cmp)
74 #define evutil_timerisset(tvp) timerisset(tvp)
75 
76 /* big-int related functions */
77 ev_int64_t evutil_strtoll(const char *s, char **endptr, int base);
78 
79 #define evutil_gettimeofday(tv, tz) gettimeofday((tv), (tz))
80 
81 int evutil_snprintf(char *buf, size_t buflen, const char *format, ...)
82 #ifdef __GNUC__
83 	__attribute__((__format__(__printf__, 3, 4)))
84 #endif
85 	;
86 int evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap)
87 #ifdef __GNUC__
88 	__attribute__((__format__(__printf__, 3, 0)))
89 #endif
90 	;
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 #endif /* _EVUTIL_H_ */
97