char keyName[MAXPATHLEN]; PRInt32 r = PR_Read(fd, keyName, MAXPATHLEN);
r = PR_Read(fd, keyName, MAXPATHLEN);
RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation){  // Register ourself in the windows registry, and record what key we created  // for future unregistration.  nsresult rv;  PRBool irv;  int i;  nsCAutoString greHome;  rv = aLocation->GetNativePath(greHome);  if (NS_FAILED(rv))    return rv;  nsCOMPtr<nsIFile> savedInfoFile;  aLocation->Clone(getter_AddRefs(savedInfoFile));  nsCOMPtr<nsILocalFile> localSaved(do_QueryInterface(savedInfoFile));  if (!localSaved)    return PR_FALSE;  const char *infoname = aRegisterGlobally ? kRegFileGlobal : kRegFileUser;  localSaved->AppendNative(nsDependentCString(infoname));  PRFileDesc* fd = nsnull;  rv = localSaved->OpenNSPRFileDesc(PR_CREATE_FILE | PR_RDWR, 0664, &fd);  if (NS_FAILED(rv)) {    // XXX report error?    return PR_FALSE;  }  HKEY rootKey = NULL;  if (::RegCreateKeyEx(aRegisterGlobally ? HKEY_LOCAL_MACHINE :                                           HKEY_CURRENT_USER,                       kRegKeyRoot, NULL, NULL, 0, KEY_WRITE,                       NULL, &rootKey, NULL) != ERROR_SUCCESS) {    irv = PR_FALSE;    goto reg_end;  }  char keyName[MAXPATHLEN];  PRInt32 r = PR_Read(fd, keyName, MAXPATHLEN);  if (r < 0) {    irv = PR_FALSE;    goto reg_end;  }  if (r > 0) {    keyName[r] = '\0';    // There was already a .reginfo file, let's see if we are already    // registered.    HKEY existing = NULL;    if (::RegOpenKeyEx(rootKey, keyName, NULL, KEY_QUERY_VALUE, &existing) ==        ERROR_SUCCESS) {      fprintf(stderr, "Warning: Registry key Software\\mozilla.org\\GRE\\%s already exists.\n"              "No action was performed.\n",              keyName);      irv = PR_FALSE;      goto reg_end;    }    PR_Close(fd);    fd = nsnull;        rv = localSaved->OpenNSPRFileDesc(PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE, 0664, &fd);    if (NS_FAILED(rv)) {      // XXX report error?      irv = PR_FALSE;      goto reg_end;    }  }  strcpy(keyName, GRE_BUILD_ID);  rv = MakeVersionKey(rootKey, keyName, greHome);  if (NS_SUCCEEDED(rv)) {    PR_Write(fd, keyName, strlen(keyName));    irv = PR_TRUE;    goto reg_end;  }    for (i = 0; i < 1000; ++i) {    sprintf(keyName, GRE_BUILD_ID "_%i", i);    rv = MakeVersionKey(rootKey, keyName, greHome);    if (NS_SUCCEEDED(rv)) {      PR_Write(fd, keyName, strlen(keyName));      irv = PR_FALSE;      goto reg_end;    }  }  irv = PR_FALSE;reg_end:  if (fd)    PR_Close(fd);  if (rootKey)    ::RegCloseKey(rootKey);  return irv;}