1 --- /Network/Servers/hills/Volumes/capanna/josborne/work-area/PR-4416984/Libc/nls/FreeBSD/msgcat.c 2004-11-25 11:38:30.000000000 -0800
2 +++ msgcat.c 2006-02-21 12:46:25.000000000 -0800
14 +#include <machine/endian.h>
15 +#include <libkern/OSByteOrder.h>
16 #include "un-namespace.h"
19 -#include "../locale/setlocale.h" /* for ENCODING_LEN */
20 +#include "setlocale.h" /* for ENCODING_LEN */
23 +#define htonll(x) OSSwapHostToBigInt64(x)
24 +#define ntohll(x) OSSwapBigToHostInt64(x)
27 #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"
30 return (loadCat(name));
32 if (type == NL_CAT_LOCALE)
33 - lang = setlocale(LC_MESSAGES, NULL);
34 + lang = (char *)querylocale(LC_MESSAGES_MASK, NULL);
36 lang = getenv("LANG");
40 #define LOOKUP(PARENT, CHILD, ID, NUM, SET) { \
42 - if (ID - 1 < PARENT->NUM) { \
43 + if (ID - 1 < NUM) { \
49 cur = (hi - lo) / 2; \
52 CHILD = PARENT->SET + cur; \
53 - if (CHILD->ID == ID) \
54 + if (htonl(CHILD->ID) == ID) \
56 - if (CHILD->ID < ID) { \
57 + if (htonl(CHILD->ID) < ID) { \
59 - if (hi > cur + (ID - CHILD->ID) + 1) \
60 - hi = cur + (ID - CHILD->ID) + 1; \
61 + if (hi > cur + (ID - htonl(CHILD->ID)) + 1) \
62 + hi = cur + (ID - htonl(CHILD->ID)) + 1; \
73 +MCGetSet(MCCatT *cat, int setId)
76 long lo, hi, cur, dir;
78 if (cat == NULL || setId <= 0)
80 - LOOKUP(cat, set, setId, numSets, sets);
81 + LOOKUP(cat, set, setId, cat->numSets, sets);
82 if (set->invalid && loadSet(cat, set) <= 0)
91 +MCGetMsg(MCSetT *set, int msgId)
94 long lo, hi, cur, dir;
96 if (set == NULL || set->invalid || msgId <= 0)
98 - LOOKUP(set, msg, msgId, numMsgs, u.msgs);
99 + LOOKUP(set, msg, msgId, htonl(set->numMsgs), u.msgs);
103 @@ -377,27 +380,30 @@
104 strncmp(header.magic, MCMagic, MCMagicLen) != 0)
107 - if (header.majorVer != MCMajorVer) {
108 + if (htonl(header.majorVer) != MCMajorVer) {
109 (void)fclose(cat->fp);
111 - (void)fprintf(stderr, "%s: %s is version %ld, we need %ld.\n",
112 - _errowner, catpath, header.majorVer, MCMajorVer);
113 + if (OSSwapInt32(htonl(header.majorVer)) == MCMajorVer) {
114 + (void)fprintf(stderr, "%s: %s is the wrong byte ordering.\n", _errowner, catpath);
116 + (void)fprintf(stderr, "%s: %s is version %ld, we need %ld.\n", _errowner, catpath, htonl(header.majorVer), MCMajorVer);
120 - if (header.numSets <= 0) {
121 + if (htonl(header.numSets) <= 0) {
122 (void)fclose(cat->fp);
124 (void)fprintf(stderr, "%s: %s has %ld sets!\n",
125 - _errowner, catpath, header.numSets);
126 + _errowner, catpath, htonl(header.numSets));
130 - cat->numSets = header.numSets;
131 - if ((cat->sets = (MCSetT *)malloc(sizeof(MCSetT) * header.numSets)) ==
132 + cat->numSets = htonl(header.numSets);
133 + if ((cat->sets = (MCSetT *)malloc(sizeof(MCSetT) * cat->numSets)) ==
137 - nextSet = header.firstSet;
138 + nextSet = htonll(header.firstSet);
139 for (i = 0; i < cat->numSets; ++i) {
140 if (fseeko(cat->fp, nextSet, SEEK_SET) == -1) {
141 __nls_free_resources(cat, i);
143 /* if it's invalid, skip over it (and backup 'i') */
146 - nextSet = set->nextSet;
147 + nextSet = htonll(set->nextSet);
155 - nextSet = set->nextSet;
156 + nextSet = htonll(set->nextSet);
159 if (cat->loadType == MCLoadAll) {
160 @@ -453,11 +459,11 @@
164 - if (fseeko(cat->fp, set->data.off, SEEK_SET) == -1)
165 + if (fseeko(cat->fp, htonll(set->data.off), SEEK_SET) == -1)
167 - if ((set->data.str = malloc(set->dataLen)) == NULL)
168 + if ((set->data.str = malloc(htonl(set->dataLen))) == NULL)
170 - if (fread(set->data.str, set->dataLen, 1, cat->fp) != 1) {
171 + if (fread(set->data.str, htonl(set->dataLen), 1, cat->fp) != 1) {
175 @@ -465,13 +471,13 @@
178 /* Get the messages */
179 - if (fseeko(cat->fp, set->u.firstMsg, SEEK_SET) == -1) {
180 + if (fseeko(cat->fp, htonll(set->u.firstMsg), SEEK_SET) == -1) {
186 - if ((set->u.msgs = (MCMsgT *)malloc(sizeof(MCMsgT) * set->numMsgs)) ==
187 + if ((set->u.msgs = (MCMsgT *)malloc(sizeof(MCMsgT) * htonl(set->numMsgs))) ==
195 - for (i = 0; i < set->numMsgs; ++i) {
196 + for (i = 0; i < htonl(set->numMsgs); ++i) {
197 msg = set->u.msgs + i;
198 if (fread(msg, sizeof(*msg), 1, cat->fp) != 1) {
204 - msg->msg.str = (char *)(set->data.str + msg->msg.off);
205 + msg->msg.str = (char *)(set->data.str + htonll(msg->msg.off));
207 set->invalid = FALSE;