nsCAutoString illegalChars;
nsresult NS_MsgHashIfNecessary(nsCAutoString &name){#if defined(XP_MAC)  nsCAutoString illegalChars(":");  const PRUint32 MAX_LEN = 25;#elif defined(XP_UNIX) || defined(XP_BEOS)  nsCAutoString illegalChars;  // is this correct for BEOS?  const PRUint32 MAX_LEN = 55;#elif defined(XP_WIN32)  nsCAutoString illegalChars("\"/\\[]:;=,|?<>*$");  const PRUint32 MAX_LEN = 55;#elif defined(XP_OS2)  nsCAutoString illegalChars("\"/\\[]:;=,|?<>*$");  const PRUint32 MAX_LEN = 55;#else#error need_to_define_your_max_filename_length#endif  nsCAutoString str(name);  // Given a filename, make it safe for filesystem  // certain filenames require hashing because they   // are too long or contain illegal characters  PRInt32 illegalCharacterIndex = str.FindCharInSet(illegalChars);  char hashedname[MAX_LEN + 1];  if (illegalCharacterIndex == kNotFound)   {    // no illegal chars, it's just too long    // keep the initial part of the string, but hash to make it fit    if (str.Length() > MAX_LEN)     {      PL_strncpy(hashedname, str.get(), MAX_LEN + 1);      PR_snprintf(hashedname + MAX_LEN - 8, 9, "%08lx",                (unsigned long) StringHash(str.get()));      name = hashedname;    }  }  else   {      // found illegal chars, hash the whole thing      // if we do substitution, then hash, two strings      // could hash to the same value.      // for example, on mac:  "foo__bar", "foo:_bar", "foo::bar"      // would map to "foo_bar".  this way, all three will map to      // different values      PR_snprintf(hashedname, 9, "%08lx",                (unsigned long) StringHash(str.get()));      name = hashedname;  }    return NS_OK;}