RTGzip.cpp revision 53ef3f0380481e398f8edd344fc07b4e5763ba65
/* $Id$ */
/** @file
* IPRT - GZIP Utility.
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/buildconfig.h>
#include <iprt/initterm.h>
static bool isStdHandleATty(int fd)
{
/** @todo IPRT is missing this */
return false;
}
/**
* Pushes data from the input to the output I/O streams.
*
* @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE.
* @param hVfsIn The input I/O stream.
* @param hVfsOut The input I/O stream.
*/
{
for (;;)
{
if (RT_FAILURE(rc))
return RTEXITCODE_SUCCESS;
if (RT_FAILURE(rc))
}
}
{
}
static RTEXITCODE gzipCompressFile(const char *pszFile, bool fStdOut, bool fForce, PRTVFSIOSTREAM phVfsStdOut)
{
}
{
if (RT_SUCCESS(rc))
{
}
else
return rcExit;
}
/**
* Handles a file on the command line.
*
* @returns exit code.
* @param pszFile The file to handle.
* @param fStdOut Whether to output to standard output or not.
* @param fForce Whether to output to or input from terminals.
* @param phVfsStdOut Pointer to the standard out handle.
*/
static RTEXITCODE gzipDecompressFile(const char *pszFile, bool fStdOut, bool fForce, PRTVFSIOSTREAM phVfsStdOut)
{
/*
* Open the specified input file.
*/
const char *pszError;
int rc = RTVfsChainOpenIoStream(pszFile, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsIn, &pszError);
if (RT_FAILURE(rc))
{
return RTMsgErrorExit(RTEXITCODE_FAILURE,
"RTVfsChainOpenIoStream failed with rc=%Rrc:\n"
" '%s'\n",
" %*s^\n",
return RTMsgErrorExit(RTEXITCODE_FAILURE,
"RTVfsChainOpenIoStream failed with rc=%Rrc: '%s'",
}
/*
* Output the output file.
*/
char szFinal[RTPATH_MAX];
if (fStdOut)
{
if (*phVfsStdOut == NIL_RTVFSIOSTREAM)
{
if (RT_FAILURE(rc))
}
hVfsOut = *phVfsStdOut;
szFinal[0] = '\0';
}
else
{
/** @todo remove the extension? Or are we supposed
* to get the org name from the gzip stream? */
}
/*
* Do the decompressing, then flush and close the output stream (unless
* it is stdout).
*/
if (RT_FAILURE(rc))
/*
* Remove the input file, if that's the desire of the caller, or
* remove the output file on decompression failure.
*/
if (!fStdOut)
{
if (rcExit == RTEXITCODE_SUCCESS)
{
if (RT_FAILURE(rc))
}
else
{
/* should we do this? */
if (RT_FAILURE(rc))
}
}
return rcExit;
}
{
}
{
}
{
if (RT_FAILURE(rc))
return RTMsgInitFailure(rc);
/*
* Parse the command line.
*/
static const RTGETOPTDEF s_aOptions[] =
{
};
bool fAscii = false;
bool fStdOut = false;
bool fDecompress = false;
bool fForce = false;
bool fList = false;
bool fName = true;
bool fQuiet = false;
bool fRecursive = false;
const char *pszSuff = ".gz";
bool fTest = false;
unsigned uLevel = 6;
unsigned cProcessed = 0;
for (;;)
{
switch (rc)
{
case 0:
{
/*
* If we've processed any files we're done. Otherwise take
* input from stdin and write the output to stdout.
*/
if (cProcessed > 0)
return rcExit;
#if 0
true /*fLeaveOpen*/,
&hVfsOut);
return RTMsgErrorExit(RTEXITCODE_SYNTAX,
"Yeah, right. I'm not %s any compressed data %s the terminal without --force.\n",
#else
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "reading from standard input has not yet been implemented");
#endif
return rcExit;
}
case VINF_GETOPT_NOT_OPTION:
{
if (fList)
else if (fTest)
else if (fDecompress)
else
if (rcExit2 != RTEXITCODE_SUCCESS)
cProcessed++;
break;
}
case 'a': fAscii = true; break;
case 'c': fStdOut = true; break;
case 'd': fDecompress = true; break;
case 'f': fForce = true; break;
case 'l': fList = true; break;
case 'n': fName = false; break;
case 'N': fName = true; break;
case 'q': fQuiet = true; break;
case 'r': fRecursive = true; break;
case 't': fTest = true; break;
case 'v': fQuiet = false; break;
case 'h':
RTPrintf("Usage: to be written\nOption dump:\n");
for (unsigned i = 0; i < RT_ELEMENTS(s_aOptions); i++)
return RTEXITCODE_SUCCESS;
case 'V':
return RTEXITCODE_SUCCESS;
default:
}
}
}