by Michael S. Kaplan, published on 2005/12/27 16:01 -05:00, original URI: http://blogs.msdn.com/b/michkap/archive/2005/12/27/507599.aspx
Documentation for API functions can sometimes fall behind and not keep up to the way functions work.
I know, that is a huge newsflash for everyone.... :-)
Eventually we fix in though.
If you look at the Locale Information topic that contains the LCTYPE values used by GetLocaleInfo/SetLocaleInfo, you will notice that for all of the string fields that can be altered by SetLocaleInfo we list the maximum legal size (including the NULL character). For example:
LOCALE_S1159
String for the AM designator (first 12 hours of the day). The maximum number of characters allowed for this string is different for different releases of Windows:
- Windows 95/98/Me, Windows NT 4/2000: nine.
- Windows XP: thirteen for SetLocaleInfo, fifteen for GetLocaleInfo.
- Windows Server 2003 or later: fifteen
LOCALE_S2359
String for the PM designator (second 12 hours of the day). The maximum number of characters allowed for this string is different for different releases of Windows:
- Windows 95/98/Me, Windows NT 4/2000: nine.
- Windows XP: thirteen for SetLocaleInfo, fifteen for GetLocaleInfo.
- Windows Server 2003 or later: fifteen
Now obviously this was not always what was there. In fact, if you look at the Platform SDK documentation in the October 2005 MSDN release, you will find a different story:
LOCALE_S1159
String for the AM designator. The maximum number of characters allowed for this string is nine.LOCALE_S2359
String for the PM designator. The maximum number of characters allowed for this string is nine.
(that number includes the NULL character)
So the new documentation has certainly worked to better describe a problem that has existed in the documentation for years after Windows XP and Server 2003 have shipped.
So how is it that the GetLocaleInfo and SetLocaleInfo limits are different?
Well, I guess it was a combination of how the functions work and what they are trying to do in Windows.
Prior to Vista, the locale data is always what we ship, which we trust. So GetLocaleInfo does not have to verify the length, it can just pick up its null-terminated string from its cache and return it. This is different than SetLocaleInfo, which has to do things with that string like put it in the registry and thd cache. So we have to care about the maximum length a bit more.
Now some time before XP shipped, the official limit was raised to 13 (12 plus the NULL) because some locale had strings greater then 8 characters.
Unfortunately, no one noticed that Gujarati had strings that were longer than this:
They are both 14 characters each. So you can retrieve them, but you can't set them!
Sometimes we might look less strange/mysterious when we explain what is happening, at the cost of seeming a little more foolish. It is definitely a trade off!
This post brought to you by "મ" (U+0aae, GUJARATI LETTER MA)
# Centaur on 28 Dec 2005 11:00 AM:
# Michael S. Kaplan on 28 Dec 2005 11:07 AM:
# Centaur on 29 Dec 2005 11:59 PM:
# Michael S. Kaplan on 30 Dec 2005 10:11 AM:
# silverpie on 30 Dec 2005 12:06 PM:
# Michael S. Kaplan on 30 Dec 2005 12:39 PM:
referenced by