1 --- msgcat.c.orig 2007-02-07 01:54:34.000000000 -0800
2 +++ msgcat.c 2007-02-07 02:03:33.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 ntohll(x) OSSwapBigToHostInt64(x)
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"
29 return (loadCat(name));
31 if (type == NL_CAT_LOCALE)
32 - lang = setlocale(LC_MESSAGES, NULL);
33 + lang = (char *)querylocale(LC_MESSAGES_MASK, NULL);
35 lang = getenv("LANG");
39 #define LOOKUP(PARENT, CHILD, ID, NUM, SET) { \
41 - if (ID - 1 < PARENT->NUM) { \
42 + if (ID - 1 < NUM) { \
48 cur = (hi - lo) / 2; \
51 CHILD = PARENT->SET + cur; \
52 - if (CHILD->ID == ID) \
53 + if (ntohl(CHILD->ID) == ID) \
55 - if (CHILD->ID < ID) { \
56 + if (ntohl(CHILD->ID) < ID) { \
58 - if (hi > cur + (ID - CHILD->ID) + 1) \
59 - hi = cur + (ID - CHILD->ID) + 1; \
60 + if (hi > cur + (ID - ntohl(CHILD->ID)) + 1) \
61 + hi = cur + (ID - ntohl(CHILD->ID)) + 1; \
72 +MCGetSet(MCCatT *cat, int setId)
75 - long lo, hi, cur, dir;
76 + int32_t 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;
95 + int32_t lo, hi, cur, dir;
97 if (set == NULL || set->invalid || msgId <= 0)
99 - LOOKUP(set, msg, msgId, numMsgs, u.msgs);
100 + LOOKUP(set, msg, msgId, ntohl(set->numMsgs), u.msgs);
113 @@ -377,27 +379,30 @@
114 strncmp(header.magic, MCMagic, MCMagicLen) != 0)
117 - if (header.majorVer != MCMajorVer) {
118 + if (ntohl(header.majorVer) != MCMajorVer) {
119 (void)fclose(cat->fp);
121 - (void)fprintf(stderr, "%s: %s is version %ld, we need %ld.\n",
122 - _errowner, catpath, header.majorVer, MCMajorVer);
123 + if (OSSwapInt32(ntohl(header.majorVer)) == MCMajorVer) {
124 + (void)fprintf(stderr, "%s: %s is the wrong byte ordering.\n", _errowner, catpath);
126 + (void)fprintf(stderr, "%s: %s is version %d, we need %d.\n", _errowner, catpath, (int)ntohl(header.majorVer), MCMajorVer);
130 - if (header.numSets <= 0) {
131 + if (ntohl(header.numSets) <= 0) {
132 (void)fclose(cat->fp);
134 - (void)fprintf(stderr, "%s: %s has %ld sets!\n",
135 - _errowner, catpath, header.numSets);
136 + (void)fprintf(stderr, "%s: %s has %d sets!\n",
137 + _errowner, catpath, (int)ntohl(header.numSets));
141 - cat->numSets = header.numSets;
142 - if ((cat->sets = (MCSetT *)malloc(sizeof(MCSetT) * header.numSets)) ==
143 + cat->numSets = ntohl(header.numSets);
144 + if ((cat->sets = (MCSetT *)malloc(sizeof(MCSetT) * cat->numSets)) ==
148 - nextSet = header.firstSet;
149 + nextSet = ntohll(header.firstSet);
150 for (i = 0; i < cat->numSets; ++i) {
151 if (fseeko(cat->fp, nextSet, SEEK_SET) == -1) {
152 __nls_free_resources(cat, i);
154 /* if it's invalid, skip over it (and backup 'i') */
157 - nextSet = set->nextSet;
158 + nextSet = ntohll(set->nextSet);
166 - nextSet = set->nextSet;
167 + nextSet = ntohll(set->nextSet);
170 if (cat->loadType == MCLoadAll) {
171 @@ -453,11 +458,11 @@
175 - if (fseeko(cat->fp, set->data.off, SEEK_SET) == -1)
176 + if (fseeko(cat->fp, ntohll(set->data.off), SEEK_SET) == -1)
178 - if ((set->data.str = malloc(set->dataLen)) == NULL)
179 + if ((set->data.str = malloc(ntohl(set->dataLen))) == NULL)
181 - if (fread(set->data.str, set->dataLen, 1, cat->fp) != 1) {
182 + if (fread(set->data.str, ntohl(set->dataLen), 1, cat->fp) != 1) {
186 @@ -465,13 +470,13 @@
189 /* Get the messages */
190 - if (fseeko(cat->fp, set->u.firstMsg, SEEK_SET) == -1) {
191 + if (fseeko(cat->fp, ntohll(set->u.firstMsg), SEEK_SET) == -1) {
197 - if ((set->u.msgs = (MCMsgT *)malloc(sizeof(MCMsgT) * set->numMsgs)) ==
198 + if ((set->u.msgs = (MCMsgT *)malloc(sizeof(MCMsgT) * ntohl(set->numMsgs))) ==
206 - for (i = 0; i < set->numMsgs; ++i) {
207 + for (i = 0; i < ntohl(set->numMsgs); ++i) {
208 msg = set->u.msgs + i;
209 if (fread(msg, sizeof(*msg), 1, cat->fp) != 1) {
215 - msg->msg.str = (char *)(set->data.str + msg->msg.off);
216 + msg->msg.str = (char *)(set->data.str + ntohll(msg->msg.off));
218 set->invalid = FALSE;