VirtualBox

Changeset 33973 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Nov 11, 2010 11:10:10 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67635
Message:

vfs: the gunzip stream works, except for some double frees somewhere.

Location:
trunk/src/VBox/Runtime
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r33945 r33973  
    371371        common/vfs/vfsbase.cpp \
    372372        common/vfs/vfschain.cpp \
     373        common/vfs/vfsmisc.cpp \
    373374        common/vfs/vfsstdfile.cpp \
    374375        common/zip/zipgzip.cpp \
     
    479480        nt/RTErrConvertFromNtStatus.cpp \
    480481        r3/posix/env-posix.cpp \
     482        r3/win/RTHandleGetStandard-win.cpp \
    481483        r3/win/RTSystemQueryOSInfo-win.cpp \
    482484        r3/win/RTSystemQueryDmiString-win.cpp \
     
    537539        r3/linux/RTSystemQueryDmiString-linux.cpp \
    538540        r3/posix/RTFileQueryFsSizes-posix.cpp \
     541        r3/posix/RTHandleGetStandard-posix.cpp \
    539542        r3/posix/RTMemProtect-posix.cpp \
    540543        r3/posix/RTPathUserHome-posix.cpp \
     
    622625        r3/os2/time-os2.cpp \
    623626        r3/posix/RTFileQueryFsSizes-posix.cpp \
     627        r3/posix/RTHandleGetStandard-posix.cpp \
    624628        r3/posix/RTMemProtect-posix.cpp \
    625629        r3/posix/RTPathUserHome-posix.cpp \
     
    671675        r3/darwin/time-darwin.cpp \
    672676        r3/posix/RTFileQueryFsSizes-posix.cpp \
     677        r3/posix/RTHandleGetStandard-posix.cpp \
    673678        r3/posix/RTMemProtect-posix.cpp \
    674679        r3/posix/RTPathUserHome-posix.cpp \
     
    720725        r3/freebsd/rtProcInitExePath-freebsd.cpp \
    721726        r3/posix/RTFileQueryFsSizes-posix.cpp \
     727        r3/posix/RTHandleGetStandard-posix.cpp \
    722728        r3/posix/RTMemProtect-posix.cpp \
    723729        r3/posix/RTPathUserHome-posix.cpp \
     
    769775        generic/RTThreadGetNativeState-generic.cpp \
    770776        r3/posix/RTFileQueryFsSizes-posix.cpp \
     777        r3/posix/RTHandleGetStandard-posix.cpp \
    771778        r3/posix/RTMemProtect-posix.cpp \
    772779        r3/posix/RTPathUserHome-posix.cpp \
  • trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp

    r33948 r33973  
    10841084
    10851085
    1086 RTDECL(int) RTVfsNewIoStream(PCRTVFSFSSTREAMOPS pFsStreamOps, size_t cbInstance, RTVFS hVfs, RTSEMRW hSemRW,
     1086RTDECL(int) RTVfsNewFsStream(PCRTVFSFSSTREAMOPS pFsStreamOps, size_t cbInstance, RTVFS hVfs, RTSEMRW hSemRW,
    10871087                             PRTVFSFSSTREAM phVfsFss, void **ppvInstance)
    10881088{
     
    12311231
    12321232    RTVFSINTERNAL *pVfs = NULL;
    1233     if (hVfs == NIL_RTVFS)
     1233    if (hVfs != NIL_RTVFS)
    12341234    {
    12351235        pVfs = hVfs;
     
    12521252    pThis->Base.uMagic  = RTVFSOBJ_MAGIC;
    12531253    pThis->Base.pvThis  = (char *)pThis + RT_ALIGN_Z(sizeof(*pThis), RTVFS_INST_ALIGNMENT);
     1254    pThis->Base.pOps    = &pIoStreamOps->Obj;
    12541255    pThis->Base.hSemRW  = hSemRW != NIL_RTSEMRW ? hSemRW : pVfs ? pVfs->Base.hSemRW : NIL_RTSEMRW;
    12551256    pThis->Base.hVfs    = hVfs;
     
    12991300
    13001301
    1301 RTDECL(int)         RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
     1302RTDECL(int) RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
    13021303{
    13031304    RTVFSIOSTREAMINTERNAL *pThis = hVfsIos;
     
    13081309
    13091310
    1310 RTDECL(int)         RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, size_t *pcbRead)
     1311RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead)
    13111312{
    13121313    AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER);
     
    13161317    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    13171318    AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE);
     1319    AssertReturn(fBlocking || pcbRead, VERR_INVALID_PARAMETER);
    13181320
    13191321    RTSGSEG Seg = { pvBuf, cbToRead };
     
    13221324
    13231325    rtVfsObjWriteLock(&pThis->Base);
    1324     int rc = pThis->pOps->pfnRead(pThis->Base.pvThis, -1 /*off*/, &SgBuf, pcbRead == NULL /*fBlocking*/, pcbRead);
     1326    int rc = pThis->pOps->pfnRead(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbRead);
    13251327    rtVfsObjWriteUnlock(&pThis->Base);
    13261328    return rc;
     
    13281330
    13291331
    1330 RTDECL(int)         RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten)
     1332RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten)
    13311333{
    13321334    AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER);
     
    13361338    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    13371339    AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE);
     1340    AssertReturn(fBlocking || pcbWritten, VERR_INVALID_PARAMETER);
    13381341
    13391342    RTSGSEG Seg = { (void *)pvBuf, cbToWrite };
     
    13421345
    13431346    rtVfsObjWriteLock(&pThis->Base);
    1344     int rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, &SgBuf, pcbWritten == NULL /*fBlocking*/, pcbWritten);
     1347    int rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbWritten);
    13451348    rtVfsObjWriteUnlock(&pThis->Base);
    13461349    return rc;
     
    13481351
    13491352
    1350 RTDECL(int)         RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     1353RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    13511354{
    13521355    AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER);
     
    13661369
    13671370
    1368 RTDECL(int)         RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     1371RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    13691372{
    13701373    AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER);
     
    13841387
    13851388
    1386 RTDECL(int)         RTVfsIoStrmFlush(RTVFSIOSTREAM hVfsIos)
     1389RTDECL(int) RTVfsIoStrmFlush(RTVFSIOSTREAM hVfsIos)
    13871390{
    13881391    RTVFSIOSTREAMINTERNAL *pThis = hVfsIos;
     
    13971400
    13981401
    1399 RTDECL(RTFOFF)      RTVfsIoStrmPoll(RTVFSIOSTREAM hVfsIos, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
    1400                                     uint32_t *pfRetEvents)
     1402RTDECL(RTFOFF) RTVfsIoStrmPoll(RTVFSIOSTREAM hVfsIos, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
     1403                               uint32_t *pfRetEvents)
    14011404{
    14021405    RTVFSIOSTREAMINTERNAL *pThis = hVfsIos;
     
    14111414
    14121415
    1413 RTDECL(RTFOFF)      RTVfsIoStrmTell(RTVFSIOSTREAM hVfsIos)
     1416RTDECL(RTFOFF) RTVfsIoStrmTell(RTVFSIOSTREAM hVfsIos)
    14141417{
    14151418    RTVFSIOSTREAMINTERNAL *pThis = hVfsIos;
     
    14271430
    14281431
    1429 RTDECL(int)         RTVfsIoStrmSkip(RTVFSIOSTREAM hVfsIos, RTFOFF cb)
     1432RTDECL(int) RTVfsIoStrmSkip(RTVFSIOSTREAM hVfsIos, RTFOFF cb)
    14301433{
    14311434    RTVFSIOSTREAMINTERNAL *pThis = hVfsIos;
     
    14511454                size_t cbToRead = RT_MIN(cb, _64K);
    14521455                rtVfsObjWriteLock(&pThis->Base);
    1453                 rc = RTVfsIoStrmRead(hVfsIos, pvBuf, cbToRead, NULL);
     1456                rc = RTVfsIoStrmRead(hVfsIos, pvBuf, cbToRead, true /*fBlocking*/, NULL);
    14541457                rtVfsObjWriteUnlock(&pThis->Base);
    14551458                if (RT_FAILURE(rc))
     
    14671470
    14681471
    1469 RTDECL(int)         RTVfsIoStrmZeroFill(RTVFSIOSTREAM hVfsIos, RTFOFF cb)
     1472RTDECL(int) RTVfsIoStrmZeroFill(RTVFSIOSTREAM hVfsIos, RTFOFF cb)
    14701473{
    14711474    RTVFSIOSTREAMINTERNAL *pThis = hVfsIos;
     
    14901493                size_t cbToWrite = RT_MIN(cb, _64K);
    14911494                rtVfsObjWriteLock(&pThis->Base);
    1492                 rc = RTVfsIoStrmWrite(hVfsIos, pvBuf, cbToWrite, NULL);
     1495                rc = RTVfsIoStrmWrite(hVfsIos, pvBuf, cbToWrite, true /*fBlocking*/, NULL);
    14931496                rtVfsObjWriteUnlock(&pThis->Base);
    14941497                if (RT_FAILURE(rc))
     
    15341537
    15351538    RTVFSINTERNAL *pVfs = NULL;
    1536     if (hVfs == NIL_RTVFS)
     1539    if (hVfs != NIL_RTVFS)
    15371540    {
    15381541        pVfs = hVfs;
     
    15571560    pThis->Stream.pOps          = &pFileOps->Stream;
    15581561    pThis->Stream.Base.pvThis   = (char *)pThis + RT_ALIGN_Z(sizeof(*pThis), RTVFS_INST_ALIGNMENT);
     1562    pThis->Stream.Base.pOps     = &pFileOps->Stream.Obj;
    15591563    pThis->Stream.Base.hSemRW   = pVfs ? pVfs->Base.hSemRW : NIL_RTSEMRW;
    15601564    pThis->Stream.Base.hVfs     = hVfs;
  • trunk/src/VBox/Runtime/common/vfs/vfschain.cpp

    r33950 r33973  
    431431        }
    432432
    433 
    434433        /*
    435434         * Ok, there should be an element here so add one to the return struct.
     
    440439        pElement->enmAction = enmAction;
    441440
    442         /* First comes a type which is followed by a '('. */
     441        /*
     442         * First up is the VFS object type followed by a parentheses.
     443         */
    443444        if (strncmp(pszSrc, "base", cch = 4) == 0)
    444445            pElement->enmTypeOut = RTVFSOBJTYPE_BASE;
     
    495496        }
    496497
    497         /* Must end with a right parantheses. */
     498        /* Must end with a right parentheses. */
    498499        if (*pszSrc != ')')
    499500        {
     
    657658
    658659
     660RTDECL(bool) RTVfsChainIsSpec(const char *pszSpec)
     661{
     662    return pszSpec
     663        && strcmp(pszSpec, RTVFSCHAIN_SPEC_PREFIX) == 0;
     664}
     665
  • trunk/src/VBox/Runtime/common/vfs/vfsstdfile.cpp

    r33903 r33973  
    446446}
    447447
     448
     449RTDECL(int)         RTVfsIoStrmFromRTFile(RTFILE hFile, uint32_t fOpen, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos)
     450{
     451    RTVFSFILE hVfsFile;
     452    int rc = RTVfsFileFromRTFile(hFile, fOpen, fLeaveOpen, &hVfsFile);
     453    if (RT_SUCCESS(rc))
     454        *phVfsIos = RTVfsFileToIoStream(hVfsFile);
     455    return rc;
     456}
     457
     458
     459
  • trunk/src/VBox/Runtime/common/zip/zipgzip.cpp

    r33945 r33973  
    3030*******************************************************************************/
    3131#include "internal/iprt.h"
    32 #include <iprt/vfslowlevel.h>
     32#include <iprt/zip.h>
    3333
    3434#include <iprt/assert.h>
     
    3737#include <iprt/poll.h>
    3838#include <iprt/string.h>
     39#include <iprt/vfslowlevel.h>
     40
    3941#include <zlib.h>
    4042
     
    477479    AssertPtrReturn(phVfsIosOut, VERR_INVALID_POINTER);
    478480
     481    uint32_t cRefs = RTVfsIoStrmRetain(hVfsIosIn);
     482    AssertReturn(cRefs != UINT32_MAX, VERR_INVALID_HANDLE);
     483
    479484    /*
    480485     * Create the decompression I/O stream.
     
    507512             */
    508513            size_t cbRead = 0;
    509             rc = RTVfsIoStrmRead(pThis->hVfsIos, pThis->abBuffer, sizeof(RTZIPGZIPHDR), NULL /*pcbRead*/);
     514            rc = RTVfsIoStrmRead(pThis->hVfsIos, pThis->abBuffer, sizeof(RTZIPGZIPHDR), true /*fBlocking*/, NULL /*pcbRead*/);
    510515            if (RT_SUCCESS(rc))
    511516            {
     
    539544        }
    540545        else
    541             rc = rtZipGzipConvertErrFromZlib(pThis, rc);
     546            rc = rtZipGzipConvertErrFromZlib(pThis, rc); /** @todo cleaning up in this situation is going to go wrong. */
     547        RTVfsIoStrmRelease(hVfsIos);
    542548    }
     549    else
     550        RTVfsIoStrmRelease(hVfsIosIn);
    543551    return rc;
    544552}
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r33678 r33973  
    572572RTLdrFlt_SOURCES = RTLdrFlt.cpp
    573573
     574# RTGzip - our gzip clone (for testing the gzip/gunzip streaming code)
     575PROGRAMS += RTGzip
     576RTGzip_TEMPLATE = VBOXR3TSTEXE
     577RTGzip_SOURCES = RTGzip.cpp
     578
    574579
    575580
  • trunk/src/VBox/Runtime/testcase/RTGzip.cpp

    r33911 r33973  
    3131#include <iprt/zip.h>
    3232
     33#include <iprt/buildconfig.h>
     34#include <iprt/file.h>
    3335#include <iprt/getopt.h>
    34 #include <iprt/init.h>
     36#include <iprt/initterm.h>
    3537#include <iprt/message.h>
     38#include <iprt/param.h>
     39#include <iprt/stream.h>
    3640#include <iprt/string.h>
    3741#include <iprt/vfs.h>
     42#include <iprt/zip.h>
    3843
    3944
     
    4348    return false;
    4449}
     50
     51
     52/**
     53 * Pushes data from the input to the output I/O streams.
     54 *
     55 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE.
     56 * @param   hVfsIn              The input I/O stream.
     57 * @param   hVfsOut             The input I/O stream.
     58 */
     59static RTEXITCODE gzipPush(RTVFSIOSTREAM hVfsIn, RTVFSIOSTREAM hVfsOut)
     60{
     61    for (;;)
     62    {
     63        uint8_t abBuf[_64K];
     64        size_t  cbRead;
     65        int rc = RTVfsIoStrmRead(hVfsIn, abBuf, sizeof(abBuf), true /*fBlocking*/, &cbRead);
     66        if (RT_FAILURE(rc))
     67            return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTVfsIoStrmRead failed: %Rrc", rc);
     68        if (rc == VINF_EOF && cbRead == 0)
     69            return RTEXITCODE_SUCCESS;
     70
     71        rc = RTVfsIoStrmWrite(hVfsOut, abBuf, cbRead, true /*fBlocking*/, NULL /*cbWritten*/);
     72        if (RT_FAILURE(rc))
     73            return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTVfsIoStrmWrite failed: %Rrc", rc);
     74    }
     75}
     76
     77static RTEXITCODE gzipCompress(RTVFSIOSTREAM hVfsIn, RTVFSIOSTREAM hVfsOut)
     78{
     79    return RTMsgErrorExit(RTEXITCODE_FAILURE, "Compression is not yet implemented, sorry.");
     80}
     81
     82
     83static RTEXITCODE gzipCompressFile(const char *pszFile, bool fStdOut, bool fForce, PRTVFSIOSTREAM phVfsStdOut)
     84{
     85    return RTMsgErrorExit(RTEXITCODE_FAILURE, "Compression is not yet implemented, sorry.");
     86}
     87
     88
     89static RTEXITCODE gzipDecompress(RTVFSIOSTREAM hVfsIn, RTVFSIOSTREAM hVfsOut)
     90{
     91    RTEXITCODE      rcExit;
     92    RTVFSIOSTREAM   hVfsGunzip;
     93    int rc = RTZipGzipDecompressIoStream(hVfsIn, 0 /*fFlags*/, &hVfsGunzip);
     94    if (RT_SUCCESS(rc))
     95    {
     96        rcExit = gzipPush(hVfsGunzip, hVfsOut);
     97        RTVfsIoStrmRelease(hVfsGunzip);
     98    }
     99    else
     100        rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "RTZipGzipDecompressIoStream failed: %Rrc", rc);
     101    return rcExit;
     102}
     103
     104
     105/**
     106 * Handles a file on the command line.
     107 *
     108 * @returns exit code.
     109 * @param   pszFile             The file to handle.
     110 * @param   fStdOut             Whether to output to standard output or not.
     111 * @param   fForce              Whether to output to or input from terminals.
     112 * @param   phVfsStdOut         Pointer to the standard out handle.
     113 *                              (input/output)
     114 */
     115static RTEXITCODE gzipDecompressFile(const char *pszFile, bool fStdOut, bool fForce, PRTVFSIOSTREAM phVfsStdOut)
     116{
     117    /*
     118     * Open the specified input file.
     119     */
     120    const char *pszError;
     121    RTVFSIOSTREAM hVfsIn;
     122    int rc = RTVfsChainOpenIoStream(pszFile, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsIn, &pszError);
     123    if (RT_FAILURE(rc))
     124    {
     125        if (pszError && *pszError)
     126            return RTMsgErrorExit(RTEXITCODE_FAILURE,
     127                                  "RTVfsChainOpenIoStream failed with rc=%Rrc:\n"
     128                                  "    '%s'\n",
     129                                  "     %*s^\n",
     130                                  rc, pszFile, pszError - pszFile, "");
     131        return RTMsgErrorExit(RTEXITCODE_FAILURE,
     132                              "RTVfsChainOpenIoStream failed with rc=%Rrc: '%s'",
     133                              rc, pszFile);
     134    }
     135
     136    /*
     137     * Output the output file.
     138     */
     139    RTVFSIOSTREAM hVfsOut;
     140    char szFinal[RTPATH_MAX];
     141    if (fStdOut)
     142    {
     143        if (*phVfsStdOut == NIL_RTVFSIOSTREAM)
     144        {
     145            rc = RTVfsIoStrmFromStdHandle(RTHANDLESTD_OUTPUT, 0 /*fOpen*/, true /*fLeaveOpen*/, phVfsStdOut);
     146            if (RT_FAILURE(rc))
     147                return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to set up standard out: %Rrc", rc);
     148        }
     149        hVfsOut = *phVfsStdOut;
     150        szFinal[0] = '\0';
     151    }
     152    else
     153    {
     154        rc = RTStrCopy(szFinal, sizeof(szFinal), pszFile);
     155        /** @todo remove the extension?  Or are we supposed
     156         *        to get the org name from the gzip stream? */
     157        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Decompressing to file is not implemented");
     158    }
     159
     160    /*
     161     * Do the decompressing, then flush and close the output stream (unless
     162     * it is stdout).
     163     */
     164    RTEXITCODE rcExit = gzipDecompress(hVfsIn, hVfsOut);
     165    RTVfsIoStrmRelease(hVfsIn);
     166    rc = RTVfsIoStrmFlush(hVfsOut);
     167    if (RT_FAILURE(rc))
     168        rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to flush the output file: %Rrc", rc);
     169    RTVfsIoStrmRelease(hVfsOut);
     170
     171    /*
     172     * Remove the input file, if that's the desire of the caller, or
     173     * remove the output file on decompression failure.
     174     */
     175    if (!fStdOut)
     176    {
     177        if (rcExit == RTEXITCODE_SUCCESS)
     178        {
     179            rc = RTFileDelete(pszFile);
     180            if (RT_FAILURE(rc))
     181                rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "RTFileDelete failed with %rc: '%s'", rc, pszFile);
     182        }
     183        else
     184        {
     185            /* should we do this? */
     186            rc = RTFileDelete(szFinal);
     187            if (RT_FAILURE(rc))
     188                RTMsgError("RTFileDelete failed with %rc: '%s'", rc, pszFile);
     189        }
     190    }
     191
     192    return rcExit;
     193}
     194
     195
     196static RTEXITCODE gzipTestFile(const char *pszFile, bool fForce)
     197{
     198    return RTMsgErrorExit(RTEXITCODE_FAILURE, "Testiong has not been implemented");
     199}
     200
     201
     202static RTEXITCODE gzipListFile(const char *pszFile, bool fForce)
     203{
     204    return RTMsgErrorExit(RTEXITCODE_FAILURE, "Listing has not been implemented");
     205}
     206
    45207
    46208int main(int argc, char **argv)
     
    53215     * Parse the command line.
    54216     */
    55     static const RTGETOPTDEF s_aOptions[]
     217    static const RTGETOPTDEF s_aOptions[] =
    56218    {
    57219        { "--ascii",        'a', RTGETOPT_REQ_NOTHING },
     
    96258    RTEXITCODE  rcExit      = RTEXITCODE_SUCCESS;
    97259    unsigned    cProcessed  = 0;
    98 
    99     RTGETOPTSTAT GetState;
    100     int rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1,
    101                           RTGETOPTINIT_FLAGS_OPTS_FIRST);
     260    RTVFSIOSTREAM hVfsStdOut= NIL_RTVFSIOSTREAM;
     261
     262    RTGETOPTSTATE GetState;
     263    rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1,
     264                      RTGETOPTINIT_FLAGS_OPTS_FIRST);
    102265    for (;;)
    103266    {
     
    112275                 * input from stdin and write the output to stdout.
    113276                 */
    114                 if (cProcessed)
     277                if (cProcessed > 0)
    115278                    return rcExit;
    116 
    117                 RTVFSIOSTREAM hVfsIn;
    118                 RTVFSIOSTREAM hVfsOut;
     279#if 0
     280                rc = RTVfsFileFromRTFile(1,
     281                                         RTFILE_O_WRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE,
     282                                         true /*fLeaveOpen*/,
     283                                         &hVfsOut);
     284
    119285
    120286                if (!fForce && isStdHandleATty(fDecompress ? 0 : 1))
     
    123289                                          fDecompress ? "reading" : "writing",
    124290                                          fDecompress ? "from"    : "to");
     291#else
     292                rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "reading from standard input has not yet been implemented");
     293#endif
    125294                return rcExit;
    126295            }
     
    128297            case VINF_GETOPT_NOT_OPTION:
    129298            {
    130                 RTVFSIOSTREAM hVfsSrc;
    131                 rc = RTVfsOpenIoStreamFromSpec(ValueUnion.psz, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsSrc);
     299                if (!*pszSuff && !fStdOut)
     300                    return RTMsgErrorExit(RTEXITCODE_SYNTAX, "The --suffix option specified an empty string");
     301                if (!fStdOut && RTVfsChainIsSpec(ValueUnion.psz))
     302                    return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Must use standard out with VFS chain specifications");
     303
     304                RTEXITCODE rcExit2;
     305                if (fList)
     306                    rcExit2 = gzipListFile(ValueUnion.psz, fForce);
     307                else if (fTest)
     308                    rcExit2 = gzipTestFile(ValueUnion.psz, fForce);
     309                else if (fDecompress)
     310                    rcExit2 = gzipDecompressFile(ValueUnion.psz, fStdOut, fForce, &hVfsStdOut);
     311                else
     312                    rcExit2 = gzipCompressFile(ValueUnion.psz, fStdOut, fForce, &hVfsStdOut);
     313                if (rcExit2 != RTEXITCODE_SUCCESS)
     314                    rcExit = rcExit2;
    132315
    133316                cProcessed++;
    134                 if (fDecompress)
    135                 {
    136                 }
    137                 else
    138                 {
    139                     if (!*pszSuff && !fStdOut)
    140                         return
    141                     {
    142                     }
    143                 }
    144317                break;
    145318            }
     
    167340            case '9':   uLevel      = 9;     break;
    168341
     342            case 'h':
     343                RTPrintf("Usage: to be written\nOption dump:\n");
     344                for (unsigned i = 0; i < RT_ELEMENTS(s_aOptions); i++)
     345                    RTPrintf(" -%c,%s\n", s_aOptions[i].iShort, s_aOptions[i].pszLong);
     346                return RTEXITCODE_SUCCESS;
     347
     348            case 'V':
     349                RTPrintf("%sr%d\n", RTBldCfgVersion(), RTBldCfgRevision());
     350                return RTEXITCODE_SUCCESS;
     351
    169352            default:
    170                 return RTGetOptPrintError(ch, &ValueUnion);
     353                return RTGetOptPrintError(rc, &ValueUnion);
    171354        }
    172355    }
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