RTFileReadAllByHandleEx-generic.cpp revision a55e9030a4645802dc4c16eb1fa66378e3642850
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - RTFileReadAllByHandleEx, generic implementation.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * available from http://www.virtualbox.org. This file is free software;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * The contents of this file may alternatively be used under the terms
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * of the Common Development and Distribution License Version 1.0
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution, in which case the provisions of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * CDDL are applicable instead of those of the GPL.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * You may elect to license modified versions of this file under the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * terms and conditions of either the GPL or the CDDL or both.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * additional information or have any questions.
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync/*******************************************************************************
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync* Header Files *
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync*******************************************************************************/
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsyncRTDECL(int) RTFileReadAllByHandleEx(RTFILE File, RTFOFF off, RTFOFF cbMax, uint32_t fFlags, void **ppvFile, size_t *pcbFile)
089c21a647af46044cad04a78cfdcfae814d2105vboxsync AssertReturn(!(fFlags & ~RTFILE_RDALL_VALID_MASK), VERR_INVALID_PARAMETER);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * Save the current offset first.
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync int rc = RTFileSeek(File, 0, RTFILE_SEEK_CURRENT, (uint64_t *)&offOrg);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * Get the file size, adjust it and check that it might fit into memory.
0e5731ab59b4ecead38375f26eeea698f00b19fdvboxsync rc = RTFileSeek(File, 0,RTFILE_SEEK_END, (uint64_t *)&cbFile);
8e034cd2a6b0c86697554278e970163287003bb9vboxsync RTFOFF cbAllocFile = cbFile > off ? cbFile - off : 0;
8e034cd2a6b0c86697554278e970163287003bb9vboxsync * Try allocate the required memory and initialize the header (hardcoded fun).
return rc;