]> git.saurik.com Git - apple/libc.git/blame - nls/FreeBSD/msgcat.c.patch
Libc-391.4.3.tar.gz
[apple/libc.git] / nls / FreeBSD / msgcat.c.patch
CommitLineData
31185420
A
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
3@@ -45,16 +45,23 @@
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
A
21+
22+#ifndef htonll
23+#define htonll(x) OSSwapHostToBigInt64(x)
24+#define ntohll(x) OSSwapBigToHostInt64(x)
25+#endif
9385eb3d
A
26
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"
28
31185420 29@@ -87,7 +94,7 @@
3d9156a7
A
30 return (loadCat(name));
31
32 if (type == NL_CAT_LOCALE)
33- lang = setlocale(LC_MESSAGES, NULL);
34+ lang = (char *)querylocale(LC_MESSAGES_MASK, NULL);
35 else
36 lang = getenv("LANG");
37
31185420
A
38@@ -210,21 +217,21 @@
39
40 #define LOOKUP(PARENT, CHILD, ID, NUM, SET) { \
41 lo = 0; \
42- if (ID - 1 < PARENT->NUM) { \
43+ if (ID - 1 < NUM) { \
44 cur = ID - 1; \
45 hi = ID; \
46 } else { \
47- hi = PARENT->NUM; \
48+ hi = NUM; \
49 cur = (hi - lo) / 2; \
50 } \
51 while (TRUE) { \
52 CHILD = PARENT->SET + cur; \
53- if (CHILD->ID == ID) \
54+ if (htonl(CHILD->ID) == ID) \
55 break; \
56- if (CHILD->ID < ID) { \
57+ if (htonl(CHILD->ID) < ID) { \
58 lo = cur + 1; \
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; \
63 dir = 1; \
64 } else { \
65 hi = cur; \
66@@ -240,32 +247,28 @@
67 }
68
69 static MCSetT *
70-MCGetSet(cat, setId)
71- MCCatT *cat;
72- int setId;
73+MCGetSet(MCCatT *cat, int setId)
74 {
75 MCSetT *set;
76 long lo, hi, cur, dir;
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;
94 long lo, hi, cur, dir;
95
96 if (set == NULL || set->invalid || msgId <= 0)
97 return (NULL);
98- LOOKUP(set, msg, msgId, numMsgs, u.msgs);
99+ LOOKUP(set, msg, msgId, htonl(set->numMsgs), u.msgs);
100 return (msg);
101 }
102
103@@ -377,27 +380,30 @@
104 strncmp(header.magic, MCMagic, MCMagicLen) != 0)
105 CORRUPT();
106
107- if (header.majorVer != MCMajorVer) {
108+ if (htonl(header.majorVer) != MCMajorVer) {
109 (void)fclose(cat->fp);
110 free(cat);
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);
115+ } else {
116+ (void)fprintf(stderr, "%s: %s is version %ld, we need %ld.\n", _errowner, catpath, htonl(header.majorVer), MCMajorVer);
117+ }
118 NLRETERR(EFTYPE);
119 }
120- if (header.numSets <= 0) {
121+ if (htonl(header.numSets) <= 0) {
122 (void)fclose(cat->fp);
123 free(cat);
124 (void)fprintf(stderr, "%s: %s has %ld sets!\n",
125- _errowner, catpath, header.numSets);
126+ _errowner, catpath, htonl(header.numSets));
127 NLRETERR(EFTYPE);
128 }
129
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)) ==
134 NULL)
135 NOSPACE();
136
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);
142@@ -414,7 +420,7 @@
143 /* if it's invalid, skip over it (and backup 'i') */
144 if (set->invalid) {
145 --i;
146- nextSet = set->nextSet;
147+ nextSet = htonll(set->nextSet);
148 continue;
149 }
150 #if 0
151@@ -432,7 +438,7 @@
152 } else
153 #endif
154 set->invalid = TRUE;
155- nextSet = set->nextSet;
156+ nextSet = htonll(set->nextSet);
157 }
158 #if 0
159 if (cat->loadType == MCLoadAll) {
160@@ -453,11 +459,11 @@
161 int saverr;
162
163 /* Get the data */
164- if (fseeko(cat->fp, set->data.off, SEEK_SET) == -1)
165+ if (fseeko(cat->fp, htonll(set->data.off), SEEK_SET) == -1)
166 return (0);
167- if ((set->data.str = malloc(set->dataLen)) == NULL)
168+ if ((set->data.str = malloc(htonl(set->dataLen))) == NULL)
169 return (-1);
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) {
172 saverr = errno;
173 free(set->data.str);
174 errno = saverr;
175@@ -465,13 +471,13 @@
176 }
177
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) {
181 saverr = errno;
182 free(set->data.str);
183 errno = saverr;
184 return (0);
185 }
186- if ((set->u.msgs = (MCMsgT *)malloc(sizeof(MCMsgT) * set->numMsgs)) ==
187+ if ((set->u.msgs = (MCMsgT *)malloc(sizeof(MCMsgT) * htonl(set->numMsgs))) ==
188 NULL) {
189 saverr = errno;
190 free(set->data.str);
191@@ -479,7 +485,7 @@
192 return (-1);
193 }
194
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) {
199 saverr = errno;
200@@ -492,7 +498,7 @@
201 --i;
202 continue;
203 }
204- msg->msg.str = (char *)(set->data.str + msg->msg.off);
205+ msg->msg.str = (char *)(set->data.str + htonll(msg->msg.off));
206 }
207 set->invalid = FALSE;
208 return (1);