1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync/* $Id$ */
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync/** @file
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * IPRT - RTPathGetCurrentOnDrive, generic implementation.
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync */
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync/*
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * Copyright (C) 2014 Oracle Corporation
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync *
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * available from http://www.virtualbox.org. This file is free software;
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * General Public License (GPL) as published by the Free Software
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync *
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * The contents of this file may alternatively be used under the terms
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * of the Common Development and Distribution License Version 1.0
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * VirtualBox OSE distribution, in which case the provisions of the
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * CDDL are applicable instead of those of the GPL.
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync *
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * You may elect to license modified versions of this file under the
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * terms and conditions of either the GPL or the CDDL or both.
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync */
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync/*******************************************************************************
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync* Header Files *
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync*******************************************************************************/
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync#define LOG_GROUP RTLOGGROUP_PATH
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync#include <iprt/path.h>
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync#include "internal/iprt.h"
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync#include <iprt/ctype.h>
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync#include <iprt/err.h>
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync#include <iprt/string.h>
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync#include "internal/path.h"
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsyncRTDECL(int) RTPathGetCurrentOnDrive(char chDrive, char *pszPath, size_t cbPath)
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync{
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync#ifdef HAVE_DRIVE
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync /*
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * Check if it's the same drive as the current directory.
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync */
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync int rc = RTPathGetCurrent(pszPath, cbPath);
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync if (RT_SUCCESS(rc))
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync {
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync if ( ( chDrive == *pszPath
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync || RT_C_TO_LOWER(chDrive) == RT_C_TO_LOWER(*pszPath))
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync && RTPATH_IS_VOLSEP(pszPath[1]))
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync return rc;
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync /*
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * Different drive, indicate root.
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync */
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync if (cbPath >= 4)
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync {
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync pszPath[0] = RT_C_TO_UPPER(chDrive);
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync pszPath[1] = ':';
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync pszPath[2] = RTPATH_SLASH;
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync pszPath[3] = '\0';
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync return VINF_SUCCESS;
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync }
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync }
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync return rc;
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync#else
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync /*
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * No driver letters, just return root slash on whatever we're asked.
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync */
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync NOREF(chDrive);
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync if (cbPath >= 2)
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync {
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync pszPath[0] = RTPATH_SLASH;
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync pszPath[1] = '\0';
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync return VINF_SUCCESS;
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync }
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync return VERR_BUFFER_OVERFLOW;
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync#endif
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync}
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsyncRT_EXPORT_SYMBOL(RTPathGetCurrentOnDrive);
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync