| Ticket UUID: | 1902648 | ||
| Title: | Do not use strcasecmp | ||
| Type: | Bug | Created on: | 2008-02-27 01:45:46 |
| Submitter: | jenglish | Assigned to: | nobody |
| Subsystem: | 52. Portability Support | Severity: | |
| Priority: | 3 Low | Last modified: | 2010-09-15 05:56:49 |
| Status: | Open | Closed by: | |
| Resolution: | None | Closed on: | |
| Version: | obsolete: 8.5.1 | ||
| Description: | ||||
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. | ||||
| User Comments: | ||||
jenglish added on 2008-02-27 08:45:47:
File Added - 268199: ftbfs.errs jenglish added on 2008-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. jenglish added on 2008-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. jenglish added on 2008-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. rkeene added on 2010-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. | ||||
