
On Wed, 21 Apr 2010 12:18:41 +1200 Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
Paul Moore wrote:
As Mike Meyer explained, whether file foo.C "has extension .c" depends (as far as the user is concerned) on whether the filesystem it's on is case sensitive.
I don't think that's really true. It's common to find, e.g., files ending with .jpg, .JPG, or other variations on a case-sensitive filesystem that got there by being copied from a case-insensitive one, or simply created by people using tools that don't care about the case of the extension.
That's probably true for the vast majority of extensions, but I chose .C vs. .c for a reason - gcc thinks they are different: bhuda% cmp bunny.c bunny.C bhuda% file bunny.? bunny.C: ASCII C program text bunny.c: ASCII C program text bhuda% gcc bunny.c bhuda% g++ bunny.c bunny.c: In function 'int main(int, char**)': bunny.c:25: error: 'fork' was not declared in this scope bunny.c:26: error: 'wait' was not declared in this scope bhuda% gcc bunny.C bunny.C: In function 'int main(int, char**)': bunny.C:25: error: 'fork' was not declared in this scope bunny.C:26: error: 'wait' was not declared in this scope bhuda%
Seems to me the best thing to do is always compare extensions case-insensitively unless you have a specific reason to do otherwise. So I would recommend that any proposed hasextension() function should be case-insensitive by default.
Reasonable, but if you have a way to make it case-sensitive, you're back where we started from: needing to figure out whether the files in question care about case. Given the number of options here - including that the file may not exist yet, and ditto for the file system it's going to be on - possibly the solution is to leave off that option, and document that this case has to be dealt with by the caller. <mike -- Mike Meyer <mwm@mired.org> http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org