759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync/* $Id$ */
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync/** @file
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * IPRT - RTFileQuerySize, generic implementation.
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync */
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync/*
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2009-2010 Oracle Corporation
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync *
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * available from http://www.virtualbox.org. This file is free software;
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * you can redistribute it and/or modify it under the terms of the GNU
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * General Public License (GPL) as published by the Free Software
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync *
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * The contents of this file may alternatively be used under the terms
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * of the Common Development and Distribution License Version 1.0
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * VirtualBox OSE distribution, in which case the provisions of the
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * CDDL are applicable instead of those of the GPL.
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync *
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * You may elect to license modified versions of this file under the
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync * terms and conditions of either the GPL or the CDDL or both.
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync */
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync/*******************************************************************************
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync* Header Files *
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync*******************************************************************************/
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync#define LOG_GROUP RTLOGGROUP_FILE
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync#include "internal/iprt.h"
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync#include <iprt/file.h>
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync#include <iprt/err.h>
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync#include <iprt/log.h>
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync#include <iprt/path.h>
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsyncRTDECL(int) RTFileQuerySize(const char *pszPath, uint64_t *pcbFile)
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync{
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync RTFSOBJINFO ObjInfo;
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync int rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_FOLLOW_LINK);
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync if (RT_SUCCESS(rc))
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync {
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync if (RTFS_IS_FILE(ObjInfo.Attr.fMode))
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync {
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync *pcbFile = ObjInfo.cbObject;
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync LogFlow(("RTFileQuerySize(%p:{%s}): returns %Rrc (%#RX64)\n", pszPath, pszPath, rc, *pcbFile));
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync return rc;
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync }
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync if (RTFS_IS_DIRECTORY(ObjInfo.Attr.fMode))
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync rc = VERR_IS_A_DIRECTORY;
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync else
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync rc = VERR_FILE_NOT_FOUND; /** @todo VERR_NOT_A_FILE... */
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync }
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync LogFlow(("RTFileQuerySize(%p:{%s}): returns %Rrc\n", pszPath, pszPath, rc));
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync return rc;
759dccca3e36af4b21053c0b93bd8167d1ae5e2avboxsync}