]>
Commit | Line | Data |
---|---|---|
224c7076 A |
1 | --- msgcat.c.orig 2007-02-07 01:54:34.000000000 -0800 |
2 | +++ msgcat.c 2007-02-07 02:03:33.000000000 -0800 | |
3 | @@ -45,16 +45,22 @@ | |
3d9156a7 A |
4 | #include <errno.h> |
5 | #include <fcntl.h> | |
6 | #include <limits.h> | |
7 | -#include <locale.h> | |
8 | +#include <xlocale.h> | |
9 | #include <nl_types.h> | |
10 | #include <stdio.h> | |
11 | #include <stdlib.h> | |
31185420 A |
12 | #include <string.h> |
13 | #include <unistd.h> | |
14 | +#include <machine/endian.h> | |
15 | +#include <libkern/OSByteOrder.h> | |
9385eb3d A |
16 | #include "un-namespace.h" |
17 | ||
18 | #include "msgcat.h" | |
19 | -#include "../locale/setlocale.h" /* for ENCODING_LEN */ | |
20 | +#include "setlocale.h" /* for ENCODING_LEN */ | |
31185420 | 21 | + |
224c7076 | 22 | +#ifndef ntohll |
31185420 A |
23 | +#define ntohll(x) OSSwapBigToHostInt64(x) |
24 | +#endif | |
9385eb3d A |
25 | |
26 | #define _DEFAULT_NLS_PATH "/usr/share/nls/%L/%N.cat:/usr/share/nls/%N/%L:/usr/local/share/nls/%L/%N.cat:/usr/local/share/nls/%N/%L" | |
27 | ||
224c7076 | 28 | @@ -87,7 +93,7 @@ |
3d9156a7 A |
29 | return (loadCat(name)); |
30 | ||
31 | if (type == NL_CAT_LOCALE) | |
32 | - lang = setlocale(LC_MESSAGES, NULL); | |
33 | + lang = (char *)querylocale(LC_MESSAGES_MASK, NULL); | |
34 | else | |
35 | lang = getenv("LANG"); | |
36 | ||
224c7076 | 37 | @@ -210,21 +216,21 @@ |
31185420 A |
38 | |
39 | #define LOOKUP(PARENT, CHILD, ID, NUM, SET) { \ | |
40 | lo = 0; \ | |
41 | - if (ID - 1 < PARENT->NUM) { \ | |
42 | + if (ID - 1 < NUM) { \ | |
43 | cur = ID - 1; \ | |
44 | hi = ID; \ | |
45 | } else { \ | |
46 | - hi = PARENT->NUM; \ | |
47 | + hi = NUM; \ | |
48 | cur = (hi - lo) / 2; \ | |
49 | } \ | |
50 | while (TRUE) { \ | |
51 | CHILD = PARENT->SET + cur; \ | |
52 | - if (CHILD->ID == ID) \ | |
224c7076 | 53 | + if (ntohl(CHILD->ID) == ID) \ |
31185420 A |
54 | break; \ |
55 | - if (CHILD->ID < ID) { \ | |
224c7076 | 56 | + if (ntohl(CHILD->ID) < ID) { \ |
31185420 A |
57 | lo = cur + 1; \ |
58 | - if (hi > cur + (ID - CHILD->ID) + 1) \ | |
59 | - hi = cur + (ID - CHILD->ID) + 1; \ | |
224c7076 A |
60 | + if (hi > cur + (ID - ntohl(CHILD->ID)) + 1) \ |
61 | + hi = cur + (ID - ntohl(CHILD->ID)) + 1; \ | |
31185420 A |
62 | dir = 1; \ |
63 | } else { \ | |
64 | hi = cur; \ | |
224c7076 | 65 | @@ -240,32 +246,28 @@ |
31185420 A |
66 | } |
67 | ||
68 | static MCSetT * | |
69 | -MCGetSet(cat, setId) | |
70 | - MCCatT *cat; | |
71 | - int setId; | |
72 | +MCGetSet(MCCatT *cat, int setId) | |
73 | { | |
74 | MCSetT *set; | |
224c7076 A |
75 | - long lo, hi, cur, dir; |
76 | + int32_t lo, hi, cur, dir; | |
31185420 A |
77 | |
78 | if (cat == NULL || setId <= 0) | |
79 | return (NULL); | |
80 | - LOOKUP(cat, set, setId, numSets, sets); | |
81 | + LOOKUP(cat, set, setId, cat->numSets, sets); | |
82 | if (set->invalid && loadSet(cat, set) <= 0) | |
83 | return (NULL); | |
84 | return (set); | |
85 | } | |
86 | ||
87 | static MCMsgT * | |
88 | -MCGetMsg(set, msgId) | |
89 | - MCSetT *set; | |
90 | - int msgId; | |
91 | +MCGetMsg(MCSetT *set, int msgId) | |
92 | { | |
93 | MCMsgT *msg; | |
224c7076 A |
94 | - long lo, hi, cur, dir; |
95 | + int32_t lo, hi, cur, dir; | |
31185420 A |
96 | |
97 | if (set == NULL || set->invalid || msgId <= 0) | |
98 | return (NULL); | |
99 | - LOOKUP(set, msg, msgId, numMsgs, u.msgs); | |
224c7076 | 100 | + LOOKUP(set, msg, msgId, ntohl(set->numMsgs), u.msgs); |
31185420 A |
101 | return (msg); |
102 | } | |
103 | ||
224c7076 A |
104 | @@ -357,7 +359,7 @@ |
105 | MCHeaderT header; | |
106 | MCCatT *cat; | |
107 | MCSetT *set; | |
108 | - long i; | |
109 | + int32_t i; | |
110 | off_t nextSet; | |
111 | int saverr; | |
112 | ||
113 | @@ -377,27 +379,30 @@ | |
31185420 A |
114 | strncmp(header.magic, MCMagic, MCMagicLen) != 0) |
115 | CORRUPT(); | |
116 | ||
117 | - if (header.majorVer != MCMajorVer) { | |
224c7076 | 118 | + if (ntohl(header.majorVer) != MCMajorVer) { |
31185420 A |
119 | (void)fclose(cat->fp); |
120 | free(cat); | |
121 | - (void)fprintf(stderr, "%s: %s is version %ld, we need %ld.\n", | |
122 | - _errowner, catpath, header.majorVer, MCMajorVer); | |
224c7076 | 123 | + if (OSSwapInt32(ntohl(header.majorVer)) == MCMajorVer) { |
31185420 A |
124 | + (void)fprintf(stderr, "%s: %s is the wrong byte ordering.\n", _errowner, catpath); |
125 | + } else { | |
224c7076 | 126 | + (void)fprintf(stderr, "%s: %s is version %d, we need %d.\n", _errowner, catpath, (int)ntohl(header.majorVer), MCMajorVer); |
31185420 A |
127 | + } |
128 | NLRETERR(EFTYPE); | |
129 | } | |
130 | - if (header.numSets <= 0) { | |
224c7076 | 131 | + if (ntohl(header.numSets) <= 0) { |
31185420 A |
132 | (void)fclose(cat->fp); |
133 | free(cat); | |
224c7076 | 134 | - (void)fprintf(stderr, "%s: %s has %ld sets!\n", |
31185420 | 135 | - _errowner, catpath, header.numSets); |
224c7076 A |
136 | + (void)fprintf(stderr, "%s: %s has %d sets!\n", |
137 | + _errowner, catpath, (int)ntohl(header.numSets)); | |
31185420 A |
138 | NLRETERR(EFTYPE); |
139 | } | |
140 | ||
141 | - cat->numSets = header.numSets; | |
142 | - if ((cat->sets = (MCSetT *)malloc(sizeof(MCSetT) * header.numSets)) == | |
224c7076 | 143 | + cat->numSets = ntohl(header.numSets); |
31185420 A |
144 | + if ((cat->sets = (MCSetT *)malloc(sizeof(MCSetT) * cat->numSets)) == |
145 | NULL) | |
146 | NOSPACE(); | |
147 | ||
148 | - nextSet = header.firstSet; | |
224c7076 | 149 | + nextSet = ntohll(header.firstSet); |
31185420 A |
150 | for (i = 0; i < cat->numSets; ++i) { |
151 | if (fseeko(cat->fp, nextSet, SEEK_SET) == -1) { | |
152 | __nls_free_resources(cat, i); | |
224c7076 | 153 | @@ -414,7 +419,7 @@ |
31185420 A |
154 | /* if it's invalid, skip over it (and backup 'i') */ |
155 | if (set->invalid) { | |
156 | --i; | |
157 | - nextSet = set->nextSet; | |
224c7076 | 158 | + nextSet = ntohll(set->nextSet); |
31185420 A |
159 | continue; |
160 | } | |
161 | #if 0 | |
224c7076 | 162 | @@ -432,7 +437,7 @@ |
31185420 A |
163 | } else |
164 | #endif | |
165 | set->invalid = TRUE; | |
166 | - nextSet = set->nextSet; | |
224c7076 | 167 | + nextSet = ntohll(set->nextSet); |
31185420 A |
168 | } |
169 | #if 0 | |
170 | if (cat->loadType == MCLoadAll) { | |
224c7076 | 171 | @@ -453,11 +458,11 @@ |
31185420 A |
172 | int saverr; |
173 | ||
174 | /* Get the data */ | |
175 | - if (fseeko(cat->fp, set->data.off, SEEK_SET) == -1) | |
224c7076 | 176 | + if (fseeko(cat->fp, ntohll(set->data.off), SEEK_SET) == -1) |
31185420 A |
177 | return (0); |
178 | - if ((set->data.str = malloc(set->dataLen)) == NULL) | |
224c7076 | 179 | + if ((set->data.str = malloc(ntohl(set->dataLen))) == NULL) |
31185420 A |
180 | return (-1); |
181 | - if (fread(set->data.str, set->dataLen, 1, cat->fp) != 1) { | |
224c7076 | 182 | + if (fread(set->data.str, ntohl(set->dataLen), 1, cat->fp) != 1) { |
31185420 A |
183 | saverr = errno; |
184 | free(set->data.str); | |
185 | errno = saverr; | |
224c7076 | 186 | @@ -465,13 +470,13 @@ |
31185420 A |
187 | } |
188 | ||
189 | /* Get the messages */ | |
190 | - if (fseeko(cat->fp, set->u.firstMsg, SEEK_SET) == -1) { | |
224c7076 | 191 | + if (fseeko(cat->fp, ntohll(set->u.firstMsg), SEEK_SET) == -1) { |
31185420 A |
192 | saverr = errno; |
193 | free(set->data.str); | |
194 | errno = saverr; | |
195 | return (0); | |
196 | } | |
197 | - if ((set->u.msgs = (MCMsgT *)malloc(sizeof(MCMsgT) * set->numMsgs)) == | |
224c7076 | 198 | + if ((set->u.msgs = (MCMsgT *)malloc(sizeof(MCMsgT) * ntohl(set->numMsgs))) == |
31185420 A |
199 | NULL) { |
200 | saverr = errno; | |
201 | free(set->data.str); | |
224c7076 | 202 | @@ -479,7 +484,7 @@ |
31185420 A |
203 | return (-1); |
204 | } | |
205 | ||
206 | - for (i = 0; i < set->numMsgs; ++i) { | |
224c7076 | 207 | + for (i = 0; i < ntohl(set->numMsgs); ++i) { |
31185420 A |
208 | msg = set->u.msgs + i; |
209 | if (fread(msg, sizeof(*msg), 1, cat->fp) != 1) { | |
210 | saverr = errno; | |
224c7076 | 211 | @@ -492,7 +497,7 @@ |
31185420 A |
212 | --i; |
213 | continue; | |
214 | } | |
215 | - msg->msg.str = (char *)(set->data.str + msg->msg.off); | |
224c7076 | 216 | + msg->msg.str = (char *)(set->data.str + ntohll(msg->msg.off)); |
31185420 A |
217 | } |
218 | set->invalid = FALSE; | |
219 | return (1); |