Index: /trunk/src/libs/xpcom18a4/xpcom/components/nsCategoryManager.cpp
===================================================================
--- /trunk/src/libs/xpcom18a4/xpcom/components/nsCategoryManager.cpp	(revision 102185)
+++ /trunk/src/libs/xpcom18a4/xpcom/components/nsCategoryManager.cpp	(revision 102186)
@@ -356,5 +356,5 @@
 
 struct persistent_userstruct {
-  PRFileDesc* fd;
+  PRTSTREAM   fd;
   const char* categoryName;
   PRBool      success;
@@ -370,9 +370,9 @@
 
   if (aLeaf->pValue) {
-    if (PR_fprintf(args->fd,
-                   "%s,%s,%s\n",
-                   args->categoryName,
-                   aLeaf->GetKey(),
-                   aLeaf->pValue) == (PRUint32) -1) {
+    if (RTStrmPrintf(args->fd,
+                     "%s,%s,%s\n",
+                     args->categoryName,
+                     aLeaf->GetKey(),
+                     aLeaf->pValue) == -1) {
       args->success = PR_FALSE;
       status = PL_DHASH_STOP;
@@ -384,5 +384,5 @@
 
 PRBool
-CategoryNode::WritePersistentEntries(PRFileDesc* fd, const char* aCategoryName)
+CategoryNode::WritePersistentEntries(PRTSTREAM fd, const char* aCategoryName)
 {
   persistent_userstruct args = {
@@ -645,5 +645,5 @@
 
 struct writecat_struct {
-  PRFileDesc* fd;
+  PRTSTREAM   fd;
   PRBool      success;
 };
@@ -665,5 +665,5 @@
 
 NS_METHOD
-nsCategoryManager::WriteCategoryManagerToRegistry(PRFileDesc* fd)
+nsCategoryManager::WriteCategoryManagerToRegistry(PRTSTREAM fd)
 {
   writecat_struct args = {
Index: /trunk/src/libs/xpcom18a4/xpcom/components/nsCategoryManager.h
===================================================================
--- /trunk/src/libs/xpcom18a4/xpcom/components/nsCategoryManager.h	(revision 102185)
+++ /trunk/src/libs/xpcom18a4/xpcom/components/nsCategoryManager.h	(revision 102186)
@@ -46,4 +46,5 @@
 
 #include <iprt/semaphore.h>
+#include <iprt/stream.h>
 
 #define NS_CATEGORYMANAGER_CLASSNAME     "Category Manager"
@@ -110,5 +111,5 @@
   NS_METHOD Enumerate(nsISimpleEnumerator** _retval);
 
-  PRBool WritePersistentEntries(PRFileDesc* fd, const char* aCategoryName);
+  PRBool WritePersistentEntries(PRTSTREAM fd, const char* aCategoryName);
 
   // CategoryNode is arena-allocated, with the strings
@@ -142,5 +143,5 @@
    * This is to be used by nsComponentManagerImpl (and NO ONE ELSE).
    */
-  NS_METHOD WriteCategoryManagerToRegistry(PRFileDesc* fd);
+  NS_METHOD WriteCategoryManagerToRegistry(PRTSTREAM fd);
 
   nsCategoryManager() : mLock(nsnull) { }
Index: /trunk/src/libs/xpcom18a4/xpcom/components/nsComponentManager.cpp
===================================================================
--- /trunk/src/libs/xpcom18a4/xpcom/components/nsComponentManager.cpp	(revision 102185)
+++ /trunk/src/libs/xpcom18a4/xpcom/components/nsComponentManager.cpp	(revision 102186)
@@ -88,4 +88,6 @@
 
 #include <iprt/assert.h>
+#include <iprt/file.h>
+#include <iprt/stream.h>
 #include <iprt/string.h>
 #include <VBox/log.h>
@@ -1276,5 +1278,5 @@
 struct PersistentWriterArgs
 {
-    PRFileDesc *mFD;
+    PRTSTREAM    mFD;
     nsLoaderdata *mLoaderData;
 };
@@ -1296,9 +1298,9 @@
         return PL_DHASH_NEXT;
 
-    PRFileDesc* fd = ((PersistentWriterArgs*)arg)->mFD;
+    PRTSTREAM fd = ((PersistentWriterArgs*)arg)->mFD;
 
     char cidString[UID_STRING_LENGTH];
     GetIDString(factoryEntry->mCid, cidString);
-    PR_fprintf(fd, "%s,%s\n", contractID, cidString); // what if this fails?
+    RTStrmPrintf(fd, "%s,%s\n", contractID, cidString); // what if this fails?
     return PL_DHASH_NEXT;
 }
@@ -1311,5 +1313,5 @@
 {
     nsFactoryEntry *factoryEntry = ((nsFactoryTableEntry*)hdr)->mFactoryEntry;
-    PRFileDesc* fd = ((PersistentWriterArgs*)arg)->mFD;
+    PRTSTREAM fd = ((PersistentWriterArgs*)arg)->mFD;
     nsLoaderdata *loaderData = ((PersistentWriterArgs*)arg)->mLoaderData;
 
@@ -1341,11 +1343,11 @@
 
     // cid,contract_id,type,class_name,inproc_server
-    PR_fprintf(fd,
-               "%s,%s,%s,%s,%s\n",
-               cidString,
-               (contractID ? contractID : ""),
-               (loaderName ? loaderName : ""),
-               (className  ? className  : ""),
-               (location   ? location   : ""));
+    RTStrmPrintf(fd,
+                 "%s,%s,%s,%s,%s\n",
+                 cidString,
+                 (contractID ? contractID : ""),
+                 (loaderName ? loaderName : ""),
+                 (className  ? className  : ""),
+                 (location   ? location   : ""));
 
     if (contractID)
@@ -1360,5 +1362,5 @@
 AutoRegEntryWriter(nsHashKey *aKey, void *aData, void* aClosure)
 {
-    PRFileDesc* fd = (PRFileDesc*) aClosure;
+    PRTSTREAM fd = (PRTSTREAM) aClosure;
     AutoRegEntry* entry = (AutoRegEntry*) aData;
 
@@ -1369,5 +1371,5 @@
     else
         fmt = "%s,%lld\n";
-    PR_fprintf(fd, fmt, entry->GetName().get(), entry->GetDate(), extraData);
+    RTStrmPrintf(fd, fmt, entry->GetName().get(), entry->GetDate(), extraData);
 
     return PR_TRUE;
@@ -1395,33 +1397,50 @@
     localFile->SetNativeLeafName(leafName);
 
-    PRFileDesc* fd = nsnull;
-    nsresult rv = localFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0600, &fd);
+    nsCAutoString pathName;
+    nsresult rv = localFile->GetNativePath(pathName);
     if (NS_FAILED(rv))
         return rv;
 
-    if (PR_fprintf(fd, "Generated File. Do not edit.\n") == (PRUint32) -1) {
+    RTFILE hFile      = NIL_RTFILE;
+    PRTSTREAM pStream = NULL;
+    int vrc = RTFileOpen(&hFile, pathName.get(),
+                         RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_TRUNCATE | RTFILE_O_DENY_NONE
+                         | (0600 << RTFILE_O_CREATE_MODE_SHIFT));
+    if (RT_SUCCESS(vrc))
+    {
+        vrc = RTStrmOpenFileHandle(hFile, "at", 0 /*fFlags*/, &pStream);
+        if (RT_FAILURE(vrc))
+        {
+            RTFileClose(hFile);
+            return NS_ERROR_UNEXPECTED;
+        }
+    }
+    else
+        return NS_ERROR_UNEXPECTED;
+
+    if (RTStrmPrintf(pStream, "Generated File. Do not edit.\n") == -1) {
         rv = NS_ERROR_UNEXPECTED;
         goto out;
     }
 
-    if (PR_fprintf(fd, "\n[HEADER]\nVersion,%d,%d\n",
+    if (RTStrmPrintf(pStream, "\n[HEADER]\nVersion,%d,%d\n",
                    PERSISTENT_REGISTRY_VERSION_MAJOR,
-                   PERSISTENT_REGISTRY_VERSION_MINOR) == (PRUint32) -1) {
+                   PERSISTENT_REGISTRY_VERSION_MINOR) == -1) {
         rv = NS_ERROR_UNEXPECTED;
         goto out;
     }
 
-    if (PR_fprintf(fd, "\n[COMPONENTS]\n") == (PRUint32) -1) {
+    if (RTStrmPrintf(pStream, "\n[COMPONENTS]\n") == -1) {
         rv = NS_ERROR_UNEXPECTED;
         goto out;
     }
 
-    mAutoRegEntries.Enumerate(AutoRegEntryWriter, (void*)fd);
+    mAutoRegEntries.Enumerate(AutoRegEntryWriter, (void*)pStream);
 
     PersistentWriterArgs args;
-    args.mFD = fd;
+    args.mFD = pStream;
     args.mLoaderData = mLoaderData;
 
-    if (PR_fprintf(fd, "\n[CLASSIDS]\n") == (PRUint32) -1) {
+    if (RTStrmPrintf(pStream, "\n[CLASSIDS]\n") == -1) {
         rv = NS_ERROR_UNEXPECTED;
         goto out;
@@ -1431,5 +1450,5 @@
     PL_DHashTableEnumerate(&mFactories, ClassIDWriter, (void*)&args);
 
-    if (PR_fprintf(fd, "\n[CONTRACTIDS]\n") == (PRUint32) -1) {
+    if (RTStrmPrintf(pStream, "\n[CONTRACTIDS]\n") == -1) {
         rv = NS_ERROR_UNEXPECTED;
         goto out;
@@ -1439,5 +1458,5 @@
     PL_DHashTableEnumerate(&mContractIDs, ContractIDWriter, (void*)&args);
 
-    if (PR_fprintf(fd, "\n[CATEGORIES]\n") == (PRUint32) -1) {
+    if (RTStrmPrintf(pStream, "\n[CATEGORIES]\n") == -1) {
         rv = NS_ERROR_UNEXPECTED;
         goto out;
@@ -1449,10 +1468,10 @@
         rv = NS_ERROR_UNEXPECTED;
     } else {
-        rv = mCategoryManager->WriteCategoryManagerToRegistry(fd);
+        rv = mCategoryManager->WriteCategoryManagerToRegistry(pStream);
     }
 
 out:
-    if (fd)
-        PR_Close(fd);
+    if (pStream)
+        RTStrmClose(pStream);
 
     // don't create the file is there was a problem????
