PERFORCE change 149051 for review
Konrad Jankowski
konrad at FreeBSD.org
Tue Sep 2 08:29:54 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=149051
Change 149051 by konrad at vspredator on 2008/09/02 08:29:17
Incremental changes to collate.c for new expansion support.
Also a cleanup of __collate_load_tables.
Affected files ...
.. //depot/projects/soc2008/konrad_collation/libc/locale/collate.c#10 edit
Differences ...
==== //depot/projects/soc2008/konrad_collation/libc/locale/collate.c#10 (text+ko) ====
@@ -70,7 +70,7 @@
FILE *fp;
int i, saverr, chains, z;
char strbuf[STR_LEN], buf[PATH_MAX];
- struct __locale_st_collate *TMP;
+ struct __locale_st_collate *TMP = NULL;
struct __collate_st_info info;
void *vp;
@@ -104,64 +104,44 @@
if ((fp = fopen(buf, "r")) == NULL)
return (_LDP_ERROR);
- if (fread(strbuf, sizeof(strbuf), 1, fp) != 1) {
- saverr = errno;
- (void)fclose(fp);
- errno = saverr;
- return (_LDP_ERROR);
- }
- chains = -1;
- if (strcmp(strbuf, COLLATE_VERSION1_3) == 0)
- chains = 1;
- if (chains < 0) {
+ if (fread(strbuf, sizeof(strbuf), 1, fp) != 1)
+ goto error_close_and_return;
+ if (strcmp(strbuf, COLLATE_VERSION1_4) != 0) {
fprintf(stderr, "__collate_load_tables: wrong signature: %s\n", strbuf);
- (void)fclose(fp);
errno = EFTYPE;
- return (_LDP_ERROR);
+ goto error_close_and_return;
}
- if (chains) {
- if (fread(&info, sizeof(info), 1, fp) != 1) {
- saverr = errno;
- (void)fclose(fp);
- errno = saverr;
- return (_LDP_ERROR);
- }
+ if (fread(&info, sizeof(info), 1, fp) != 1)
+ goto error_close_and_return;
#if _BYTE_ORDER == _LITTLE_ENDIAN
- for(z = 0; z < info.directive_count; z++) {
- info.undef_pri.pri[z] = ntohl(info.undef_pri.pri[z]);
- info.subst_count[z] = ntohl(info.subst_count[z]);
- }
- info.chain_count = ntohl(info.chain_count);
- info.large_pri_count = ntohl(info.large_pri_count);
+ for(z = 0; z < info.directive_count; z++) {
+ info.undef_pri.pri[z] = ntohl(info.undef_pri.pri[z]);
+ info.subst_count[z] = ntohl(info.subst_count[z]);
+ }
+ info.chain_count = ntohl(info.chain_count);
+ info.large_pri_count = ntohl(info.large_pri_count);
#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
- if ((chains = info.chain_count) < 0) {
- (void)fclose(fp);
- errno = EFTYPE;
- return (_LDP_ERROR);
- }
- } else
- chains = TABLE_SIZE;
+ if ((chains = info.chain_count) < 0) {
+#ifdef LOCALE_DEBUG
+ fprintf(stderr, "__collate_load_tables: wrong chain count (%d)\n",
+ chains);
+#endif
+ errno = EFTYPE;
+ goto error_close_and_return;
+ }
i = sizeof(struct __locale_st_collate)
+ sizeof(struct __collate_st_chain_pri) * chains
+ sizeof(struct __collate_st_large_char_pri) * info.large_pri_count;
for(z = 0; z < info.directive_count; z++)
i += sizeof(struct __collate_st_subst) * info.subst_count[z];
- if ((TMP = (struct __locale_st_collate *)malloc(i)) == NULL) {
- saverr = errno;
- (void)fclose(fp);
- errno = saverr;
- return (_LDP_ERROR);
- }
+ if ((TMP = (struct __locale_st_collate *)malloc(i)) == NULL)
+ goto error_close_and_return;
#define FREAD(a, b, c, d) \
{ \
if (fread(a, b, c, d) != c) { \
- saverr = errno; \
- free(TMP); \
- (void)fclose(d); \
- errno = saverr; \
- return (_LDP_ERROR); \
+ goto error_close_and_return; \
} \
}
@@ -251,6 +231,15 @@
__collate_info->directive_count = COLL_WEIGHTS_MAX;
return (_LDP_LOADED);
+
+ error_close_and_return:
+ saverr = errno;
+ (void)fclose(fp);
+ if (TMP)
+ free(TMP);
+ errno = saverr;
+
+ return (_LDP_ERROR);
}
static int
@@ -564,7 +553,7 @@
xfp = xf[pass];
if (direc & DIRECTIVE_POSITION) {
while(*t) {
- __collate_lookup_which(t, &len, &pri, pass);
+ pri = __collate_lookup(t, &len)->pri[pass];
t += len;
if (pri <= 0) {
if (pri < 0) {
@@ -578,7 +567,7 @@
}
} else {
while(*t) {
- __collate_lookup_which(t, &len, &pri, pass);
+ pri = __collate_lookup(t, &len)->pri[pass];
t += len;
if (pri <= 0) {
if (pri < 0) {
More information about the p4-projects
mailing list