1 /* $NetBSD: misc.c,v 1.5 2008/06/18 07:04:23 mgrooms Exp $ */
3 /* $KAME: misc.c,v 1.23 2001/08/16 14:37:29 itojun Exp $ */
6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/types.h>
37 #include <sys/param.h>
54 static int bindump
__P((void *, size_t));
61 unsigned char *buf
= (unsigned char *)buf0
;
64 for (i
= 0; i
< len
; i
++) {
65 if ((buf
[i
] & 0x80) || !isprint(buf
[i
]))
66 printf("\\x%x", buf
[i
]);
77 racoon_hexdump(buf0
, len
)
81 caddr_t buf
= (caddr_t
)buf0
;
84 for (i
= 0; i
< len
; i
++) {
85 if (i
!= 0 && i
% 32 == 0)
89 printf("%02x", (unsigned char)buf
[i
]);
100 #define MAXBITLEN 128
101 static char b
[MAXBITLEN
+ 1];
105 return "Failed to convert."; /* NG */
109 for (i
= 0; i
< bl
; i
++) {
118 debug_location(file
, line
, func
)
123 static char buf
[1024];
126 /* truncate pathname */
127 p
= strrchr(file
, '/');
134 snprintf(buf
, sizeof(buf
), "%s:%d:%s()", p
, line
, func
);
136 snprintf(buf
, sizeof(buf
), "%s:%d", p
, line
);
151 if (stat(path
, &st
) != 0)
158 * set the close-on-exec flag for file descriptor fd.
164 fcntl(fd
, F_SETFD
, FD_CLOEXEC
);
168 * calculate the difference between two times.
174 struct timeval
*t1
, *t2
;
176 if (t2
->tv_usec
>= t1
->tv_usec
)
177 return t2
->tv_sec
- t1
->tv_sec
+
178 (double)(t2
->tv_usec
- t1
->tv_usec
) / 1000000;
180 return t2
->tv_sec
- t1
->tv_sec
- 1 +
181 (double)(1000000 + t2
->tv_usec
- t1
->tv_usec
) / 1000000;