VirtualBox

Changeset 30079 in vbox for trunk


Ignore:
Timestamp:
Jun 7, 2010 2:57:44 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
62451
Message:

IPRT: Use PFNRTPROGRESS.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/manifest.h

    r29901 r30079  
    5151typedef RTMANIFESTTEST* PRTMANIFESTTEST;
    5252
    53 /**
    54  * Manifest progress callback.
    55  *
    56  * @returns IPRT status code.
    57  *
    58  * @param   uPercent    The progress completion percentage.
    59  * @param   pvUser      The user defined parameter.
    60  */
    61 typedef DECLCALLBACK(int) FNRTMANIFESTPROGRESS(unsigned uPercent, void *pvUser);
    62 /** Pointer to a manifest progress callback. */
    63 typedef FNRTMANIFESTPROGRESS *PFNRTMANIFESTPROGRESS;
    6453
    6554/**
     
    9786 * @param   pvUser               user defined pointer for the callback
    9887 */
    99 RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, size_t *piFailed, PFNRTMANIFESTPROGRESS pfnProgressCallback, void *pvUser);
     88RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, size_t *piFailed,
     89                                    PFNRTPROGRESS pfnProgressCallback, void *pvUser);
    10090
    10191/**
     
    112102 * @param   pvUser               user defined pointer for the callback
    113103 */
    114 RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, PFNRTMANIFESTPROGRESS pfnProgressCallback, void *pvUser);
     104RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles,
     105                                   PFNRTPROGRESS pfnProgressCallback, void *pvUser);
    115106
    116107/** @} */
     
    118109RT_C_DECLS_END
    119110
    120 #endif /* ___iprt_manifest_h */
     111#endif
    121112
  • trunk/include/iprt/sha.h

    r29901 r30079  
    3535 * @{
    3636 */
    37 
    38 /**
    39  * SHA progress callback.
    40  *
    41  * @returns IPRT status code.
    42  *
    43  * @param   uPercent    The progress completion percentage.
    44  * @param   pvUser      The user defined parameter.
    45  */
    46 typedef DECLCALLBACK(int) FNRTSHAPROGRESS(unsigned uPercent, void *pvUser);
    47 /** Pointer to a SHA progress callback. */
    48 typedef FNRTSHAPROGRESS *PFNRTSHAPROGRESS;
    4937
    5038/** The size of a SHA-1 hash. */
     
    135123 * @param   pvUser                user defined pointer for the callback
    136124 */
    137 RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest, PFNRTSHAPROGRESS pfnProgressCallback, void *pvUser);
     125RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest, FNRTPROGRESS pfnProgressCallback, void *pvUser);
    138126
    139127
  • trunk/src/VBox/Runtime/common/checksum/RTSha1Digest.cpp

    r29901 r30079  
    55
    66/*
    7  * Copyright (C) 2009 Oracle Corporation
     7 * Copyright (C) 2009-2010 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232#include <iprt/sha.h>
    3333
     34#include <iprt/alloca.h>
    3435#include <iprt/assert.h>
    3536#include <iprt/mem.h>
     
    3940#include <openssl/sha.h>
    4041
    41 RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest, PFNRTSHAPROGRESS pfnProgressCallback, void *pvUser)
     42
     43RTR3DECL(int) RTSha1Digest(const char *pszFile, char **ppszDigest, FNRTPROGRESS pfnProgressCallback, void *pvUser)
    4244{
    4345    /* Validate input */
     
    4749
    4850    *ppszDigest = NULL;
    49     int rc = VINF_SUCCESS;
    5051
    51     /* Initialize OpenSSL */
     52    /* Initialize OpenSSL. */
    5253    SHA_CTX ctx;
    5354    if (!SHA1_Init(&ctx))
    5455        return VERR_INTERNAL_ERROR;
    5556
     57    /* Open the file to calculate a SHA1 sum of */
     58    RTFILE hFile;
     59    int rc = RTFileOpen(&hFile, pszFile, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
     60    if (RT_FAILURE(rc))
     61        return rc;
     62
    5663    /* Fetch the file size. Only needed if there is a progress callback. */
    57     float multi = 0;
     64    double rdMulti = 0;
    5865    if (pfnProgressCallback)
    5966    {
    6067        uint64_t cbFile;
    61         rc = RTFileQuerySize(pszFile, &cbFile);
     68        rc = RTFileGetSize(hFile, &cbFile);
    6269        if (RT_FAILURE(rc))
     70        {
     71            RTFileClose(hFile);
    6372            return rc;
    64         multi = 100.0 / cbFile;
     73        }
     74        rdMulti = 100.0 / cbFile;
    6575    }
    6676
    67     /* Open the file to calculate a SHA1 sum of */
    68     RTFILE file;
    69     rc = RTFileOpen(&file, pszFile, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
    70     if (RT_FAILURE(rc))
    71         return rc;
     77    /* Allocate a reasonably large buffer, fall back on a tiny one. */
     78    void  *pvBufFree;
     79    size_t cbBuf = _1M;
     80    void  *pvBuf = pvBufFree = RTMemTmpAlloc(cbBuf);
     81    if (!pvBuf)
     82    {
     83        cbBuf = 0x1000;
     84        pvBuf = alloca(cbBuf);
     85    }
    7286
    7387    /* Read that file in blocks */
    74     void *pvBuf = RTMemTmpAlloc(_1M);
    75     if (!pvBuf)
    76     {
    77         RTFileClose(file);
    78         rc = VERR_NO_MEMORY;
    79     }
    8088    size_t cbRead;
    81     size_t cbReadFull = 0;
     89    size_t cbReadTotal = 0;
    8290    for (;;)
    8391    {
    84         cbRead = 0;
    85         rc = RTFileRead(file, pvBuf, _1M, &cbRead);
     92        rc = RTFileRead(hFile, pvBuf, cbBuf, &cbRead);
    8693        if (RT_FAILURE(rc) || !cbRead)
    8794            break;
     
    9198            break;
    9299        }
    93         cbReadFull += cbRead;
    94         /* Call progress callback if some is defined */
    95         if (   pfnProgressCallback
    96             && RT_FAILURE(pfnProgressCallback((unsigned)(cbReadFull * multi), pvUser)))
     100        cbReadTotal += cbRead;
     101
     102        /* Call the progress callback if one is defined */
     103        if (pfnProgressCallback)
    97104        {
    98             /* Cancel support */
    99             rc = VERR_CANCELLED;
    100             break;
     105            rc = pfnProgressCallback((unsigned)(cbReadTotal * rdMulti), pvUser);
     106            if (RT_FAILURE(rc))
     107                break; /* canceled */
    101108        }
    102109    }
    103     RTMemTmpFree(pvBuf);
    104     RTFileClose(file);
     110    RTMemTmpFree(pvBufFree);
     111    RTFileClose(hFile);
    105112
    106113    if (RT_FAILURE(rc))
  • trunk/src/VBox/Runtime/common/checksum/manifest.cpp

    r29904 r30079  
    6060typedef struct RTMANIFESTCALLBACKDATA
    6161{
    62     PFNRTMANIFESTPROGRESS pfnProgressCallback;
     62    PFNRTPROGRESS pfnProgressCallback;
    6363    void *pvUser;
    6464    size_t cMaxFiles;
     
    6767typedef RTMANIFESTCALLBACKDATA* PRTMANIFESTCALLBACKDATA;
    6868
     69
    6970int rtSHAProgressCallback(unsigned uPercent, void *pvUser)
    7071{
    7172    PRTMANIFESTCALLBACKDATA pData = (PRTMANIFESTCALLBACKDATA)pvUser;
    72     return pData->pfnProgressCallback((unsigned)((uPercent + (float)pData->cCurrentFile * 100.0) / (float)pData->cMaxFiles), pData->pvUser);
     73    return pData->pfnProgressCallback((unsigned)(  (uPercent + (float)pData->cCurrentFile * 100.0)
     74                                                 / (float)pData->cMaxFiles),
     75                                      pData->pvUser);
    7376}
    7477
     
    227230
    228231
    229 RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, size_t *piFailed, PFNRTMANIFESTPROGRESS pfnProgressCallback, void *pvUser)
     232RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, size_t *piFailed,
     233                                    PFNRTPROGRESS pfnProgressCallback, void *pvUser)
    230234{
    231235    /* Validate input */
     
    275279
    276280
    277 RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, PFNRTMANIFESTPROGRESS pfnProgressCallback, void *pvUser)
     281RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles,
     282                                   PFNRTPROGRESS pfnProgressCallback, void *pvUser)
    278283{
    279284    /* Validate input */
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