dir-win32.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* $Id$ */
/** @file
* InnoTek Portable Runtime - Directory, win32.
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_DIR
#include <Windows.h>
{
bool fRc = false;
/*
* Convert to UCS2.
*/
if (RT_SUCCESS(rc))
{
/*
* Query and check attributes.
*/
&& (dwAttr & FILE_ATTRIBUTE_DIRECTORY);
}
return fRc;
}
{
/*
* Validate the file mode.
*/
int rc;
{
/*
* Convert to UCS2.
*/
if (RT_SUCCESS(rc))
{
/*
* Create the directory.
*/
rc = VINF_SUCCESS;
else
}
}
else
{
}
return rc;
}
{
/*
* Convert to UCS2.
*/
if (RT_SUCCESS(rc))
{
/*
* Remove the directory.
*/
rc = VINF_SUCCESS;
else
}
return rc;
}
{
/*
* Setup the search expression.
*
* pszPathBuf is pointing to the return 4K return buffer for the RTPathReal()
* call in rtDirOpenCommon(), so all we gota do is check that we don't overflow
* it when adding the wildcard expression.
*/
const char *pszExpr;
{
}
else
{
pszExpr = "*";
cchExpr = sizeof("*");
}
return VERR_FILENAME_TOO_LONG;
/*
* Attempt opening the search.
*/
int rc = VINF_SUCCESS;
#ifndef RT_DONT_CONVERT_FILENAMES
if (RT_SUCCESS(rc))
{
#else
#endif
pDir->fDataUnread = true;
/* theoretical case of an empty directory. */
else if (GetLastError() == ERROR_NO_MORE_FILES)
pDir->fDataUnread = false;
else
#ifndef RT_DONT_CONVERT_FILENAMES
}
#endif
return rc;
}
{
/*
* Validate input.
*/
if (!pDir)
return VERR_INVALID_PARAMETER;
{
return VERR_INVALID_PARAMETER;
}
/*
* Close the handle.
*/
{
}
return VINF_SUCCESS;
}
{
/*
* Validate input.
*/
{
return VERR_INVALID_PARAMETER;
}
if (!pDirEntry)
{
return VERR_INVALID_PARAMETER;
}
unsigned cbDirEntry = sizeof(*pDirEntry);
if (pcbDirEntry)
{
{
AssertMsgFailed(("Invalid *pcbDirEntry=%d (min %d)\n", *pcbDirEntry, RT_OFFSETOF(RTDIRENTRY, szName[2])));
return VERR_INVALID_PARAMETER;
}
}
/*
* Fetch data?
*/
if (!pDir->fDataUnread)
{
#ifdef RT_DONT_CONVERT_FILENAMES
#else
#endif
if (!fRc)
{
int iErr = GetLastError();
return VERR_NO_MORE_FILES;
return RTErrConvertFromWin32(iErr);
}
}
#ifndef RT_DONT_CONVERT_FILENAMES
/*
* Convert the filename to UTF-8.
*/
{
if (RT_FAILURE(rc))
{
return rc;
}
}
#endif
/*
* Check if we've got enough space to return the data.
*/
#ifdef RT_DONT_CONVERT_FILENAMES
#else
#endif
if (pcbDirEntry)
if (cbRequired > cbDirEntry)
return VERR_BUFFER_OVERFLOW;
/*
* Setup the returned data.
*/
pDir->fDataUnread = false;
return VINF_SUCCESS;
}
RTDECL(int) RTDirReadEx(PRTDIR pDir, PRTDIRENTRYEX pDirEntry, unsigned *pcbDirEntry, RTFSOBJATTRADD enmAdditionalAttribs)
{
/*
* Validate input.
*/
{
return VERR_INVALID_PARAMETER;
}
if (!pDirEntry)
{
return VERR_INVALID_PARAMETER;
}
{
return VERR_INVALID_PARAMETER;
}
unsigned cbDirEntry = sizeof(*pDirEntry);
if (pcbDirEntry)
{
{
AssertMsgFailed(("Invalid *pcbDirEntry=%d (min %d)\n", *pcbDirEntry, RT_OFFSETOF(RTDIRENTRYEX, szName[2])));
return VERR_INVALID_PARAMETER;
}
}
/*
* Fetch data?
*/
if (!pDir->fDataUnread)
{
#ifdef RT_DONT_CONVERT_FILENAMES
#else
#endif
if (!fRc)
{
int iErr = GetLastError();
return VERR_NO_MORE_FILES;
return RTErrConvertFromWin32(iErr);
}
}
#ifndef RT_DONT_CONVERT_FILENAMES
/*
* Convert the filename to UTF-8.
*/
{
if (RT_FAILURE(rc))
{
return rc;
}
}
#endif
/*
* Check if we've got enough space to return the data.
*/
#ifdef RT_DONT_CONVERT_FILENAMES
#else
#endif
if (pcbDirEntry)
if (cbRequired > cbDirEntry)
return VERR_BUFFER_OVERFLOW;
/*
* Setup the returned data.
*/
pDir->fDataUnread = false;
#ifndef RT_DONT_CONVERT_FILENAMES /* this ain't nice since the whole point of this define is not to drag in conversion... */
{
/* copy and calc length */
while (*pucSrc)
/* zero the rest */
*pucDst++ = '\0';
}
else
#endif
{
pDirEntry->cucShortName = 0;
}
pDirEntry->Info.Attr.fMode = rtFsModeFromDos((pDir->Data.dwFileAttributes << RTFS_DOS_SHIFT) & RTFS_DOS_MASK_NT,
/*
* Requested attributes (we cannot provide anything actually).
*/
switch (enmAdditionalAttribs)
{
case RTFSOBJATTRADD_EASIZE:
break;
case RTFSOBJATTRADD_UNIX:
break;
case RTFSOBJATTRADD_NOTHING:
break;
default:
AssertMsgFailed(("Impossible!\n"));
return VERR_INTERNAL_ERROR;
}
return VINF_SUCCESS;
}
{
/*
* Validate input.
*/
AssertMsgReturn(!(fRename & ~RTPATHRENAME_FLAGS_REPLACE), ("%#x\n", fRename), VERR_INVALID_PARAMETER);
/*
* Call the worker.
*/
LogFlow(("RTDirRename(%p:{%s}, %p:{%s}, %#x): returns %Rrc\n", pszSrc, pszSrc, pszDst, pszDst, fRename, rc));
return rc;
}