Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2010-09-15
05:56 • Ticket [1902648fff] Do not use strcasecmp status still Open with 4 other cha... artifact: a0c1a2ce65 user: rkeene
2008-02-29
04:47 • Ticket [1902648fff]: 4 changes artifact: fbbc80ee94 user: jenglish
2008-02-27
09:53 • Ticket [1902648fff]: 4 changes artifact: 7bfcd92b03 user: jenglish
09:13 • Ticket [1902648fff]: 4 changes artifact: ac04219c70 user: jenglish
08:45 • Ticket [1902648fff]: 4 changes artifact: 45f34f5d2c user: jenglish
01:45 • New ticket [1902648fff]. artifact: e4d416c565 user: jenglish

Do not use strcasecmp

Open1902648fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 16 years ago
Descriptionplain2008-02-27 01:45:46
Found this when trying to build Tcl 8.5.1 on an ancient Unix (AIX 4.1):

Tcl 8.5.1 calls strcasecmp() in a few places, and it really should not.  strcasecmp is nonportable (it's not part of C89 -- with good reason).

FTBFS errors on AIX 4.1 attached.
jenglishplain2008-02-27 08:45:47
File Added - 268199: ftbfs.errs
jenglishplain2008-02-27 09:13:26
Logged In: YES 
user_id=68433
Originator: YES

More info:

There is a fallback implementation of strcasecmp and strncasecmp in compat/strncasecmp.c; however the autoconf logic to enable it is not being triggered on this platform.

AIX 4.1 has strcasecmp; it's defined in libc.a, and declared in <strings.h> along with a few other BSDisms like bcmp/bcopy/bzero, index, and rindex.  

Adding:

#if HAVE_STRINGS_H
#  include <strings.h>
#endif

to unix/tclUnixPort.h fixes the compile-time errors, and there are no subsequent link-time errors.

<strings.h> is in neither C89 nor POSIX, but it is specified in the Open Group Single Unix Specification.
jenglishplain2008-02-27 09:53:46
File Deleted - 268199: 

Logged In: YES 
user_id=68433
Originator: YES

strcasecmp is called in the following places in Tcl 8.5.1

+ In the implementation of [lsort -nocase], [switch -nocase], [lsearch -nocase], and [lsearch -sorted -nocase]

All of these uses were introduced by TIP#241.  The TIP does not specify whether "case-insensitive" means "ASCII-only", "locale-dependent", "UTF-aware but still ASCII-only", "according to one of the standardized Unicode normalization forms", or "what Tcl does elsewhere".  Presumably "what Tcl does elsewhere" (e.g., Tcl_StringCaseMatch, Tcl_UniCharToLower) is the most sensible.  strcasecmp() will typically be locale-dependent (or ASCII-only, which amounts to the same thing).  In any event, strcasecmp() is incorrect here, and causes portability problems.  This should be fixed.

+ In the definition of TclpInitLibraryPath().  This call was introduced 1999-04-15 <stanton> with the log message "merged tcl 8.1 branch back into the main trunk"; further details are lost to history.  It is not immediately clear to me why TclpInitLibraryPath is doing a case-insensitive comparison at this point, or indeed what it is doing at all.
jenglishplain2008-02-29 04:47:47
Logged In: YES 
user_id=68433
Originator: YES

See also #1236896 "make -nocase behave correct with non-ASCII characters".  That would take care of the first batch of calls.

Tracked the introduction of the strcasecmp() call in unix/tclUnixInit.c back to another jumbo patch; 
Committer: stanton <stanton>  1998-09-21 16:39:52
Changelog entry just says "Added contents of Tcl 8.1a2".  Sigh.

It looks like it might be related to early Mac OS support.
rkeeneplain2010-09-15 05:56:49
When using Diet Libc (<http://www.fefe.de/dietlibc/>), Tcl fails to build with complaints regarding strcasecmp.  Adding "#include <strings.h>" in generic/tclInt.h with the existing "#include <string.h>" fixes the issue and Tcl compiles cleanly.
Log in (anonymous is fine) to add a comment.