summaryrefslogtreecommitdiff
path: root/usr.sbin/zic
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2015-02-10 09:17:03 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2015-02-10 09:17:03 +0000
commit54d006ed012062423884374decf65fd4dd142d22 (patch)
tree99274ca9b3896c1cb3c43a9bd1154d4e099f70e6 /usr.sbin/zic
parent72991b730a41018e0dc85d41d6a9e21219404c40 (diff)
redo the tolower/string conversion, but retain itsabbr which is strangely
not quite the same as strncasecmp
Diffstat (limited to 'usr.sbin/zic')
-rw-r--r--usr.sbin/zic/zic.c42
1 files changed, 12 insertions, 30 deletions
diff --git a/usr.sbin/zic/zic.c b/usr.sbin/zic/zic.c
index b9c0c042ae8..6213f53817d 100644
--- a/usr.sbin/zic/zic.c
+++ b/usr.sbin/zic/zic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: zic.c,v 1.15 2015/02/10 05:45:46 tedu Exp $ */
+/* $OpenBSD: zic.c,v 1.16 2015/02/10 09:17:02 tedu Exp $ */
/*
** This file is in the public domain, so clarified as of
** 2006-07-17 by Arthur David Olson.
@@ -94,7 +94,6 @@ static int addtype(long gmtoff, const char * abbr, int isdst,
static void leapadd(zic_t t, int positive, int rolling, int count);
static void adjleap(void);
static void associate(void);
-static int ciequal(const char * ap, const char * bp);
static void convert(long val, char * buf);
static void convert64(zic_t val, char * buf);
static void dolink(const char * fromfield, const char * tofield);
@@ -118,7 +117,6 @@ static int inzsub(char ** fields, int nfields, int iscont);
static int is32(zic_t x);
static int itsabbr(const char * abbr, const char * word);
static int itsdir(const char * name);
-static int lowerit(int c);
static int mkdirs(char * filename);
static void newabbr(const char * abbr);
static long oadd(long t1, long t2);
@@ -1190,7 +1188,7 @@ const char * const timep;
dp = ecpyalloc(timep);
if (*dp != '\0') {
ep = dp + strlen(dp) - 1;
- switch (lowerit(*ep)) {
+ switch (tolower((unsigned char)*ep)) {
case 's': /* Standard */
rp->r_todisstd = TRUE;
rp->r_todisgmt = FALSE;
@@ -2295,38 +2293,21 @@ yearistype(int year, const char *type)
errx(1, "command was '%s', result was %d", buf, result);
}
+/* this function is not strncasecmp */
static int
-lowerit(a)
-int a;
+itsabbr(const char *sabbr, const char *sword)
{
- a = (unsigned char) a;
- return (isascii(a) && isupper(a)) ? tolower(a) : a;
-}
-
-static int
-ciequal(ap, bp) /* case-insensitive equality */
-const char * ap;
-const char * bp;
-{
- while (lowerit(*ap) == lowerit(*bp++))
- if (*ap++ == '\0')
- return TRUE;
- return FALSE;
-}
+ const unsigned char *abbr = sabbr;
+ const unsigned char *word = sword;
-static int
-itsabbr(abbr, word)
-const char * abbr;
-const char * word;
-{
- if (lowerit(*abbr) != lowerit(*word))
+ if (tolower(*abbr) != tolower(*word))
return FALSE;
- ++word;
while (*++abbr != '\0')
do {
+ ++word;
if (*word == '\0')
return FALSE;
- } while (lowerit(*word++) != lowerit(*abbr));
+ } while (tolower(*word) != tolower(*abbr));
return TRUE;
}
@@ -2342,7 +2323,7 @@ byword(const char *word, const struct lookup *table)
** Look for exact match.
*/
for (lp = table; lp->l_word != NULL; ++lp)
- if (ciequal(word, lp->l_word))
+ if (strcasecmp(word, lp->l_word) == 0)
return lp;
/*
** Look for inexact match.
@@ -2352,7 +2333,8 @@ byword(const char *word, const struct lookup *table)
if (itsabbr(word, lp->l_word)) {
if (foundlp == NULL)
foundlp = lp;
- else return NULL; /* multiple inexact matches */
+ else
+ return NULL; /* multiple inexact matches */
}
return foundlp;
}