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