VBoxBs2Linker.cpp revision cf22150eaeeb72431bf1cf65c309a431454fb22b
/* $Id$ */
/** @file
* VirtualBox Validation Kit - Boot Sector 2 "linker".
*/
/*
* Copyright (C) 2006-2014 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 <stdio.h>
#include <string.h>
#include <stdlib.h>
{
unsigned cInputs = 0;
/*
* Scan the arguments.
*/
for (int i = 1; i < argc; i++)
{
if (argv[i][0] == '-')
{
if (*pszOpt == '-')
{
/* Convert long options to short ones. */
pszOpt--;
pszOpt = "o";
pszOpt = "V";
pszOpt = "h";
else
{
return 2;
}
}
/* Process the list of short options. */
while (*pszOpt)
{
switch (*pszOpt++)
{
case 'o':
{
if (*pszValue == '=')
pszValue++;
else if (!*pszValue)
{
if (i + 1 >= argc)
{
return 12;
}
}
if (pszOutput)
{
return 2;
}
pszOpt = "";
break;
}
case 'V':
return 0;
case '?':
case 'h':
printf("usage: %s [options] -o <output> <input1> [input2 ... [inputN]]\n",
argv[0]);
return 0;
}
}
}
else
}
if (!pszOutput)
{
return 2;
}
if (cInputs == 0)
{
return 2;
}
/*
* Do the job.
*/
/* Open the output file. */
#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
#else
#endif
if (!pOutput)
{
return 1;
}
/* Copy the input files to the output file, with sector padding applied. */
int rcExit = 0;
{
#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
#else
#endif
if (pInput)
{
for (;;)
{
/* Read a block from the input file. */
break;
/* Padd the end of the file if necessary. */
{
(unsigned)cbRead);
rcExit = 1;
break;
}
if ((cbRead & 0x1ff) != 0)
{
}
/* Write the block to the output file. */
else
{
rcExit = 1;
break;
}
}
{
rcExit = 1;
}
}
else
{
rcExit = 1;
}
}
/* Finally, close the output file (can fail because of buffered data). */
{
rcExit = 1;
}
return rcExit;
}