Boost logo

Boost :

From: Mike Morearty (mike_at_[hidden])
Date: 2000-01-11 17:39:28


Dang, and I thought I was being so good by looking up this line of code in
Josuttis' book before I posted! :-)

I should point out that I was calling ::tolower (the standard C function), not
std::tolower (the standard C++ function). I did this because it was easier --
the compiler wouldn't let me use std::tolower because std::tolower is templated,
so it couldn't pass it as a function pointer to transform().

In your comments and your code you mention std::tolower, but I think you mean
::tolower. std::tolower(T, locale) returns type T, but ::tolower(int) returns
type int.

In any case, in light of Ross Smith's comments about file extensions in an
earlier message, maybe the REAL solution here is to simply drop the
get<user_execute> function altogether from the Windows version of the code.
Dietmar has already chosen to omit set<user_execute>, get/set<group_execute>,
and get/set<other_execute>, because those simply don't make sense on Windows.
But in fact, you could really make a very good argument that get<user_execute>
doesn't make sense on Windows either. On Unix it has a very clear meaning, but
on Windows, you can pass any file you want to the CreateProcess() and ask it to
execute it; it will succeed for any native binary no matter what its extension,
and it will fail for anything other than a native binary. You can also pass any
file you want to COMMAND.COM or CMD.EXE and ask it to execute it; that will
succeed for some extensions and fail for others. I suppose strictly speaking,
get<user_execute> could call GetBinaryType(), but that's way too expensive --
that function opens the file and looks at its header.

____

Darin Adler wrote:

> > The easiest way to do that is by adding the following line to change the
> > "ext" variable to all lower-case:
> >
> > std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
>
> No!
>
> Unfortunately, std::tolower takes and returns an int, not a char. On some
> standard-conforming systems the above code will work, on others it will
> fail. Instead, do this:
>
> inline char chartolower(char c) { return std::tolower(c); }
>
> std::transform(ext.begin(), ext.end(), ext.begin(), chartolower);
>
> I've been discussing this with Nicolai Josuttis because this example appears
> in his book and he's planning to correct it.
>
> -- Darin


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk