VirtualBox

Changeset 102186 in vbox for trunk/src


Ignore:
Timestamp:
Nov 21, 2023 10:38:17 AM (17 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
160311
Message:

libs/xpcom/xpcom: Convert nsComponentManager and nsCategoryManager registry writing from nsprpub to IPRT streams, bugref:10545

Location:
trunk/src/libs/xpcom18a4/xpcom/components
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/xpcom/components/nsCategoryManager.cpp

    r101976 r102186  
    356356
    357357struct persistent_userstruct {
    358   PRFileDesc* fd;
     358  PRTSTREAM  fd;
    359359  const char* categoryName;
    360360  PRBool      success;
     
    370370
    371371  if (aLeaf->pValue) {
    372     if (PR_fprintf(args->fd,
    373                    "%s,%s,%s\n",
    374                    args->categoryName,
    375                    aLeaf->GetKey(),
    376                    aLeaf->pValue) == (PRUint32) -1) {
     372    if (RTStrmPrintf(args->fd,
     373                     "%s,%s,%s\n",
     374                     args->categoryName,
     375                     aLeaf->GetKey(),
     376                     aLeaf->pValue) == -1) {
    377377      args->success = PR_FALSE;
    378378      status = PL_DHASH_STOP;
     
    384384
    385385PRBool
    386 CategoryNode::WritePersistentEntries(PRFileDesc* fd, const char* aCategoryName)
     386CategoryNode::WritePersistentEntries(PRTSTREAM fd, const char* aCategoryName)
    387387{
    388388  persistent_userstruct args = {
     
    645645
    646646struct writecat_struct {
    647   PRFileDesc* fd;
     647  PRTSTREAM  fd;
    648648  PRBool      success;
    649649};
     
    665665
    666666NS_METHOD
    667 nsCategoryManager::WriteCategoryManagerToRegistry(PRFileDesc* fd)
     667nsCategoryManager::WriteCategoryManagerToRegistry(PRTSTREAM fd)
    668668{
    669669  writecat_struct args = {
  • trunk/src/libs/xpcom18a4/xpcom/components/nsCategoryManager.h

    r101976 r102186  
    4646
    4747#include <iprt/semaphore.h>
     48#include <iprt/stream.h>
    4849
    4950#define NS_CATEGORYMANAGER_CLASSNAME     "Category Manager"
     
    110111  NS_METHOD Enumerate(nsISimpleEnumerator** _retval);
    111112
    112   PRBool WritePersistentEntries(PRFileDesc* fd, const char* aCategoryName);
     113  PRBool WritePersistentEntries(PRTSTREAM fd, const char* aCategoryName);
    113114
    114115  // CategoryNode is arena-allocated, with the strings
     
    142143   * This is to be used by nsComponentManagerImpl (and NO ONE ELSE).
    143144   */
    144   NS_METHOD WriteCategoryManagerToRegistry(PRFileDesc* fd);
     145  NS_METHOD WriteCategoryManagerToRegistry(PRTSTREAM fd);
    145146
    146147  nsCategoryManager() : mLock(nsnull) { }
  • trunk/src/libs/xpcom18a4/xpcom/components/nsComponentManager.cpp

    r102175 r102186  
    8888
    8989#include <iprt/assert.h>
     90#include <iprt/file.h>
     91#include <iprt/stream.h>
    9092#include <iprt/string.h>
    9193#include <VBox/log.h>
     
    12761278struct PersistentWriterArgs
    12771279{
    1278     PRFileDesc *mFD;
     1280    PRTSTREAM    mFD;
    12791281    nsLoaderdata *mLoaderData;
    12801282};
     
    12961298        return PL_DHASH_NEXT;
    12971299
    1298     PRFileDesc* fd = ((PersistentWriterArgs*)arg)->mFD;
     1300    PRTSTREAM fd = ((PersistentWriterArgs*)arg)->mFD;
    12991301
    13001302    char cidString[UID_STRING_LENGTH];
    13011303    GetIDString(factoryEntry->mCid, cidString);
    1302     PR_fprintf(fd, "%s,%s\n", contractID, cidString); // what if this fails?
     1304    RTStrmPrintf(fd, "%s,%s\n", contractID, cidString); // what if this fails?
    13031305    return PL_DHASH_NEXT;
    13041306}
     
    13111313{
    13121314    nsFactoryEntry *factoryEntry = ((nsFactoryTableEntry*)hdr)->mFactoryEntry;
    1313     PRFileDesc* fd = ((PersistentWriterArgs*)arg)->mFD;
     1315    PRTSTREAM fd = ((PersistentWriterArgs*)arg)->mFD;
    13141316    nsLoaderdata *loaderData = ((PersistentWriterArgs*)arg)->mLoaderData;
    13151317
     
    13411343
    13421344    // cid,contract_id,type,class_name,inproc_server
    1343     PR_fprintf(fd,
    1344                "%s,%s,%s,%s,%s\n",
    1345                cidString,
    1346                (contractID ? contractID : ""),
    1347                (loaderName ? loaderName : ""),
    1348                (className  ? className  : ""),
    1349                (location   ? location   : ""));
     1345    RTStrmPrintf(fd,
     1346                 "%s,%s,%s,%s,%s\n",
     1347                 cidString,
     1348                 (contractID ? contractID : ""),
     1349                 (loaderName ? loaderName : ""),
     1350                 (className  ? className  : ""),
     1351                 (location   ? location   : ""));
    13501352
    13511353    if (contractID)
     
    13601362AutoRegEntryWriter(nsHashKey *aKey, void *aData, void* aClosure)
    13611363{
    1362     PRFileDesc* fd = (PRFileDesc*) aClosure;
     1364    PRTSTREAM fd = (PRTSTREAM) aClosure;
    13631365    AutoRegEntry* entry = (AutoRegEntry*) aData;
    13641366
     
    13691371    else
    13701372        fmt = "%s,%lld\n";
    1371     PR_fprintf(fd, fmt, entry->GetName().get(), entry->GetDate(), extraData);
     1373    RTStrmPrintf(fd, fmt, entry->GetName().get(), entry->GetDate(), extraData);
    13721374
    13731375    return PR_TRUE;
     
    13951397    localFile->SetNativeLeafName(leafName);
    13961398
    1397     PRFileDesc* fd = nsnull;
    1398     nsresult rv = localFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0600, &fd);
     1399    nsCAutoString pathName;
     1400    nsresult rv = localFile->GetNativePath(pathName);
    13991401    if (NS_FAILED(rv))
    14001402        return rv;
    14011403
    1402     if (PR_fprintf(fd, "Generated File. Do not edit.\n") == (PRUint32) -1) {
     1404    RTFILE hFile      = NIL_RTFILE;
     1405    PRTSTREAM pStream = NULL;
     1406    int vrc = RTFileOpen(&hFile, pathName.get(),
     1407                         RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_TRUNCATE | RTFILE_O_DENY_NONE
     1408                         | (0600 << RTFILE_O_CREATE_MODE_SHIFT));
     1409    if (RT_SUCCESS(vrc))
     1410    {
     1411        vrc = RTStrmOpenFileHandle(hFile, "at", 0 /*fFlags*/, &pStream);
     1412        if (RT_FAILURE(vrc))
     1413        {
     1414            RTFileClose(hFile);
     1415            return NS_ERROR_UNEXPECTED;
     1416        }
     1417    }
     1418    else
     1419        return NS_ERROR_UNEXPECTED;
     1420
     1421    if (RTStrmPrintf(pStream, "Generated File. Do not edit.\n") == -1) {
    14031422        rv = NS_ERROR_UNEXPECTED;
    14041423        goto out;
    14051424    }
    14061425
    1407     if (PR_fprintf(fd, "\n[HEADER]\nVersion,%d,%d\n",
     1426    if (RTStrmPrintf(pStream, "\n[HEADER]\nVersion,%d,%d\n",
    14081427                   PERSISTENT_REGISTRY_VERSION_MAJOR,
    1409                    PERSISTENT_REGISTRY_VERSION_MINOR) == (PRUint32) -1) {
     1428                   PERSISTENT_REGISTRY_VERSION_MINOR) == -1) {
    14101429        rv = NS_ERROR_UNEXPECTED;
    14111430        goto out;
    14121431    }
    14131432
    1414     if (PR_fprintf(fd, "\n[COMPONENTS]\n") == (PRUint32) -1) {
     1433    if (RTStrmPrintf(pStream, "\n[COMPONENTS]\n") == -1) {
    14151434        rv = NS_ERROR_UNEXPECTED;
    14161435        goto out;
    14171436    }
    14181437
    1419     mAutoRegEntries.Enumerate(AutoRegEntryWriter, (void*)fd);
     1438    mAutoRegEntries.Enumerate(AutoRegEntryWriter, (void*)pStream);
    14201439
    14211440    PersistentWriterArgs args;
    1422     args.mFD = fd;
     1441    args.mFD = pStream;
    14231442    args.mLoaderData = mLoaderData;
    14241443
    1425     if (PR_fprintf(fd, "\n[CLASSIDS]\n") == (PRUint32) -1) {
     1444    if (RTStrmPrintf(pStream, "\n[CLASSIDS]\n") == -1) {
    14261445        rv = NS_ERROR_UNEXPECTED;
    14271446        goto out;
     
    14311450    PL_DHashTableEnumerate(&mFactories, ClassIDWriter, (void*)&args);
    14321451
    1433     if (PR_fprintf(fd, "\n[CONTRACTIDS]\n") == (PRUint32) -1) {
     1452    if (RTStrmPrintf(pStream, "\n[CONTRACTIDS]\n") == -1) {
    14341453        rv = NS_ERROR_UNEXPECTED;
    14351454        goto out;
     
    14391458    PL_DHashTableEnumerate(&mContractIDs, ContractIDWriter, (void*)&args);
    14401459
    1441     if (PR_fprintf(fd, "\n[CATEGORIES]\n") == (PRUint32) -1) {
     1460    if (RTStrmPrintf(pStream, "\n[CATEGORIES]\n") == -1) {
    14421461        rv = NS_ERROR_UNEXPECTED;
    14431462        goto out;
     
    14491468        rv = NS_ERROR_UNEXPECTED;
    14501469    } else {
    1451         rv = mCategoryManager->WriteCategoryManagerToRegistry(fd);
     1470        rv = mCategoryManager->WriteCategoryManagerToRegistry(pStream);
    14521471    }
    14531472
    14541473out:
    1455     if (fd)
    1456         PR_Close(fd);
     1474    if (pStream)
     1475        RTStrmClose(pStream);
    14571476
    14581477    // don't create the file is there was a problem????
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette