RTFileModeToFlags.cpp revision ea4e4a67ff01ace0be2ee49b63302d8d1dd301de
/* $Id$ */
/** @file
* IPRT - RTFileModeToFlags.
*/
/*
* Copyright (C) 2013 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 *
*******************************************************************************/
{
int rc = VINF_SUCCESS;
char chPrev = 0;
if (*pszCur == '\0')
return VERR_INVALID_PARAMETER;
while ( pszCur
&& *pszCur != '\0')
{
bool fSkip = false;
switch (*pszCur)
{
/* Opens an existing file for reading and places the
* file pointer at the end of the file. */
case 'a':
if ((uMode & RTFILE_O_ACTION_MASK) == 0)
{
}
else
break;
case 'b': /* Binary mode. */
/* Just skip as being valid. */
fSkip = true;
break;
/* Creates a file or open an existing one for
* writing only. The file pointer will be placed
* at the beginning of the file.*/
case 'c':
if ((uMode & RTFILE_O_ACTION_MASK) == 0)
{
}
else
break;
/* Opens an existing file for reading and places the
* file pointer at the beginning of the file. If the
* file does not exist an error will be returned. */
case 'r':
if ((uMode & RTFILE_O_ACTION_MASK) == 0)
{
}
else
break;
case 't': /* Text mode. */
/* Just skip as being valid. */
fSkip = true;
break;
/* Creates a new file or replaces an existing one
* for writing. Places the file pointer at the beginning.
* An existing file will be truncated to 0 bytes. */
case 'w':
if ((uMode & RTFILE_O_ACTION_MASK) == 0)
{
}
else
break;
/* Creates a new file and opens it for writing. Places
* the file pointer at the beginning. If the file
* exists an error will be returned. */
case 'x':
if ((uMode & RTFILE_O_ACTION_MASK) == 0)
{
}
else
break;
case '+':
{
switch (chPrev)
{
case 'c':
case 'w':
case 'x':
/* Also open / create file with read access. */
uMode |= RTFILE_O_READ;
break;
case 'a':
case 'r':
/* Also open / create file with write access. */
uMode |= RTFILE_O_WRITE;
break;
case 'b':
case 't':
/* Silently eat skipped parameters. */
fSkip = true;
break;
case 0: /* No previous character yet. */
case '+':
/* Eat plusses which don't belong to a command. */
fSkip = true;
break;
default:
break;
}
break;
}
default:
break;
}
if (RT_FAILURE(rc))
break;
if (!fSkip)
pszCur++;
}
/* No action mask set? */
if ((uMode & RTFILE_O_ACTION_MASK) == 0)
if (RT_SUCCESS(rc))
return rc;
}
{
/* pszSharing is not used yet. */
int rc = VINF_SUCCESS;
char chPrev = 0;
if (*pszCur == '\0')
return VERR_INVALID_PARAMETER;
/*
* Handle open mode.
*/
while ( pszCur
&& *pszCur != '\0')
{
bool fSkip = false;
switch (*pszCur)
{
case 'b': /* Binary mode. */
/* Just skip as being valid. */
fSkip = true;
break;
case 'r': /* Read. */
uMode |= RTFILE_O_READ;
break;
case 't': /* Text mode. */
/* Just skip as being valid. */
fSkip = true;
break;
case 'w': /* Write. */
uMode |= RTFILE_O_WRITE;
break;
case '+':
{
switch (chPrev)
{
case 'w':
/* Also use read access in write mode. */
uMode |= RTFILE_O_READ;
break;
case 'r':
/* Also use write access in read mode. */
uMode |= RTFILE_O_WRITE;
break;
case 'b':
case 't':
/* Silently eat skipped parameters. */
fSkip = true;
break;
case 0: /* No previous character yet. */
case '+':
/* Eat plusses which don't belong to a command. */
fSkip = true;
break;
default:
break;
}
break;
}
default:
break;
}
if (RT_FAILURE(rc))
break;
if (!fSkip)
pszCur++;
}
if (RT_FAILURE(rc))
return rc;
/*
* Handle disposition.
*/
/* Create a new file, always, overwrite an existing file. */
/* Create a new file if it does not exist, fail if exist. */
uMode |= RTFILE_O_CREATE;
/* Open existing file, create file if does not exist. */
/* Open existing, fail if does not exist. */
uMode |= RTFILE_O_OPEN;
/* Open and truncate existing, fail of not exist. */
else
/* No action mask set? */
if ( RT_SUCCESS(rc)
&& (uMode & RTFILE_O_ACTION_MASK) == 0)
/** @todo Handle sharing mode. */
if (RT_SUCCESS(rc))
return rc;
}