a27567873aa392eab8243497a5674ee0336f61c9vboxsync/* $Id$ */
a27567873aa392eab8243497a5674ee0336f61c9vboxsync/** @file
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * IPRT - UUID, Generic RTUuidCreate implementation.
a27567873aa392eab8243497a5674ee0336f61c9vboxsync */
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync/*
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2006-2010 Oracle Corporation
a27567873aa392eab8243497a5674ee0336f61c9vboxsync *
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * available from http://www.virtualbox.org. This file is free software;
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * General Public License (GPL) as published by the Free Software
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a27567873aa392eab8243497a5674ee0336f61c9vboxsync *
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * The contents of this file may alternatively be used under the terms
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * of the Common Development and Distribution License Version 1.0
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * VirtualBox OSE distribution, in which case the provisions of the
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * CDDL are applicable instead of those of the GPL.
a27567873aa392eab8243497a5674ee0336f61c9vboxsync *
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * You may elect to license modified versions of this file under the
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * terms and conditions of either the GPL or the CDDL or both.
a27567873aa392eab8243497a5674ee0336f61c9vboxsync */
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync/*******************************************************************************
a27567873aa392eab8243497a5674ee0336f61c9vboxsync* Header Files *
a27567873aa392eab8243497a5674ee0336f61c9vboxsync*******************************************************************************/
a27567873aa392eab8243497a5674ee0336f61c9vboxsync#include <iprt/uuid.h>
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync#include "internal/iprt.h"
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync#include <iprt/assert.h>
a27567873aa392eab8243497a5674ee0336f61c9vboxsync#include <iprt/err.h>
a27567873aa392eab8243497a5674ee0336f61c9vboxsync#include <iprt/rand.h>
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
cca68441e3840543d10a390547e94d1b7a984778vboxsync/* WARNING: This implementation ASSUMES little endian. Does not work on big endian! */
cca68441e3840543d10a390547e94d1b7a984778vboxsync
cca68441e3840543d10a390547e94d1b7a984778vboxsync/* Remember, the time fields in the UUID must be little endian. */
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsyncRTDECL(int) RTUuidCreate(PRTUUID pUuid)
a27567873aa392eab8243497a5674ee0336f61c9vboxsync{
a27567873aa392eab8243497a5674ee0336f61c9vboxsync /* validate input. */
a27567873aa392eab8243497a5674ee0336f61c9vboxsync AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER);
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync RTRandBytes(pUuid, sizeof(*pUuid));
cca68441e3840543d10a390547e94d1b7a984778vboxsync pUuid->Gen.u8ClockSeqHiAndReserved = (pUuid->Gen.u8ClockSeqHiAndReserved & 0x3f) | 0x80;
a27567873aa392eab8243497a5674ee0336f61c9vboxsync pUuid->Gen.u16TimeHiAndVersion = (pUuid->Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync return VINF_SUCCESS;
a27567873aa392eab8243497a5674ee0336f61c9vboxsync}
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsyncRT_EXPORT_SYMBOL(RTUuidCreate);
a27567873aa392eab8243497a5674ee0336f61c9vboxsync