RTUuidCreate-generic.cpp revision a27567873aa392eab8243497a5674ee0336f61c9
a27567873aa392eab8243497a5674ee0336f61c9vboxsync/* $Id$ */
a27567873aa392eab8243497a5674ee0336f61c9vboxsync/** @file
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * IPRT - UUID, Generic RTUuidCreate implementation.
a27567873aa392eab8243497a5674ee0336f61c9vboxsync */
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync/*
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
a27567873aa392eab8243497a5674ee0336f61c9vboxsync * additional information or have any questions.
a27567873aa392eab8243497a5674ee0336f61c9vboxsync */
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync/*******************************************************************************
a27567873aa392eab8243497a5674ee0336f61c9vboxsync* Header Files *
a27567873aa392eab8243497a5674ee0336f61c9vboxsync*******************************************************************************/
a27567873aa392eab8243497a5674ee0336f61c9vboxsync#include <iprt/uuid.h>
a27567873aa392eab8243497a5674ee0336f61c9vboxsync#include <iprt/assert.h>
a27567873aa392eab8243497a5674ee0336f61c9vboxsync#include <iprt/err.h>
a27567873aa392eab8243497a5674ee0336f61c9vboxsync#include <iprt/rand.h>
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync/* WARNING: This implementation ASSUMES little endian. Needs testing on big endian! */
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync/** @todo move to a different file. */
a27567873aa392eab8243497a5674ee0336f61c9vboxsyncRTDECL(int) RTUuidCreate(PRTUUID pUuid)
a27567873aa392eab8243497a5674ee0336f61c9vboxsync{
a27567873aa392eab8243497a5674ee0336f61c9vboxsync /* validate input. */
a27567873aa392eab8243497a5674ee0336f61c9vboxsync AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER);
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync RTRandBytes(pUuid, sizeof(*pUuid));
a27567873aa392eab8243497a5674ee0336f61c9vboxsync pUuid->Gen.u16ClockSeq = (pUuid->Gen.u16ClockSeq & 0x3fff) | 0x8000;
a27567873aa392eab8243497a5674ee0336f61c9vboxsync pUuid->Gen.u16TimeHiAndVersion = (pUuid->Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
a27567873aa392eab8243497a5674ee0336f61c9vboxsync
a27567873aa392eab8243497a5674ee0336f61c9vboxsync return VINF_SUCCESS;
a27567873aa392eab8243497a5674ee0336f61c9vboxsync}
a27567873aa392eab8243497a5674ee0336f61c9vboxsync