Message-Id: <199902122232.RAA21568@delorie.com> From: Robert Hoehne Organization: none provided To: djgpp-workers AT delorie DOT com Date: Fri, 12 Feb 1999 23:33:14 +0100 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: ctype functions In-reply-to: <199902122120.QAA21593@envy.delorie.com> References: <199902122054 DOT PAA16714 AT delorie DOT com> (message from Robert Hoehne on Fri, 12 Feb 1999 21:55:17 +0100) X-mailer: Pegasus Mail for Win32 (v3.01d) Reply-To: djgpp-workers AT delorie DOT com > > We should fix our files in these cases, they're clearly wrong. If you really think so, here now a first try to fix at least tolower() and toupper() related things. The other ctype functions should be checked too. (But in my opinion the patch for ctype.h did the same in a shorter and saver way). --- src/libc/ansi/stdio/rename.c~ Sun Aug 31 14:01:58 1997 +++ src/libc/ansi/stdio/rename.c Fri Feb 12 23:03:26 1999 @@ -191,7 +191,7 @@ { if (dir1 == 0 || dir2 == 0 || *dir1 == 0) return 0; - while (*dir1 && *dir2 && tolower(*dir1) == tolower(*dir2)) + while (*dir1 && *dir2 && tolower((int)(unsigned char)*dir1) == tolower((int)(unsigned char)*dir2)) { dir1++; dir2++; @@ -284,11 +284,11 @@ /* Fail with EXDEV, if old and new aren't on the same device. */ if (old[1] == ':') - old_dev = toupper(old[0]) - 'A'; + old_dev = toupper((int)(unsigned char)old[0]) - 'A'; else old_dev = getdisk(); if (new[1] == ':') - new_dev = toupper(new[0]) - 'A'; + new_dev = toupper((int)(unsigned char)new[0]) - 'A'; else new_dev = getdisk(); if (old_dev != new_dev) --- src/libc/ansi/time/strftime.c~ Thu Jan 1 16:42:52 1998 +++ src/libc/ansi/time/strftime.c Fri Feb 12 23:03:50 1999 @@ -35,7 +35,7 @@ if (!(*pt = *str++)) return 1; if (upcase) - *pt = toupper(*pt); + *pt = toupper((int)(unsigned char)*pt); } } --- src/libc/compat/mntent/mntent.c~ Sun Nov 15 14:20:56 1998 +++ src/libc/compat/mntent/mntent.c Fri Feb 12 23:04:20 1999 @@ -669,7 +669,7 @@ truename_result = _truename(drive_string, mnt_fsname); if (truename_result && mnt_fsname[0] && mnt_fsname[1] == ':' && islower(mnt_fsname[0])) - mnt_fsname[0] = toupper(mnt_fsname[0]); + mnt_fsname[0] = toupper((int)(unsigned char)mnt_fsname[0]); /* Get some info from the DOS Current Directory Structure (CDS). We've already hit the disk with _truename(), so CDS now @@ -862,7 +862,7 @@ if (*p == '\\') *p = '/'; else - *p = tolower(*p); + *p = tolower((int)(unsigned char)*p); } /* Should we convert ``\\HOST\PATH'' into ``HOST:PATH''? */ --- src/libc/compat/string/memicmp.c~ Sun Aug 31 15:34:14 1997 +++ src/libc/compat/string/memicmp.c Fri Feb 12 23:05:06 1999 @@ -12,7 +12,7 @@ do { if (*p1 != *p2) { - int c = toupper(*p1) - toupper(*p2); + int c = toupper((int)(unsigned char)*p1) - toupper((int)(unsigned char)*p2); if (c) return c; } --- src/libc/compat/string/stricmp.c~ Thu Nov 16 00:38:26 1995 +++ src/libc/compat/string/stricmp.c Fri Feb 12 22:57:32 1999 @@ -6,12 +6,12 @@ int stricmp(const char *s1, const char *s2) { - while (tolower(*s1) == tolower(*s2)) + while (tolower((int)(unsigned char)*s1) == tolower((int)(unsigned char)*s2)) { if (*s1 == 0) return 0; s1++; s2++; } - return (int)tolower(*s1) - (int)tolower(*s2); + return (int)tolower((int)(unsigned char)*s1) - (int)tolower((int)(unsigned char)*s2); } --- src/libc/compat/string/strlwr.c~ Sat Mar 11 22:53:40 1995 +++ src/libc/compat/string/strlwr.c Fri Feb 12 22:57:46 1999 @@ -8,7 +8,7 @@ char *rv = _s; while (*_s) { - *_s = tolower(*_s); + *_s = tolower((int)(unsigned char)*_s); _s++; } return rv; --- src/libc/compat/string/strnicmp.c~ Thu Nov 16 00:38:50 1995 +++ src/libc/compat/string/strnicmp.c Fri Feb 12 22:58:20 1999 @@ -9,8 +9,8 @@ if (n == 0) return 0; do { - if (tolower(*s1) != tolower(*s2++)) - return (int)tolower(*s1) - (int)tolower(*--s2); + if (tolower((int)(unsigned char)*s1) != tolower((int)(unsigned char)*s2++)) + return (int)tolower((int)(unsigned char)*s1) - (int)tolower((int)(unsigned char)*--s2); if (*s1++ == 0) break; } while (--n != 0); --- src/libc/compat/string/strupr.c~ Sat Mar 11 22:53:48 1995 +++ src/libc/compat/string/strupr.c Fri Feb 12 23:05:28 1999 @@ -8,7 +8,7 @@ char *rv = _s; while (*_s) { - *_s = toupper(*_s); + *_s = toupper((int)(unsigned char)*_s); _s++; } return rv; --- src/libc/crt0/c1args.c~ Sun Jul 26 13:33:36 1998 +++ src/libc/crt0/c1args.c Fri Feb 12 22:58:46 1999 @@ -376,7 +376,7 @@ argv0[i] = '/'; if (!(_crt0_startup_flags & _CRT0_FLAG_PRESERVE_UPPER_CASE)) if (isupper(argv0[i])) - argv0[i] = tolower(argv0[i]); + argv0[i] = tolower((int)(unsigned char)argv0[i]); } if (_crt0_startup_flags & _CRT0_FLAG_DROP_EXE_SUFFIX) { --- src/libc/crt0/c1loadef.c~ Fri Jul 26 00:50:56 1996 +++ src/libc/crt0/c1loadef.c Fri Feb 12 23:05:34 1999 @@ -49,7 +49,7 @@ if (strchr("\\/:", *a0p)) bp = a0p+1; for (a0p=base+1; *bp && *bp != '.';) - *a0p++ = tolower(*bp++); + *a0p++ = tolower((int)(unsigned char)*bp++); *a0p++ = ']'; *a0p++ = 0; @@ -136,8 +136,8 @@ char ec = *e++; if (strchr("\\/:", ec)) dirend=dp; - if (mapup) ec = toupper(ec); - if (maplow) ec = tolower(ec); + if (mapup) ec = toupper((int)(unsigned char)ec); + if (maplow) ec = tolower((int)(unsigned char)ec); if (mapfs && ec == '\\') ec = '/'; if (mapbs && ec == '/') ec = '\\'; *dp++ = ec; --- src/libc/dos/lfn/_use_lfn.c~ Sun Dec 13 13:09:46 1998 +++ src/libc/dos/lfn/_use_lfn.c Fri Feb 12 22:59:48 1999 @@ -164,7 +164,7 @@ last_env_changed = __environ_changed; lfnenv = getenv ("LFN"); - if(lfnenv && (tolower (lfnenv[0]) == 'n')) + if(lfnenv && (tolower ((int)(unsigned char)lfnenv[0]) == 'n')) { _lfnenv = 'n'; last_drive = 0; --- src/libc/dos/lfn/fncase.c~ Sat Aug 31 22:09:32 1996 +++ src/libc/dos/lfn/fncase.c Fri Feb 12 23:00:08 1999 @@ -11,5 +11,5 @@ char *ep; return ((_crt0_startup_flags & _CRT0_FLAG_PRESERVE_FILENAME_CASE) - || ((ep = getenv ("FNCASE")) && tolower (*ep) == 'y')); + || ((ep = getenv ("FNCASE")) && tolower ((int)(unsigned char)*ep) == 'y')); } --- src/libc/dos/lfn/lfnshort.c~ Sun Jun 28 22:18:16 1998 +++ src/libc/dos/lfn/lfnshort.c Fri Feb 12 23:07:50 1999 @@ -70,7 +70,7 @@ const char *s = long_fname; char *d = short_fname; - while ((*d++ = msdos_toupper_fname (*s++))) + while ((*d++ = msdos_toupper_fname ((int)(unsigned char)*s++))) if (d - short_fname >= 12) { *d = '\0'; --- src/libc/emu387/npxsetup.c~ Mon Sep 7 18:55:40 1998 +++ src/libc/emu387/npxsetup.c Fri Feb 12 23:00:40 1999 @@ -69,12 +69,12 @@ #endif cp = getenv("387"); - if (cp && (tolower(cp[0]) == 'y')) + if (cp && (tolower((int)(unsigned char)cp[0]) == 'y')) { _control87(0x033f, 0xffff); /* mask all numeric exceptions */ return; } - if (cp && (tolower(cp[0]) == 'n')) + if (cp && (tolower((int)(unsigned char)cp[0]) == 'n')) have_80387 = 0; else { @@ -85,7 +85,7 @@ _8087 = (have_80387 ? 3 : 0); } - if (cp && (tolower(cp[0]) == 'q')) { + if (cp && (tolower((int)(unsigned char)cp[0]) == 'q')) { if (!have_80387) _write(2, "No ", 3); _write(2, "80387 detected.\r\n", 17); --- src/libc/posix/fnmatch/fnmatch.c~ Sun Jun 28 23:10:42 1998 +++ src/libc/posix/fnmatch/fnmatch.c Fri Feb 12 23:09:22 1999 @@ -41,13 +41,13 @@ { if (c <= test && test <= c2) ok = 1; - if (nocase && toupper(c) <= toupper(test) && toupper(test) <= toupper(c2)) + if (nocase && toupper((int)(unsigned char)c) <= toupper((int)(unsigned char)test) && toupper ((int)(unsigned char)test) <= toupper((int)(unsigned char)c2)) ok = 1; pattern += 2; } else if (c == test) ok = 1; - else if (nocase && (toupper(c) == toupper(test))) + else if (nocase && (toupper((int)(unsigned char)c) == toupper((int)(unsigned char)test))) ok = 1; } return ok == negate ? NULL : pattern; @@ -133,7 +133,7 @@ } if (flags & FNM_NOCASE) { - if (toupper(c) != toupper(*string++)) + if (toupper((int)(unsigned char)c) != toupper((int)(unsigned char)*string++)) return FNM_NOMATCH; } else --- src/libc/posix/regex/regcomp.c~ Thu Jul 16 18:20:30 1998 +++ src/libc/posix/regex/regcomp.c Fri Feb 12 23:09:38 1999 @@ -823,9 +823,9 @@ { assert(isalpha(ch)); if (isupper(ch)) - return(tolower(ch)); + return(tolower((int)(unsigned char)ch)); else if (islower(ch)) - return(toupper(ch)); + return(toupper((int)(unsigned char)ch)); else /* peculiar, but could happen */ return(ch); } --- src/libc/posix/sys/stat/fixpath.c~ Sun Dec 13 13:09:46 1998 +++ src/libc/posix/sys/stat/fixpath.c Fri Feb 12 23:20:58 1999 @@ -5,7 +5,6 @@ #include /* For FILENAME_MAX */ #include #include /* For errno */ -#include /* For tolower */ #include /* For strlen() */ #include /* For LFN stuff */ #include --- src/libc/posix/sys/stat/is_exec.c~ Sat Oct 19 12:24:46 1996 +++ src/libc/posix/sys/stat/is_exec.c Fri Feb 12 23:10:10 1999 @@ -190,7 +190,7 @@ if (*extension == '.') extension++; while (*extension) - *tp++ = toupper (*extension++); + *tp++ = toupper ((int)(unsigned char)*extension++); *tp++ = '|'; *tp = '\0'; if (strstr(non_executables, tmp_buf)) --- src/libc/posix/sys/stat/stat.c~ Tue Aug 25 09:47:26 1998 +++ src/libc/posix/sys/stat/stat.c Fri Feb 12 23:11:46 1999 @@ -452,7 +452,7 @@ /* Get the drive number. It is always explicit, since we called `_fixpath' on the original pathname. */ - drv_no = toupper(pathname[0]) - 'A'; + drv_no = toupper((int)(unsigned char)pathname[0]) - 'A'; /* Produce canonical pathname, with all the defaults resolved and all redundant parts removed. This calls undocumented DOS @@ -521,7 +521,7 @@ because SUBST.EXE and JOIN.EXE won't let you do it; so, for these cases, there is no problem in believing the drive number we've got from the original path (or is there?). */ - drv_no = toupper(canon_path[0]) - 'A'; + drv_no = toupper((int)(unsigned char)canon_path[0]) - 'A'; } } else @@ -579,7 +579,7 @@ statbuf->st_ino = _invent_inode(canon_path, dos_ftime, ff_blk.ff_fsize); } - else if (toupper (canon_path[0]) != toupper (pathname[0]) + else if (toupper ((int)(unsigned char)canon_path[0]) != toupper ((int)(unsigned char)pathname[0 ]) && canon_path[1] == ':' && canon_path[2] == '\\' && canon_path[3] == '\0') @@ -707,7 +707,7 @@ if (j >= i) { for ( ; i >= 0 && j >= 0; i--, j--) - if (toupper (ff_blk.ff_name[i]) != toupper (pathname[j])) + if (toupper ((int)(unsigned char)ff_blk.ff_name[i]) != toupper ((int)(unsigned char)pathname[j]) ) break; } } --- src/libc/posix/unistd/pathconf.c~ Sun Aug 31 16:07:06 1997 +++ src/libc/posix/unistd/pathconf.c Fri Feb 12 23:02:12 1999 @@ -7,7 +7,7 @@ #include #include -#define TOLOWER(c) (isascii(c) && isupper(c) ? tolower (c) : (c)) +#define TOLOWER(c) (isascii(c) && isupper(c) ? tolower ((int)(unsigned char)c) : (c)) long pathconf(const char *path, int name) ****************************************************** * email: Robert Hoehne * * Post: Am Berg 3, D-09573 Dittmannsdorf, Germany * * WWW: http://www.tu-chemnitz.de/~sho/rho * ******************************************************