| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: citrus_csmapper.c,v 1.10 2009/01/11 02:46:24 christos Exp $ */ | | 1 | /* $NetBSD: citrus_csmapper.c,v 1.11 2011/11/20 07:43:52 tnozaki Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c)2003 Citrus Project, | | 4 | * Copyright (c)2003 Citrus Project, |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -18,27 +18,27 @@ | | | @@ -18,27 +18,27 @@ |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | #if defined(LIBC_SCCS) && !defined(lint) | | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
31 | __RCSID("$NetBSD: citrus_csmapper.c,v 1.10 2009/01/11 02:46:24 christos Exp $"); | | 31 | __RCSID("$NetBSD: citrus_csmapper.c,v 1.11 2011/11/20 07:43:52 tnozaki Exp $"); |
32 | #endif /* LIBC_SCCS and not lint */ | | 32 | #endif /* LIBC_SCCS and not lint */ |
33 | | | 33 | |
34 | #include "namespace.h" | | 34 | #include "namespace.h" |
35 | #include "reentrant.h" | | 35 | #include "reentrant.h" |
36 | #include <assert.h> | | 36 | #include <assert.h> |
37 | #include <stdio.h> | | 37 | #include <stdio.h> |
38 | #include <stdlib.h> | | 38 | #include <stdlib.h> |
39 | #include <string.h> | | 39 | #include <string.h> |
40 | #include <errno.h> | | 40 | #include <errno.h> |
41 | #include <limits.h> | | 41 | #include <limits.h> |
42 | #include <paths.h> | | 42 | #include <paths.h> |
43 | #include <sys/types.h> | | 43 | #include <sys/types.h> |
44 | #include <sys/queue.h> | | 44 | #include <sys/queue.h> |
| @@ -132,26 +132,27 @@ find_best_pivot_pvdb(const char *src, co | | | @@ -132,26 +132,27 @@ find_best_pivot_pvdb(const char *src, co |
132 | goto quit3; | | 132 | goto quit3; |
133 | /* r1:pivot name, r2:norm among src and pivot */ | | 133 | /* r1:pivot name, r2:norm among src and pivot */ |
134 | ret = get32(&r2, &val32); | | 134 | ret = get32(&r2, &val32); |
135 | if (ret) | | 135 | if (ret) |
136 | goto quit3; | | 136 | goto quit3; |
137 | norm = val32; | | 137 | norm = val32; |
138 | snprintf(buf, sizeof(buf), "%.*s", | | 138 | snprintf(buf, sizeof(buf), "%.*s", |
139 | (int)_region_size(&r1), (char *)_region_head(&r1)); | | 139 | (int)_region_size(&r1), (char *)_region_head(&r1)); |
140 | /* buf: pivot name */ | | 140 | /* buf: pivot name */ |
141 | ret = open_subdb(&db3, db1, buf); | | 141 | ret = open_subdb(&db3, db1, buf); |
142 | if (ret) | | 142 | if (ret) |
143 | goto quit3; | | 143 | goto quit3; |
144 | if (_db_lookup_by_s(db3, dst, &r2, NULL) != 0) | | 144 | if (_db_lookup_by_s(db3, dst, &r2, NULL) != 0) |
| | | 145 | /* don't break the loop, test all src/dst pairs. */ |
145 | goto quit4; | | 146 | goto quit4; |
146 | /* r2: norm among pivot and dst */ | | 147 | /* r2: norm among pivot and dst */ |
147 | ret = get32(&r2, &val32); | | 148 | ret = get32(&r2, &val32); |
148 | if (ret) | | 149 | if (ret) |
149 | goto quit4; | | 150 | goto quit4; |
150 | norm += val32; | | 151 | norm += val32; |
151 | /* judge minimum norm */ | | 152 | /* judge minimum norm */ |
152 | if (norm < *rnorm) { | | 153 | if (norm < *rnorm) { |
153 | *rnorm = norm; | | 154 | *rnorm = norm; |
154 | strlcpy(pivot, buf, pvlen); | | 155 | strlcpy(pivot, buf, pvlen); |
155 | } | | 156 | } |
156 | quit4: | | 157 | quit4: |
157 | _db_close(db3); | | 158 | _db_close(db3); |