I tried Google a bit and I have found that you seem to have been "lucky" and that you have hit a problematic part of certain libc's. Problems with __ctype_b_loc() are reported repeatedly whenever ctype() tries to query locale settings. All reports seem to be rather old (2003 .. 2006) so that the problem should be gone now. It is possible that the AVR environment reproduces the bug. I have no experience with AVR programming. At any rate, it's not your bug, your code is okay.
Try to bypass ctype.h, use your own code. Also, there should be ctype.c somewhere around. Using this code instead of the code in libc was reported to solve the problem.