aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/localedef
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2017-03-09 19:02:36 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2017-03-09 19:02:36 +0000
commitc48c87b790a1b0cd34b2987e2e07baeb757306d9 (patch)
treea1283cfd1a609edc29d86a0bafdf84416debf8a6 /usr.bin/localedef
parentf73286645f487e3ddd876858b867281f47b9f46e (diff)
downloadsrc-c48c87b790a1b0cd34b2987e2e07baeb757306d9.tar.gz
src-c48c87b790a1b0cd34b2987e2e07baeb757306d9.zip
Revert r314969, r314961:
The localdef(1) changes are breaking world: 00:18:40.750 /usr/src/share/colldef/af_ZA.UTF-8.src: 2421: error: Bad file descriptor I will fix them offline. Reported by: lwshu and many others
Notes
Notes: svn path=/head/; revision=314972
Diffstat (limited to 'usr.bin/localedef')
-rw-r--r--usr.bin/localedef/collate.c6
-rw-r--r--usr.bin/localedef/ctype.c45
-rw-r--r--usr.bin/localedef/localedef.c24
-rw-r--r--usr.bin/localedef/localedef.h3
-rw-r--r--usr.bin/localedef/time.c4
5 files changed, 31 insertions, 51 deletions
diff --git a/usr.bin/localedef/collate.c b/usr.bin/localedef/collate.c
index 8d1c0fb967e1..789053819011 100644
--- a/usr.bin/localedef/collate.c
+++ b/usr.bin/localedef/collate.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Nexenta Systems, Inc.
+ * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
* Copyright 2015 John Marino <draco@marino.st>
*
* This source code is derived from the illumos localedef command, and
@@ -1291,25 +1291,21 @@ dump_collate(void)
if ((wr_category(vers, COLLATE_STR_LEN, f) < 0) ||
(wr_category(&collinfo, sizeof (collinfo), f) < 0) ||
(wr_category(&chars, sizeof (chars), f) < 0)) {
- delete_category(f);
return;
}
for (i = 0; i < NUM_WT; i++) {
sz = sizeof (collate_subst_t) * collinfo.subst_count[i];
if (wr_category(subst[i], sz, f) < 0) {
- delete_category(f);
return;
}
}
sz = sizeof (collate_chain_t) * collinfo.chain_count;
if (wr_category(chain, sz, f) < 0) {
- delete_category(f);
return;
}
sz = sizeof (collate_large_t) * collinfo.large_count;
if (wr_category(large, sz, f) < 0) {
- delete_category(f);
return;
}
diff --git a/usr.bin/localedef/ctype.c b/usr.bin/localedef/ctype.c
index 20646d5d5708..0e238d79080f 100644
--- a/usr.bin/localedef/ctype.c
+++ b/usr.bin/localedef/ctype.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Nexenta Systems, Inc.
+ * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright 2012 Garrett D'Amore <garrett@damore.org> All rights reserved.
* Copyright 2015 John Marino <draco@marino.st>
*
@@ -306,7 +306,7 @@ dump_ctype(void)
return;
(void) memcpy(rl.magic, _FILE_RUNE_MAGIC_1, 8);
- (void) strlcpy(rl.encoding, get_wide_encoding(), sizeof (rl.encoding));
+ (void) strncpy(rl.encoding, get_wide_encoding(), sizeof (rl.encoding));
/*
* Initialize the identity map.
@@ -379,12 +379,12 @@ dump_ctype(void)
if ((ctn->ctype & _ISALPHA) &&
(ctn->ctype & (_ISPUNCT|_ISDIGIT)))
conflict++;
- if ((ctn->ctype & _ISPUNCT) &&
+ if ((ctn->ctype & _ISPUNCT) &
(ctn->ctype & (_ISDIGIT|_ISALPHA|_ISXDIGIT)))
conflict++;
if ((ctn->ctype & _ISSPACE) && (ctn->ctype & _ISGRAPH))
conflict++;
- if ((ctn->ctype & _ISCNTRL) && (ctn->ctype & _ISPRINT))
+ if ((ctn->ctype & _ISCNTRL) & _ISPRINT)
conflict++;
if ((wc == ' ') && (ctn->ctype & (_ISPUNCT|_ISGRAPH)))
conflict++;
@@ -412,10 +412,8 @@ dump_ctype(void)
ct[rl.runetype_ext_nranges-1].max = wc;
} else {
rl.runetype_ext_nranges++;
- ct = realloc(ct, rl.runetype_ext_nranges *
- sizeof (*ct));
- if (ct == NULL)
- goto fail;
+ ct = realloc(ct,
+ sizeof (*ct) * rl.runetype_ext_nranges);
ct[rl.runetype_ext_nranges - 1].min = wc;
ct[rl.runetype_ext_nranges - 1].max = wc;
ct[rl.runetype_ext_nranges - 1].map = ctn->ctype;
@@ -429,10 +427,8 @@ dump_ctype(void)
last_lo = ctn;
} else {
rl.maplower_ext_nranges++;
- lo = realloc(lo, rl.maplower_ext_nranges *
- sizeof (*lo));
- if (lo == NULL)
- goto fail;
+ lo = realloc(lo,
+ sizeof (*lo) * rl.maplower_ext_nranges);
lo[rl.maplower_ext_nranges - 1].min = wc;
lo[rl.maplower_ext_nranges - 1].max = wc;
lo[rl.maplower_ext_nranges - 1].map = ctn->tolower;
@@ -447,10 +443,8 @@ dump_ctype(void)
last_up = ctn;
} else {
rl.mapupper_ext_nranges++;
- up = realloc(up, rl.mapupper_ext_nranges *
- sizeof (*up));
- if (up == NULL)
- goto fail;
+ up = realloc(up,
+ sizeof (*up) * rl.mapupper_ext_nranges);
up[rl.mapupper_ext_nranges - 1].min = wc;
up[rl.mapupper_ext_nranges - 1].max = wc;
up[rl.mapupper_ext_nranges - 1].map = ctn->toupper;
@@ -458,17 +452,12 @@ dump_ctype(void)
}
}
- if ((wr_category(&rl, sizeof (rl), f) == 0) &&
- (wr_category(ct, sizeof (*ct) * rl.runetype_ext_nranges, f) == 0) &&
- (wr_category(lo, sizeof (*lo) * rl.maplower_ext_nranges, f) == 0) &&
- (wr_category(up, sizeof (*up) * rl.mapupper_ext_nranges, f) == 0)) {
- close_category(f);
- goto out;
+ if ((wr_category(&rl, sizeof (rl), f) < 0) ||
+ (wr_category(ct, sizeof (*ct) * rl.runetype_ext_nranges, f) < 0) ||
+ (wr_category(lo, sizeof (*lo) * rl.maplower_ext_nranges, f) < 0) ||
+ (wr_category(up, sizeof (*up) * rl.mapupper_ext_nranges, f) < 0)) {
+ return;
}
-fail:
- delete_category(f);
-out:
- free(ct);
- free(lo);
- free(up);}
+ close_category(f);
+}
diff --git a/usr.bin/localedef/localedef.c b/usr.bin/localedef/localedef.c
index bd8312365ae3..e4d0dff5c72a 100644
--- a/usr.bin/localedef/localedef.c
+++ b/usr.bin/localedef/localedef.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Nexenta Systems, Inc.
+ * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
* Copyright 2015 John Marino <draco@marino.st>
*
* This source code is derived from the illumos localedef command, and
@@ -126,19 +126,12 @@ open_category(void)
}
void
-delete_category(FILE *f)
-{
- (void) fclose(f);
- (void) unlink(category_file());
-}
-
-void
close_category(FILE *f)
{
- if (fchmod(fileno(f), 0644) < 0 ||
- fclose(f) != 0) {
+ if (fchmod(fileno(f), 0644) < 0) {
+ (void) fclose(f);
+ (void) unlink(category_file());
errf(strerror(errno));
- delete_category(f);
}
if (fclose(f) < 0) {
(void) unlink(category_file());
@@ -200,13 +193,15 @@ int
putl_category(const char *s, FILE *f)
{
if (s && fputs(s, f) == EOF) {
+ (void) fclose(f);
+ (void) unlink(category_file());
errf(strerror(errno));
- delete_category(f);
return (EOF);
}
if (fputc('\n', f) == EOF) {
+ (void) fclose(f);
+ (void) unlink(category_file());
errf(strerror(errno));
- delete_category(f);
return (EOF);
}
return (0);
@@ -219,8 +214,9 @@ wr_category(void *buf, size_t sz, FILE *f)
return (0);
}
if (fwrite(buf, sz, 1, f) < 1) {
+ (void) fclose(f);
+ (void) unlink(category_file());
errf(strerror(errno));
- delete_category(f);
return (EOF);
}
return (0);
diff --git a/usr.bin/localedef/localedef.h b/usr.bin/localedef/localedef.h
index c6ffdb53083b..8c829399d186 100644
--- a/usr.bin/localedef/localedef.h
+++ b/usr.bin/localedef/localedef.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Nexenta Systems, Inc.
+ * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
* Copyright 2015 John Marino <draco@marino.st>
*
* This source code is derived from the illumos localedef command, and
@@ -60,7 +60,6 @@ void warn(const char *, ...);
int putl_category(const char *, FILE *);
int wr_category(void *, size_t, FILE *);
FILE *open_category(void);
-void delete_category(FILE *);
void close_category(FILE *);
void copy_category(char *);
const char *category_name(void);
diff --git a/usr.bin/localedef/time.c b/usr.bin/localedef/time.c
index 80d04df11c8d..e40001d18e64 100644
--- a/usr.bin/localedef/time.c
+++ b/usr.bin/localedef/time.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Nexenta Systems, Inc.
+ * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
* Copyright 2015 John Marino <draco@marino.st>
*
* This source code is derived from the illumos localedef command, and
@@ -78,7 +78,7 @@ add_time_str(wchar_t *wcs)
break;
case T_DATE_FMT:
/*
- * This one is a Solaris extension. Too bad date just
+ * This one is a Solaris extension, Too bad date just
* doesn't use %c, which would be simpler.
*/
tm.date_fmt = str;