[MPlayer-dev-eng] ctype.h functions on win32

Rich Felker dalias at aerifal.cx
Sat Oct 13 15:00:53 CEST 2007


On Sat, Oct 13, 2007 at 07:50:29AM +0200, Gianluigi Tiesi wrote:
> isspace can be replaced by check if value is 9 or 32
> this works on ascii, 8bit locales and utf-8
> obiviously doesn't work on utf-16, but you

You keep getting confused on irrelevant or incorrect lines of
thinking. UTF-16 is NOT A TEXT ENCODING. Read the relevant portion of
ISO C or POSIX on multibyte characters.

> > The current locale in MPlayer is always C, so it's not a problem.
> > However, leaving the locale as C is probably a bad idea...
> 
> this is a workaround not a solution

It's the current state of affairs. That was my only point.

> I currently mean:
> 
> if (c == -1) then do something to handle eof
> else call isspace with cast,
> -1 will never become 255 in the isspace call cast
> so it doesn't look so wrong
> 
> a better way is checking if < 0 then avoid isspace call at all
> no cast is needed here

No cast is needed to begin with; the cast does nothing unless there's
a bug in the C library implementation. The only possible return values
for fgetc are the integers in the range -1 to 255, the same as the
valid arguments to isspace.

> the problem is that isXXX functions with negative values are not
> working correct on mingw and they get a crash on msvc 2005 (not really a problem
> since mplayer cannot be compiled by msvc)
> on other platforms mileage can vary
> 
> signed chars can be changed to unsigned,

This is the only change needed.

> fgets stuff can be checked if
> negative,

Not useful. -1 is a valid argument.

> isXXX functions can be wrapped by a macro that checks if
> negative then returns false (0 or whatever) if positive returns
> the result of the api call

This would also work but it's ugly.

Rich



More information about the MPlayer-dev-eng mailing list