Compare commits

...
5 Commits
Author SHA1 Message Date
Clifford Yapp caf9c27b2a Never mind integrating a 3rd party uuid - we'll just put together a libbu uuid that does what we need. Remove uuid branch. (svn branch delete)
svn:revision:62157
svn:branch:uuid
svn:account:starseeker
2014-08-15 13:12:32 +00:00
Clifford Yapp 488aaea7ce Start trying to make a one C file + one header version of ossp uuid. Once we get that done, the next step will be to 'libbu-ify' it
svn:revision:61654
svn:branch:uuid
svn:account:starseeker
2014-07-10 13:31:21 +00:00
Clifford Yapp b75cc57f73 Start stripping down what we don't need
svn:revision:61650
svn:branch:uuid
svn:account:starseeker
2014-07-10 12:41:24 +00:00
Clifford Yapp 40c6da4fe3 Add OSSP uuid 1.6.2 (http://www.ossp.org/pkg/lib/uuid/)
svn:revision:61649
svn:branch:uuid
svn:account:starseeker
2014-07-10 12:33:00 +00:00
Clifford Yapp e758af4385 Set up a branch to experiment with some uuid code to create bu_uuid (should be able to build off of some old work for geomcore.)
svn:revision:61647
svn:branch:uuid
svn:account:starseeker
2014-07-10 12:22:45 +00:00
35 changed files with 14244 additions and 0 deletions
+624
View File
@@ -0,0 +1,624 @@
_ ___ ____ ____ ____ _ _
|_|_ _ / _ \/ ___/ ___|| _ \ _ _ _ _(_) __| |
_|_||_| | | | \___ \___ \| |_) | | | | | | | | |/ _` |
|_||_|_| | |_| |___) |__) | __/ | |_| | |_| | | (_| |
|_|_|_| \___/|____/____/|_| \__,_|\__,_|_|\__,_|
OSSP uuid - Universally Unique Identifier
CHANGELOG
This is a list of all changes to OSSP uuid.
For a more brief summary please have a look at the NEWS file.
Changes between 1.6.1 and 1.6.2 (21-Feb-2008 to 04-Jul-2008)
o Adjust "devtool.func" for latest GNU Libtool compatibility.
[Ralf S. Engelschall]
o Improve PRNG under Win32.
[Hiroshi Saito]
o Consistently annotate "RFC-XXXX" with "IETF" to clearly
indicate from which standards body this comes from.
[Ralf S. Engelschall]
o Resolve namespace conflicts of recently introduced time_xxx()
functions by using a propoer "uuid_" prefix.
[Ralf S. Engelschall]
o Remove unused "struct timezone" from time_gettimeofday() in
order to simplify portability.
[Ralf S. Engelschall]
o Add support for POSIX clock_gettime(3) in case the Unix/POSIX
gettimeofday(3) is not available.
[Ralf S. Engelschall]
o Upgrade build environment to GNU autoconf 2.62.
[Ralf S. Engelschall]
o Upgrade build environment to GNU libtool 2.2.4.
[Ralf S. Engelschall]
Changes between 1.6.0 and 1.6.1 (19-May-2007 to 21-Feb-2008)
o Port to Win32 API.
[Hiroshi Saito, Wu Yongwei, Ralf S. Engelschall]
o Adjust copyright messages for new year 2008.
[Ralf S. Engelschall]
o Fix __VA_COPY_USE_{CSP,CPP} fallback macros for va_copy.
[Mark A. Lindner <mark.a.lindner@gmail.com>]
o PostgreSQL bindings: use SET_VARSIZE() instead
of assigning to bytea->v_len under PostgreSQL >= 8.3
[Ralf S. Engelschall]
o Upgrade build environment to GNU libtool 1.5.26
[Ralf S. Engelschall]
Changes between 1.5.1 and 1.6.0 (31-Jul-2006 to 19-May-2007)
o Expand unused "datarootdir" in Makefile.in and uuid-config.in to
make newer GNU autoconf versions happy.
[Ralf S. Engelschall]
o Upgrade build environment to GNU shtool 2.0.7
[Ralf S. Engelschall]
o Make GNU autoconf procedure of PHP binding more robust by using
-Wl,-Bsymbolic only on platforms where uuid_create(3) actually
exists and where -Wl,-Bsymbolic is really accepted by the tool
chain. This especially unbreaks MacOS X.
[Ralf S. Engelschall]
o Fix "uuid_export" function in PHP bindings under
UUID_FMT_SIV, UUID_FMT_STR and UUID_FMT_TXT where the
NUL-termination character should be not passed back to PHP.
[Neil Caunt <retardis@gmail.com>, Ralf S. Engelschall]
o Adjust copyright messages for new year 2007.
[Ralf S. Engelschall]
o Upgrade build environment to GNU autoconf 2.61
[Ralf S. Engelschall]
o Disable PostgreSQL "(CSTRING AS uuid)" and "(uuid AS CSTRING)"
CASTS as PostgreSQL 8.2 and higher explicitly disallow this.
[David Wheeler <david@kineticode.com>, Ralf S. Engelschall]
o Fix PostgreSQL bindings by mapping the correct DSO symbol
to the functions "uuid_send" and "uuid_recv".
[Ralf S. Engelschall]
o Silence PostgreSQL processing messages
[David Wheeler <david@kineticode.com>]
o Support MacOS X (aka Darwin) in PostgreSQL bindings by passing
a "-bundle_loader" option to the linker in order to resolve the
"undefined symbols" problem.
[David Wheeler <david@kineticode.com>, Ralf S. Engelschall]
o Pass the correct type to PostgreSQL's errmsg().
[David Wheeler <david@kineticode.com>, Ralf S. Engelschall]
o Added PostgreSQL 8.2 PG_MODULE_MAGIC support.
[David Wheeler <david@kineticode.com>]
o Fix the Data::UUID::to_b64string() function of the Perl backward
compatibility API: an empty string was not supplied as the EOL
marker to MIME::Base64::encode_base64() and hence the returned
string ended with a newline character (which in turn breaks many
applications using Data::UUID).
[Piotr Roszatycki <dexter@debian.org>]
o Change type of "data_ptr" argument in uuid_export() API signature
from "void **" to "void *" as there is unfortunately no
"generic pointer to pointer type" in ISO C (see also
http://c-faq.com/ptrs/genericpp.html) and "void **" is just a
"pointer to a 'void *'".
The "void **" especially had the nasty side-effect that it breaks
strict pointer aliasing rules of ISO C and hence would require
fiddling with temporary variables on all uuid_export() calls if
one would be 100% correct and avoid aliasing related compiler
warnings. Instead, as uuid_export() internally has to cast the
"data_ptr" to the particular expected type anyway, it is better
to have "data_ptr" just be a really generic "void *" in the API
signature.
Keep in mind that although this is an API change, it doesn't cause
any incompatibilities as the function still expects the same
"pointer to a pointer of a particular type". This expected pointer
is just now passed the more correct although less intuitive way.
[Hrvoje Niksic <hniksic@xemacs.org>, Ralf S. Engelschall]
o Optional DMALLOC based memory debugging support.
[Ralf S. Engelschall]
o Consistently include "uuid_ac.h" in all source files to have GNU
autoconf results and standard system defines available everywhere.
[Ralf S. Engelschall]
Changes between 1.5.0 and 1.5.1 (28-Jul-2006 to 31-Jul-2006)
o Use "MODULE_PATHNAME" instead of "@MODULE_PATHNAME@" in
uuid.sql.in to be more aligned to the PostgreSQL styles.
[Simon "janus" Dassow <janus@errornet.de>]
o Use the available variables $(LIB_NAME), $(DCE_NAME) and
$(CXX_NAME) more consistently in Makefile.in to allow packagers to
override the library name with less patching.
[Piotr Roszatycki <dexter@debian.org>]
o Fix the "make distclean" target of php/Makefile.local
to make sure the ".deps" file is not left over.
[Ralf S. Engelschall]
o Fix the tarball rolling procedure to make sure we
do not distribute binary files again. This now especially uses
a MANIFEST file which explicitly lists all files which form the
distribution tarball. We compare the tarball and the MANIFEST file
for differences in the "devtool dist" now.
[Ralf S. Engelschall]
Changes between 1.4.2 and 1.5.0 (13-Mar-2006 to 28-Jul-2006)
o Fixed potential memory leak in uuid_create() as spotted by SPLINT.
[Ralf S. Engelschall]
o Cleanup source code according to complains by SPLINT.
[Ralf S. Engelschall]
o Cleanup internal uuid_mac.h header.
[Ralf S. Engelschall]
o Numerous fixed to the error handling in the PostgreSQL bindings.
[Neil Conway <neilc@samurai.com>]
o Add Hash indexing support UUID data type of PostgreSQL bindings.
[Ralf S. Engelschall]
o Add comparison operators and B-Tree indexing support UUID data
type of PostgreSQL bindings.
[Roman Neuhauser <neuhauser@sigpipe.cz>]
o Fix PHP bindings: the wrong argument to uuid_create()
was forced to a reference
[Roman Neuhauser <neuhauser@sigpipe.cz>]
o Add full support for Single Integer Value (SIV) UUID representation
for both importing and exporting in C/C++/Perl/PHP APIs.
[Ralf S. Engelschall]
o Upgrade build environment to GNU shtool 2.0.6 and GNU autoconf 2.60
[Ralf S. Engelschall]
o Added an "OVERVIEW" file which tries to give the "big picture"
about UUIDs and allows to survice during the nasty UUID bit fiddling.
[Ralf S. Engelschall]
o Replaced "clock_seq_and_reserved" with
"clock_seq_high_and_reserved" in uuid.pod to already reflect the
description in the forthcoming RFC.
[Ralf S. Engelschall]
o Speed up processing in uuid_str.c by reducing va_copy() calls from
two to just one per formatting.
[Ralf S. Engelschall]
Changes between 1.4.1 and 1.4.2 (07-Feb-2006 to 13-Mar-2006)
o Fix uuid_export() function by fixing the internal
uuid_s[ar]printf() functions which require the backup of va_list
arguments between subsequent processing.
[Ralf S. Engelschall, Thomas Lotterer <thomas@lotterer.net>]
o Fix Perl API's "export" function by not taking over NUL-termination
character under UUID_FMT_TXT.
[Thomas Lotterer <thomas@lotterer.net>]
o Declare "install", "uninstall" and "clean" make(1) targets
".PHONY". This especially workarounds problems on case insensitive
filesystems (like MacOS X' filesystem) where the "INSTALL" document
conflicts with the "install" target.
[Ralf S. Engelschall, David Wheeler <david@kineticode.com>]
Changes between 1.4.0 and 1.4.1 (15-Jan-2006 to 07-Feb-2006)
o Upgrade to GNU shtool 2.0.5
[Ralf S. Engelschall]
o Apply workaround to uuid.h to avoid conflicts with
vendor UUID implementations where uuid_t (Darwin/MacOSX)
or uuid_create/uuid_compare (POSIX) might exist.
[Ralf S. Engelschall]
Changes between 1.3.2 and 1.4.0 (06-Dec-2005 to 15-Jan-2006)
o Created a top-level Perl ExtUtils::MakeMaker wrapper script
[Ralf S. Engelschall]
o Adjust copyright messages for new year 2006.
[Ralf S. Engelschall]
o Added experimental PostgreSQL bindings.
[Ralf S. Engelschall]
o Fixed documentation of uuid_make() function.
[Ralf S. Engelschall]
o Upgrade build environment to GNU libtool 1.5.22
[Ralf S. Engelschall]
Changes between 1.3.1 and 1.3.2 (24-Sep-2005 to 06-Dec-2005)
o Cleaned up and speed optimized perl/uuid_compat.pm
(the Data::UUID compatibility module for Perl)
[David Wheeler <david@justatheory.com>]
o Upgrade to GNU shtool 2.0.3
[Ralf S. Engelschall]
o Consistently use "return" in uuid++.cc
[Ralf S. Engelschall]
Changes between 1.3.0 and 1.3.1 (02-Sep-2005 to 24-Sep-2005)
o Fix two incorrect casts, detected by compiling the C code
under C++ constraints.
[Ralf S. Engelschall]
o Remove a compiler warning in the PHP bindings.
[Ralf S. Engelschall]
o Plug memory leak in PRNG sub-library.
[Ralf S. Engelschall]
o Add VPATH/srcdir support for at the default
build procedure plus at least C++ and DCE build options.
[Ralf S. Engelschall]
Changes between 1.2.1 and 1.3.0 (30-Aug-2005 to 02-Sep-2005)
o Add an experimental PHP 4/5 language API binding which
can be enabled under build-time with opption --with-php.
[Ralf S. Engelschall]
o Upgrade to GNU libtool 1.5.20
[Ralf S. Engelschall]
o Add missing "const" in manual page.
[Ralf S. Engelschall]
o Add an experimental C++ API binding which can be
enabled under build-time with option --with-cxx.
[Ralf S. Engelschall]
o Cleanup the internals of the uuid_create() function and
add a new corresponding uuid_clone() API function.
[Ralf S. Engelschall]
o Cleanup some Makefile parts.
[Ralf S. Engelschall]
o Added a pkg-config(1) specification uuid.pc which is also
installed by default in addition to the old-style uuid-config tool.
[Ralf S. Engelschall]
o Added optional Data::UUID backward compatibility Perl API which can
be enabled with the build-time option --with-perl-compat.
[Piotr Roszatycki <dexter@debian.org>, Ralf S. Engelschall]
o Add a functionality-reduced TIE-style Perl API OSSP::uuid::tie,
intended for very high-level convenience programming.
[Ralf S. Engelschall]
o Reference the new officially published RFC 4122.
[Ralf S. Engelschall]
Changes between 1.2.0 and 1.2.1 (23-Jan-2005 to 30-Aug-2005)
o Add SEEALSO document which references all known
UUID implementations.
[Ralf S. Engelschall]
o Improve the PRNG in case no stronger system PRNG device is
available by passing time and rand(3) based entropy into the MD5
one-way hash function to achieve at least some sort of weaker PRN data.
[Ralf S. Engelschall]
o Fix MAC address determination under Solaris by using the result of
ioctl(...,SIOCGARP,...) only if arp_flags had ATF_COM set.
[Ralf S. Engelschall]
o Upgrade to GNU libtool 1.5.18 and GNU shtool 2.0.2.
[Ralf S. Engelschall]
o Cleanup the source code even more by following a large
set of FlexeLint's suggestions.
[Ralf S. Engelschall]
o Fixed generated "section" number in uuid-config(1).
[Piotr Roszatycki <dexter@debian.org>]
Changes between 1.1.2 and 1.2.0 (13-Jan-2005 to 23-Jan-2005)
o Added support for new version 5 UUIDs (name-based, SHA-1)
according to latest draft-mealling-uuid-urn-05.txt.
[Ralf S. Engelschall]
o Reference new ISO/IEC 9834-8:2004 / ITU-T Rec. X.667 2004 standard
and latest IETF draft-mealling-uuid-urn-05.txt.
[Ralf S. Engelschall]
Changes between 1.1.1 and 1.1.2 (18-Nov-2004 to 13-Jan-2005)
o Fix generation of v3 UUIDs by adding support for 64-bit platforms
to the underlying uuid_md5.c code (which internally is based on
the RFC reference code which in turn assumes a 32-bit environment).
[Ralf S. Engelschall, Piotr Roszatycki <Piotr_Roszatycki@netia.net.pl>]
o Optimize internal md5_store() function by directly finalizing MD5
calculation on buffer copy instead of finalizing original buffer
and having to restore it from the buffer copy.
[Ralf S. Engelschall]
o Adjust copyright messages for new year 2005.
[Ralf S. Engelschall]
o Do not rebuild the Perl API if there were no actual changes.
[Ralf S. Engelschall]
Changes between 1.1.0 and 1.1.1 (03-Nov-2004 to 18-Nov-2004)
o Apply the FreeBSD libc uuid_create() related workaround
in the Perl bindings also under FreeBSD 6.0-CURRENT.
[Ralf S. Engelschall]
o Fix --with-perl configure option processing: Perl is
only required if --with-perl is used although we search for Perl
always in order to provide the PERL variable substitution.
[Ralf S. Engelschall]
Changes between 1.0.4 and 1.1.0 (16-Oct-2004 to 03-Nov-2004)
o Add --with-perl configure option for optionally enabling
the Perl language bindings.
[Ralf S. Engelschall]
o Add Perl language bindings providing both a C-style and OO-style API.
[Ralf S. Engelschall]
Changes between 1.0.3 and 1.0.4 (15-Oct-2004 to 16-Oct-2004)
o Fix version detection from uuid_vers.h
[Ralf S. Engelschall]
Changes between 1.0.2 and 1.0.3 (12-Sep-2004 to 15-Oct-2004)
o Support configuring/building/installing from an arbitrary
directory via srcdir/top_srcdir/VPATH.
[David Lee <t.d.lee@durham.ac.uk>, Ralf S. Engelschall]
o Upgrade build environment to GNU libtool 1.5.10.
[Ralf S. Engelschall]
Changes between 1.0.1 and 1.0.2 (16-Jul-2004 to 12-Sep-2004)
o Upgrade build environment to GNU libtool 1.5.8 and GNU shtool 2.0.1
[Ralf S. Engelschall]
Changes between 1.0.0 and 1.0.1 (16-Feb-2004 to 16-Jul-2004)
o Made documentation of uuid_export() more clear.
[Ralf S. Engelschall]
o Upgrade build environment to GNU libtool 1.5.6 and GNU shtool 2.0.0
[Ralf S. Engelschall]
o Remove some warnings occurring under GCC 3.5
[Ralf S. Engelschall]
Changes between 0.9.7 and 1.0.0 (13-Feb-2004 to 16-Feb-2004)
o Replace remaining (old) UUID_VERSIONX names with UUID_MAKE_VX
in the documentation (uuid.pod).
[Ralf S. Engelschall]
o Resolve namespace conflicts with GCC 3.4 internal pow10() and round()
functions within uuid_str.c.
[Ralf S. Engelschall]
o Fix buffer handling in "uuid_export(..., UUID_FMT_TXT, vp, ...)" in
case "vp" is not NULL.
[Fuyuki <fuyuki@nigredo.org>]
Changes between 0.9.6 and 0.9.7 (11-Feb-2004 to 13-Feb-2004)
o remove --with-rfc2518 option and functionality because
even the IETF/IESG has finally approved our report about the broken
random multicast MAC address generation in the standard (and
will fix it in new versions of the draft-mealling-uuid-urn). So,
finally get rid of this broken-by-design backward compatibility
functionality.
[Ralf S. Engelschall]
o Add support to uuid(1) CLI for decoding from stdin for
both binary and string representations.
[Ralf S. Engelschall]
o Add missing documentation entries for UUID_XXXX API constants and
uuid_version() function.
[Fuyuki <fuyuki@nigredo.org>]
o Adjust references for new draft-mealling-uuid-urn-02.txt.
[Fuyuki <fuyuki@nigredo.org>]
o Replaced overlooked references to old
uuid_{unpack,pack,parse,format,dump}() functions with their
current uuid_{import,export}() replacements.
[Fuyuki <fuyuki@nigredo.org>]
o Fixed "uuid -h" command.
[Fuyuki <fuyuki@nigredo.org>]
Changes between 0.9.5 and 0.9.6 (06-Feb-2004 to 11-Feb-2004)
o Added an experimental additional DCE 1.1 API for backward
compatibility with existing applications.
[Ralf S. Engelschall]
Changes between 0.9.4 and 0.9.5 (19-Jan-2004 to 06-Feb-2004)
o Fixed filedescriptor leak in the PRNG sub-API.
[Guerry Semones <guerry@tsunamiresearch.com>]
o Upgraded build environment to GNU libtool 1.5.2.
[Ralf S. Engelschall]
Changes between 0.9.3 and 0.9.4 (16-Jan-2004 to 19-Jan-2004)
o Include <string.h> in uuid.h because of size_t usage.
[Ralf S. Engelschall]
o INCOMPATIBILITY: Refactor the API and rename uuid_generate()
to uuid_make() and use a "uuid_t" pointer for the namespace
on UUID_VERSION3 generation. To allow access to the internal
pre-defined namespace UUIDs, provide a new uuid_load() function.
Because uuid_load() now also allows the loading of the "nil" UUID,
remove uuid_nil() from the API. After this second refactoring the
API is now the one we originally wished for the forthcoming version
1.0 of OSSP uuid.
[Ralf S. Engelschall]
o INCOMPATIBILITY: rename UUID_VERSIONx to UUID_MAKE_Vx and
UUID_MCASTRND to UUID_MAKE_MC to be more consistent throughout API.
[Ralf S. Engelschall]
o Add version support to API via UUID_VERSION (compile-time)
and uuid_version() (link-time).
[Ralf S. Engelschall]
o INCOMPATIBILITY: Refactor the API by merging
uuid_{unpack,pack,parse,format,dump}() functions into unified
uuid_{import,export}() functions. This allows us to easily add
support for other formats (e.g. XML) in the future without having
the change the API in principle.
[Ralf S. Engelschall]
o Document what DCE 1.1 UUID versions exist and what they are
intended for.
[Ralf S. Engelschall]
o Cleanup the C code to also pass warning-free a C++ compiler.
[Ralf S. Engelschall]
o Support C++ by enclosing the C API declarations in
'extern "C" {...}' within uuid.h.
[Guerry Semones <guerry@tsunamiresearch.com>]
o Improvide decoding in uuid_dump() by at least hex-dumping the
binary representation in case of v3, v4 and Nil UUIDs. Also,
annotate with better hints.
[Ralf S. Engelschall]
o Recognize special "Nil UUID" on decoding in uuid_dump().
[Ralf S. Engelschall]
Changes between 0.9.2 and 0.9.3 (15-Jan-2004 to 16-Jan-2004)
o Tested OSSP uuid on 16 particular Unix platforms and list
those in the new PORTING file.
[Ralf S. Engelschall]
o Fixed minor formatting bug in call to str_rsprintf().
[Ralf S. Engelschall]
o Fix syntax error in uuid.ac.
[Ralf S. Engelschall]
Changes between 0.9.1 and 0.9.2 (13-Jan-2004 to 15-Jan-2004)
o Provide both incorrect RFC2518-based and correct IEEE 802
multicast address generation. The default now is the correct
IEEE 802 multicast address generation but compile-time option
--with-rfc2518 selects the broken variant.
[Ralf S. Engelschall]
o Decode also the IEEE 802 MAC address local/global bit.
[Ralf S. Engelschall]
o Added missing documentation for uuid_dump().
[Ralf S. Engelschall]
o Fixed BM_POW2() macro implementation.
[Ralf S. Engelschall]
o Use BM_XXX() and str_xxx() APIs throughout internal implementation.
[Ralf S. Engelschall]
o Added missing manual page uuid-config(1).
[Ralf S. Engelschall]
o Fixed output of "uuid-config --version"
[Ralf S. Engelschall]
o Fixed typos in uuid.pod
[Ralf S. Engelschall]
o Cleanup uuid.ac for unused elements.
[Ralf S. Engelschall]
o Moved uuid_[u]int{8,16,32}_t auto-configuration into
own internal header uuid_ac.h.
[Ralf S. Engelschall]
o Fixed portability by replacing accidentally introduced
uint{8,16,32}_t with the portable uuid_uint{8,16,32}_t.
[Guerry Semones <guerry@tsunamiresearch.com>]
o Prefix all variable symbols in uuid.h with underscores
to avoid namespace conflicts.
[Ralf S. Engelschall]
o Add decoding examples to uuid(1) manual page.
[Ralf S. Engelschall]
Changes between 0.9.0 and 0.9.1 (11-Jan-2004 to 13-Jan-2004)
o Make "md5_init" and "mac_address" symbols namespace clean
by adding correct embedding support via "uuid_" prefix.
[Ralf S. Engelschall]
o Implement uuid_dump() and corresponding uuid CLI "-d"
option for dumping a given UUID into clear text. For convenience
reasons add uuid_bm.h (bit mask API) and uuid_str (string
formatting API) sub-modules.
[Ralf S. Engelschall]
o Add "-m" option to CLI for allowing to generate v1 UUIDs
with random multi-cast addresses (API UUID_MCASTRND option).
[Ralf S. Engelschall]
o Disable the C++ and F77 checks in GNU libtool.
[Ralf S. Engelschall]
o Print involved option character (instead of '?') on invalid
option for uuid(1) CLI.
[Matthias Andree <matthias.andree@gmx.de>]
o Fixed "make install" and "make uninstall": the uuid(1) CLI
has to be [un]installed through GNU libtool, too.
[Matthias Andree <matthias.andree@gmx.de>]
o Document in uuid(1) [uuid_cli.pod] that for version 3
UUIDs additional arguments are required and what pre-defined
namespace ids are known.
[Ralf S. Engelschall, M.Daniel <mdaniel@scdi.com>]
o cleaned up source tree documentation files.
[Ralf S. Engelschall]
+357
View File
@@ -0,0 +1,357 @@
##
## OSSP uuid - Universally Unique Identifier
## Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
## Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
##
## This file is part of OSSP uuid, a library for the generation
## of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
##
## Permission to use, copy, modify, and distribute this software for
## any purpose with or without fee is hereby granted, provided that
## the above copyright notice and this permission notice appear in all
## copies.
##
## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
## SUCH DAMAGE.
##
## Makefile.in: make(1) build procedure
##
@SET_MAKE@
VPATH = @srcdir@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
S = $(srcdir)
C = .
DESTDIR =
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
bindir = @bindir@
libdir = @libdir@
includedir = @includedir@
mandir = @mandir@
CC = @CC@
CXX = @CXX@
CPPFLAGS = -I. -I$(S) @CPPFLAGS@ @DEFS@
CFLAGS = @CFLAGS@
CXXFLAGS = @CXXFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
RM = rm -f
CP = cp
RMDIR = rmdir
SHTOOL = $(S)/shtool
LIBTOOL = $(C)/libtool
TRUE = true
POD2MAN = pod2man
PERL = @PERL@
PHP = @PHP@
PG_CONFIG = @PG_CONFIG@
LIB_NAME = libuuid.la
LIB_OBJS = uuid.lo uuid_md5.lo uuid_sha1.lo uuid_prng.lo uuid_mac.lo uuid_time.lo uuid_ui64.lo uuid_ui128.lo uuid_str.lo
DCE_NAME = libuuid_dce.la
DCE_OBJS = uuid_dce.lo $(LIB_OBJS)
CXX_NAME = libuuid++.la
CXX_OBJS = uuid++.lo $(LIB_OBJS)
PRG_NAME = uuid
PRG_OBJS = uuid_cli.o
MAN_NAME = uuid.3 uuid++.3 uuid.1
PERL_NAME = $(S)/perl/blib/lib/OSSP/uuid.pm
PERL_OBJS = $(S)/perl/uuid.pm
PHP_NAME = $(S)/php/modules/uuid.so
PHP_OBJS = $(S)/php/uuid.c
PGSQL_NAME = $(S)/pgsql/libuuid.so
PGSQL_OBJS = $(S)/pgsql/uuid.c
TARGETS = $(LIB_NAME) @DCE_NAME@ @CXX_NAME@ $(PRG_NAME) @PERL_NAME@ @PHP_NAME@ @PGSQL_NAME@
WITH_DCE = @WITH_DCE@
WITH_CXX = @WITH_CXX@
WITH_PERL = @WITH_PERL@
WITH_PERL_COMPAT = @WITH_PERL_COMPAT@
WITH_PHP = @WITH_PHP@
WITH_PGSQL = @WITH_PGSQL@
.SUFFIXES:
.SUFFIXES: .c .cc .o .lo
all: $(TARGETS)
.c.o:
$(CC) $(CPPFLAGS) $(CFLAGS) -c $<
.cc.o:
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $<
.c.lo:
@$(LIBTOOL) --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS) -c $<
.cc.lo:
@$(LIBTOOL) --mode=compile $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $<
$(LIB_NAME): $(LIB_OBJS)
@$(LIBTOOL) --mode=link $(CC) -o $(LIB_NAME) $(LIB_OBJS) -rpath $(libdir) \
-version-info `$(SHTOOL) version -l c -d libtool $(S)/uuid_vers.h`
$(DCE_NAME): $(DCE_OBJS)
@$(LIBTOOL) --mode=link $(CC) -o $(DCE_NAME) $(DCE_OBJS) -rpath $(libdir) \
-version-info `$(SHTOOL) version -l c -d libtool $(S)/uuid_vers.h`
$(CXX_NAME): $(CXX_OBJS)
@$(LIBTOOL) --mode=link $(CXX) -o $(CXX_NAME) $(CXX_OBJS) -rpath $(libdir) \
-version-info `$(SHTOOL) version -l c -d libtool $(S)/uuid_vers.h`
$(PRG_NAME): $(PRG_OBJS) $(LIB_NAME)
@$(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $(PRG_NAME) $(PRG_OBJS) $(LIB_NAME) $(LIBS)
$(PERL_NAME): $(PERL_OBJS) $(LIB_NAME)
@cd $(S)/perl && $(PERL) Makefile.PL PREFIX=$(prefix) COMPAT=$(WITH_PERL_COMPAT) && $(MAKE) $(MFLAGS) all
@touch $(PERL_NAME)
$(PHP_NAME): $(PHP_OBJS) $(LIB_NAME)
@cd $(S)/php && $(MAKE) $(MFLAGS) -f Makefile.local PHP=$(PHP)
@touch $(PHP_NAME)
$(PGSQL_NAME): $(PGSQL_OBJS) $(LIB_NAME)
@cd $(S)/pgsql && $(MAKE) $(MFLAGS) PG_CONFIG=$(PG_CONFIG)
@touch $(PGSQL_NAME)
uuid.lo: $(S)/uuid.c uuid.h $(S)/uuid_md5.h $(S)/uuid_sha1.h $(S)/uuid_prng.h $(S)/uuid_mac.h $(S)/uuid_ui64.h $(S)/uuid_ui128.h $(S)/uuid_str.h $(S)/uuid_bm.h $(S)/uuid_ac.h
uuid_mac.lo: $(S)/uuid_mac.c $(S)/uuid_mac.h
uuid_md5.lo: $(S)/uuid_md5.c $(S)/uuid_md5.h
uuid_sha1.lo: $(S)/uuid_sha1.c $(S)/uuid_sha1.h
uuid_prng.lo: $(S)/uuid_prng.c $(S)/uuid_prng.h
uuid_str.lo: $(S)/uuid_str.c $(S)/uuid_str.h
uuid_ui64.lo: $(S)/uuid_ui64.c $(S)/uuid_ui64.h
uuid_ui128.lo: $(S)/uuid_ui64.c $(S)/uuid_ui128.h
uuid_dce.lo: $(S)/uuid_dce.c uuid.h $(S)/uuid_dce.h
uuid_cli.o: $(S)/uuid_cli.c uuid.h
uuid++.lo: $(S)/uuid++.cc $(S)/uuid++.hh
man: uuid.3 uuid++.3 uuid-config.1 uuid.1
uuid.3: uuid.pod
V1=`$(SHTOOL) version -l c -d short $(S)/uuid_vers.h`; \
V2=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h`; \
D=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h | sed -e 's;.*(;;' -e 's;).*;;'`; \
$(POD2MAN) --quotes=none \
--section=3 --center="Universally Unique Identifier" \
--release="$$D" --date="OSSP uuid $$V1" $(S)/uuid.pod | \
sed -e "s;UUID_VERSION_STR;$$V2;" >uuid.3
uuid++.3: uuid++.pod
V1=`$(SHTOOL) version -l c -d short $(S)/uuid_vers.h`; \
V2=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h`; \
D=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h | sed -e 's;.*(;;' -e 's;).*;;'`; \
$(POD2MAN) --quotes=none \
--section=3 --center="Universally Unique Identifier" \
--release="$$D" --date="OSSP uuid $$V1" $(S)/uuid++.pod | \
sed -e "s;UUID_VERSION_STR;$$V2;" >uuid++.3
uuid-config.1: uuid-config.pod
V1=`$(SHTOOL) version -l c -d short $(S)/uuid_vers.h`; \
V2=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h`; \
D=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h | sed -e 's;.*(;;' -e 's;).*;;'`; \
$(POD2MAN) --quotes=none \
--section=1 --center="Universally Unique Identifier" \
--release="$$D" --date="OSSP uuid $$V1" $(S)/uuid-config.pod | \
sed -e "s;UUID_VERSION_STR;$$V2;" >uuid-config.1
uuid.1: uuid_cli.pod
V1=`$(SHTOOL) version -l c -d short $(S)/uuid_vers.h`; \
V2=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h`; \
D=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h | sed -e 's;.*(;;' -e 's;).*;;'`; \
$(CP) $(S)/uuid_cli.pod /tmp/uuid.pod; \
$(POD2MAN) --quotes=none \
--section=1 --center="Universally Unique Identifier" \
--release="$$D" --date="OSSP uuid $$V1" /tmp/uuid.pod | \
sed -e "s;UUID_VERSION_STR;$$V2;" >uuid.1; \
$(RM) /tmp/uuid.pod
check: all
@echo "==== UUID version 1 (time and node based): 4 single iterations"; \
$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v1 -n 4 -1
@echo "==== UUID version 1 (time and node based): 4 subsequent iterations"; \
$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v1 -n 4
@echo "==== UUID version 3 (name based, MD5): 2 times repeated"; \
$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v3 -n 2 ns:URL http://www.ossp.org/
@echo "==== UUID version 5 (name based, SHA-1): 2 times repeated"; \
$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v5 -n 2 ns:URL http://www.ossp.org/
@echo "==== UUID version 4 (random data based): 4 single iterations"; \
$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v4 -n 4 -1
@echo "==== UUID version 4 (random data based): 4 subsequent iterations"; \
$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v4 -n 4
@echo "==== UUID version 1 generation and decoding"; \
$(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v1`; \
$(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v1 -m`
@echo "==== UUID version 3 generation and decoding"; \
$(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v3 ns:URL http://www.ossp.org/`
@echo "==== UUID version 5 generation and decoding"; \
$(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v5 ns:URL http://www.ossp.org/`
@echo "==== UUID version 3 generation and decoding"; \
$(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v4`
-@if [ ".$(WITH_PERL)" = .yes ]; then \
echo "==== Perl bindings to C API"; \
(cd $(S)/perl && $(MAKE) $(MFLAGS) test); \
fi
-@if [ ".$(WITH_PHP)" = .yes ]; then \
echo "==== PHP bindings to C API"; \
(cd $(S)/php && $(MAKE) $(MFLAGS) -f Makefile.local test PHP=$(PHP)); \
fi
-@if [ ".$(WITH_PGSQL)" = .yes ]; then \
echo "==== PGSQL bindings to C API"; \
(cd $(S)/pgsql && $(MAKE) $(MFLAGS) test PG_CONFIG=$(PG_CONFIG)); \
fi
.PHONY: install
install:
$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(prefix)
$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(bindir)
$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(includedir)
$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(libdir)/pkgconfig
$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(mandir)/man3
$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(mandir)/man1
$(SHTOOL) install -c -m 755 uuid-config $(DESTDIR)$(bindir)/
$(SHTOOL) install -c -m 644 $(S)/uuid-config.1 $(DESTDIR)$(mandir)/man1/
$(SHTOOL) install -c -m 644 $(S)/uuid.pc $(DESTDIR)$(libdir)/pkgconfig/
$(SHTOOL) install -c -m 644 uuid.h $(DESTDIR)$(includedir)/
-@if [ ".$(WITH_DCE)" = .yes ]; then \
echo "$(SHTOOL) install -c -m 644 $(S)/uuid_dce.h $(DESTDIR)$(includedir)/"; \
$(SHTOOL) install -c -m 644 $(S)/uuid_dce.h $(DESTDIR)$(includedir)/; \
fi
-@if [ ".$(WITH_CXX)" = .yes ]; then \
echo "$(SHTOOL) install -c -m 644 $(S)/uuid++.hh $(DESTDIR)$(includedir)/"; \
$(SHTOOL) install -c -m 644 $(S)/uuid++.hh $(DESTDIR)$(includedir)/; \
fi
$(SHTOOL) install -c -m 644 $(S)/uuid.3 $(DESTDIR)$(mandir)/man3/
-@if [ ".$(WITH_CXX)" = .yes ]; then \
echo "$(SHTOOL) install -c -m 644 $(S)/uuid++.3 $(DESTDIR)$(mandir)/man3/"; \
$(SHTOOL) install -c -m 644 $(S)/uuid++.3 $(DESTDIR)$(mandir)/man3/; \
fi
@$(LIBTOOL) --mode=install $(SHTOOL) install -c -m 644 $(LIB_NAME) $(DESTDIR)$(libdir)/
-@if [ ".$(WITH_DCE)" = .yes ]; then \
$(LIBTOOL) --mode=install $(SHTOOL) install -c -m 644 $(DCE_NAME) $(DESTDIR)$(libdir)/; \
fi
-@if [ ".$(WITH_CXX)" = .yes ]; then \
$(LIBTOOL) --mode=install $(SHTOOL) install -c -m 644 $(CXX_NAME) $(DESTDIR)$(libdir)/; \
fi
@$(LIBTOOL) --mode=install $(SHTOOL) install -c -s -m 755 uuid $(DESTDIR)$(bindir)/
$(SHTOOL) install -c -m 644 $(S)/uuid.1 $(DESTDIR)$(mandir)/man1/
-@if [ ".$(WITH_PERL)" = .yes ]; then \
(cd $(S)/perl && $(MAKE) $(MFLAGS) install DESTDIR=$(DESTDIR)); \
fi
-@if [ ".$(WITH_PHP)" = .yes ]; then \
(cd $(S)/php && $(MAKE) $(MFLAGS) -f Makefile.local install EXTDIR=$(prefix)/lib/php PHP=$(PHP) DESTDIR=$(DESTDIR)); \
fi
-@if [ ".$(WITH_PGSQL)" = .yes ]; then \
(cd $(S)/pgsql && $(MAKE) $(MFLAGS) install DESTDIR=$(DESTDIR) PG_CONFIG=$(PG_CONFIG)); \
fi
.PHONY: uninstall
uninstall:
-$(RM) $(DESTDIR)$(mandir)/man1/uuid.1
-@$(LIBTOOL) --mode=uninstall $(RM) $(DESTDIR)$(bindir)/uuid
-@$(LIBTOOL) --mode=uninstall $(RM) $(DESTDIR)$(libdir)/$(LIB_NAME)
-@if [ ".$(WITH_DCE)" = .yes ]; then \
$(LIBTOOL) --mode=uninstall $(RM) $(DESTDIR)$(libdir)/$(DCE_NAME); \
fi
-@if [ ".$(WITH_CXX)" = .yes ]; then \
$(LIBTOOL) --mode=uninstall $(RM) $(DESTDIR)$(libdir)/$(CXX_NAME); \
fi
-$(RM) $(DESTDIR)$(mandir)/man3/uuid.3
-@if [ ".$(WITH_CXX)" = .yes ]; then \
echo "$(RM) $(DESTDIR)$(mandir)/man3/uuid++.3"; \
$(RM) $(DESTDIR)$(mandir)/man3/uuid++.3; \
fi
-$(RM) $(DESTDIR)$(includedir)/uuid.h
-@if [ ".$(WITH_DCE)" = .yes ]; then \
echo "$(RM) $(DESTDIR)$(includedir)/uuid_dce.h"; \
$(RM) $(DESTDIR)$(includedir)/uuid_dce.h; \
fi
-@if [ ".$(WITH_CXX)" = .yes ]; then \
echo "$(RM) $(DESTDIR)$(includedir)/uuid++.hh"; \
$(RM) $(DESTDIR)$(includedir)/uuid++.hh; \
fi
-$(RM) $(DESTDIR)$(libdir)/pkgconfig/uuid.pc
-$(RM) $(DESTDIR)$(mandir)/man1/uuid-config.1
-$(RM) $(DESTDIR)$(bindir)/uuid-config
-$(RMDIR) $(DESTDIR)$(mandir)/man1 >/dev/null 2>&1 || $(TRUE)
-$(RMDIR) $(DESTDIR)$(mandir)/man3 >/dev/null 2>&1 || $(TRUE)
-$(RMDIR) $(DESTDIR)$(mandir) >/dev/null 2>&1 || $(TRUE)
-$(RMDIR) $(DESTDIR)$(libdir)/pkgconfig >/dev/null 2>&1 || $(TRUE)
-$(RMDIR) $(DESTDIR)$(libdir) >/dev/null 2>&1 || $(TRUE)
-$(RMDIR) $(DESTDIR)$(includedir) >/dev/null 2>&1 || $(TRUE)
-$(RMDIR) $(DESTDIR)$(bindir) >/dev/null 2>&1 || $(TRUE)
-$(RMDIR) $(DESTDIR)$(prefix) >/dev/null 2>&1 || $(TRUE)
.PHONY: clean
clean:
-$(RM) $(LIB_NAME) $(LIB_OBJS)
-@if [ ".$(WITH_DCE)" = .yes ]; then \
echo "$(RM) $(DCE_NAME) $(DCE_OBJS)"; \
$(RM) $(DCE_NAME) $(DCE_OBJS); \
fi
-@if [ ".$(WITH_CXX)" = .yes ]; then \
echo "$(RM) $(CXX_NAME) $(CXX_OBJS)"; \
$(RM) $(CXX_NAME) $(CXX_OBJS); \
fi
-$(RM) $(PRG_NAME) $(PRG_OBJS)
-$(RM) -r .libs >/dev/null 2>&1 || $(TRUE)
-$(RM) *.o *.lo
-@if [ ".$(WITH_PERL)" = .yes ]; then \
(cd $(S)/perl && $(MAKE) $(MFLAGS) clean || true); \
fi
-@if [ ".$(WITH_PHP)" = .yes ]; then \
(cd $(S)/php && $(MAKE) $(MFLAGS) -f Makefile.local clean || true); \
fi
-@if [ ".$(WITH_PGSQL)" = .yes ]; then \
(cd $(S)/pgsql && $(MAKE) $(MFLAGS) clean PG_CONFIG=$(PG_CONFIG) || true); \
fi
distclean: clean
-$(RM) config.log config.status config.cache
-$(RM) Makefile config.h uuid-config uuid.h uuid.pc
-$(RM) libtool
-@if [ ".$(WITH_PERL)" = .yes ]; then \
(cd $(S)/perl && $(MAKE) $(MFLAGS) distclean || true; rm -f Makefile.old); \
fi
-@if [ ".$(WITH_PHP)" = .yes ]; then \
(cd $(S)/php && $(MAKE) $(MFLAGS) -f Makefile.local distclean || true); \
fi
-@if [ ".$(WITH_PGSQL)" = .yes ]; then \
(cd $(S)/pgsql && $(MAKE) $(MFLAGS) distclean PG_CONFIG=$(PG_CONFIG) || true); \
fi
realclean: distclean
-$(RM) uuid.3 uuid.1
-$(RM) configure config.h.in
-$(RM) shtool
-$(RM) ltmain.sh libtool.m4 config.guess config.sub
-@if [ ".$(WITH_PERL)" = .yes ]; then \
(cd $(S)/perl && $(MAKE) $(MFLAGS) realclean || true; rm -f Makefile.old); \
fi
-@if [ ".$(WITH_PHP)" = .yes ]; then \
(cd $(S)/php && $(MAKE) $(MFLAGS) -f Makefile.local realclean || true); \
fi
-@if [ ".$(WITH_PGSQL)" = .yes ]; then \
(cd $(S)/pgsql && $(MAKE) $(MFLAGS) realclean PG_CONFIG=$(PG_CONFIG) || true); \
fi
+352
View File
@@ -0,0 +1,352 @@
dnl ##
dnl ## SA - OSSP Socket Abstraction Library
dnl ## Copyright (c) 2001-2003 Ralf S. Engelschall <rse@engelschall.com>
dnl ## Copyright (c) 2001-2003 The OSSP Project <http://www.ossp.org/>
dnl ## Copyright (c) 2001-2003 Cable & Wireless Deutschland <http://www.cw.com/de/>
dnl ##
dnl ## This file is part of OSSP SA, a socket abstraction library which
dnl ## can be found at http://www.ossp.org/pkg/sa/.
dnl ##
dnl ## Permission to use, copy, modify, and distribute this software for
dnl ## any purpose with or without fee is hereby granted, provided that
dnl ## the above copyright notice and this permission notice appear in all
dnl ## copies.
dnl ##
dnl ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
dnl ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
dnl ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dnl ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dnl ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
dnl ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
dnl ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
dnl ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
dnl ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
dnl ## SUCH DAMAGE.
dnl ##
dnl ## aclocal.m4: GNU Autoconf local macro definitions
dnl ##
dnl ##
dnl ## Check whether compiler option works
dnl ##
dnl ## configure.in:
dnl ## AC_COMPILER_OPTION(<name>, <display>, <option>,
dnl ## <action-success>, <action-failure>)
dnl ##
AC_DEFUN(AC_COMPILER_OPTION,[dnl
AC_MSG_CHECKING(whether compiler option(s) $2 work)
AC_CACHE_VAL(ac_cv_compiler_option_$1,[
SAVE_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $3"
AC_TRY_COMPILE([],[], ac_cv_compiler_option_$1=yes, ac_cv_compiler_option_$1=no)
CFLAGS="$SAVE_CFLAGS"
])dnl
if test ".$ac_cv_compiler_option_$1" = .yes; then
ifelse([$4], , :, [$4])
else
ifelse([$5], , :, [$5])
fi
AC_MSG_RESULT([$ac_cv_compiler_option_$1])
])dnl
dnl ##
dnl ## Debugging Support
dnl ##
dnl ## configure.in:
dnl ## AC_CHECK_DEBUGGING
dnl ##
AC_DEFUN(AC_CHECK_DEBUGGING,[dnl
AC_ARG_ENABLE(debug,dnl
[ --enable-debug build for debugging (default=no)],
[dnl
if test ".$ac_cv_prog_gcc" = ".yes"; then
case "$CFLAGS" in
*-O* ) ;;
* ) CFLAGS="$CFLAGS -O2" ;;
esac
case "$CFLAGS" in
*-g* ) ;;
* ) CFLAGS="$CFLAGS -g" ;;
esac
case "$CFLAGS" in
*-pipe* ) ;;
* ) AC_COMPILER_OPTION(pipe, -pipe, -pipe, CFLAGS="$CFLAGS -pipe") ;;
esac
AC_COMPILER_OPTION(defdbg, -DDEBUG, -DDEBUG, CFLAGS="$CFLAGS -DDEBUG")
CFLAGS="$CFLAGS -pedantic"
CFLAGS="$CFLAGS -Wall"
WMORE="-Wshadow -Wpointer-arith -Wcast-align -Winline"
WMORE="$WMORE -Wmissing-prototypes -Wmissing-declarations -Wnested-externs"
AC_COMPILER_OPTION(wmore, -W<xxx>, $WMORE, CFLAGS="$CFLAGS $WMORE")
AC_COMPILER_OPTION(wnolonglong, -Wno-long-long, -Wno-long-long, CFLAGS="$CFLAGS -Wno-long-long")
else
case "$CFLAGS" in
*-g* ) ;;
* ) CFLAGS="$CFLAGS -g" ;;
esac
fi
msg="enabled"
],[
if test ".$ac_cv_prog_gcc" = ".yes"; then
case "$CFLAGS" in
*-pipe* ) ;;
* ) AC_COMPILER_OPTION(pipe, -pipe, -pipe, CFLAGS="$CFLAGS -pipe") ;;
esac
fi
case "$CFLAGS" in
*-g* ) CFLAGS=`echo "$CFLAGS" |\
sed -e 's/ -g / /g' -e 's/ -g$//' -e 's/^-g //g' -e 's/^-g$//'` ;;
esac
case "$CXXFLAGS" in
*-g* ) CXXFLAGS=`echo "$CXXFLAGS" |\
sed -e 's/ -g / /g' -e 's/ -g$//' -e 's/^-g //g' -e 's/^-g$//'` ;;
esac
msg=disabled
])dnl
AC_MSG_CHECKING(for compilation debug mode)
AC_MSG_RESULT([$msg])
if test ".$msg" = .enabled; then
enable_shared=no
fi
])
dnl ##
dnl ## Check for C99 va_copy() implementation
dnl ## (and provide fallback implementation if neccessary)
dnl ##
dnl ## configure.in:
dnl ## AC_CHECK_VA_COPY
dnl ## foo.c:
dnl ## #include "config.h"
dnl ## [...]
dnl ## va_copy(d,s)
dnl ##
dnl ## This check is rather complex: first because we really have to
dnl ## try various possible implementations in sequence and second, we
dnl ## cannot define a macro in config.h with parameters directly.
dnl ##
dnl # test program for va_copy() implementation
changequote(<<,>>)
m4_define(__va_copy_test, <<[
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#define DO_VA_COPY(d, s) $1
void test(char *str, ...)
{
va_list ap, ap2;
int i;
va_start(ap, str);
DO_VA_COPY(ap2, ap);
for (i = 1; i <= 9; i++) {
int k = (int)va_arg(ap, int);
if (k != i)
abort();
}
DO_VA_COPY(ap, ap2);
for (i = 1; i <= 9; i++) {
int k = (int)va_arg(ap, int);
if (k != i)
abort();
}
va_end(ap);
}
int main(int argc, char *argv[])
{
test("test", 1, 2, 3, 4, 5, 6, 7, 8, 9);
exit(0);
}
]>>)
changequote([,])
dnl # test driver for va_copy() implementation
m4_define(__va_copy_check, [
AH_VERBATIM($1,
[/* Predefined possible va_copy() implementation (id: $1) */
#define __VA_COPY_USE_$1(d, s) $2])
if test ".$ac_cv_va_copy" = .; then
AC_TRY_RUN(__va_copy_test($2), [ac_cv_va_copy="$1"])
fi
])
dnl # Autoconf check for va_copy() implementation checking
AC_DEFUN(AC_CHECK_VA_COPY,[
dnl # provide Autoconf display check message
AC_MSG_CHECKING(for va_copy() function)
dnl # check for various implementations in priorized sequence
AC_CACHE_VAL(ac_cv_va_copy, [
ac_cv_va_copy=""
dnl # 1. check for standardized C99 macro
__va_copy_check(C99, [va_copy((d), (s))])
dnl # 2. check for alternative/deprecated GCC macro
__va_copy_check(GCM, [VA_COPY((d), (s))])
dnl # 3. check for internal GCC macro (high-level define)
__va_copy_check(GCH, [__va_copy((d), (s))])
dnl # 4. check for internal GCC macro (built-in function)
__va_copy_check(GCB, [__builtin_va_copy((d), (s))])
dnl # 5. check for assignment approach (assuming va_list is a struct)
__va_copy_check(ASS, [do { (d) = (s); } while (0)])
dnl # 6. check for assignment approach (assuming va_list is a pointer)
__va_copy_check(ASP, [do { *(d) = *(s); } while (0)])
dnl # 7. check for memory copying approach (assuming va_list is a struct)
__va_copy_check(CPS, [memcpy((void *)&(d), (void *)&(s), sizeof((s)))])
dnl # 8. check for memory copying approach (assuming va_list is a pointer)
__va_copy_check(CPP, [memcpy((void *)(d), (void *)(s), sizeof(*(s)))])
if test ".$ac_cv_va_copy" = .; then
AC_ERROR([no working implementation found])
fi
])
dnl # optionally activate the fallback implementation
if test ".$ac_cv_va_copy" = ".C99"; then
AC_DEFINE(HAVE_VA_COPY, 1, [Define if va_copy() macro exists (and no fallback implementation is required)])
fi
dnl # declare which fallback implementation to actually use
AC_DEFINE_UNQUOTED([__VA_COPY_USE], [__VA_COPY_USE_$ac_cv_va_copy],
[Define to id of used va_copy() implementation])
dnl # provide activation hook for fallback implementation
AH_VERBATIM([__VA_COPY_ACTIVATION],
[/* Optional va_copy() implementation activation */
#ifndef HAVE_VA_COPY
#define va_copy(d, s) __VA_COPY_USE(d, s)
#endif
])
dnl # provide Autoconf display result message
if test ".$ac_cv_va_copy" = ".C99"; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no (using fallback implementation)])
fi
])
dnl ##
dnl ## Check for an external/extension library.
dnl ## - is aware of <libname>-config style scripts
dnl ## - searches under standard paths include, lib, etc.
dnl ## - searches under subareas like .libs, etc.
dnl ##
dnl ## configure.in:
dnl ## AC_CHECK_EXTLIB(<realname>, <libname>, <func>, <header>,
dnl ## [<success-action> [, <fail-action>]])
dnl ## Makefile.in:
dnl ## CFLAGS = @CFLAGS@
dnl ## LDFLAGS = @LDFLAGS@
dnl ## LIBS = @LIBS@
dnl ## shell:
dnl ## $ ./configure --with-<libname>[=DIR]
dnl ##
AC_DEFUN(AC_CHECK_EXTLIB,[dnl
AC_ARG_WITH($2, [dnl
[ --with-]m4_substr([$2[[=DIR]] ], 0, 19)[build with external $1 library (default=no)]], [dnl
if test ".$with_$2" = .yes; then
# via config script in PATH
$2_version=`($2-config --version) 2>/dev/null`
if test ".$$2_version" != .; then
CPPFLAGS="$CPPFLAGS `$2-config --cflags`"
CFLAGS="$CFLAGS `$2-config --cflags`"
LDFLAGS="$LDFLAGS `$2-config --ldflags`"
fi
else
if test -d "$with_$2"; then
found=0
# via config script
for dir in $with_$2/bin $with_$2; do
if test -f "$dir/$2-config" && test ! -f "$dir/$2-config.in"; then
$2_version=`($dir/$2-config --version) 2>/dev/null`
if test ".$$2_version" != .; then
CPPFLAGS="$CPPFLAGS `$dir/$2-config --cflags`"
CFLAGS="$CFLAGS `$dir/$2-config --cflags`"
LDFLAGS="$LDFLAGS `$dir/$2-config --ldflags`"
found=1
break
fi
fi
done
# in standard sub-areas
if test ".$found" = .0; then
for dir in $with_$2/include/$2 $with_$2/include $with_$2; do
if test -f "$dir/$4"; then
CPPFLAGS="$CPPFLAGS -I$dir"
CFLAGS="$CFLAGS -I$dir"
found=1
break
fi
done
for dir in $with_$2/lib/$2 $with_$2/lib $with_$2; do
if test -f "$dir/lib$2.la" && test -d "$dir/.libs"; then
LDFLAGS="$LDFLAGS -L$dir -L$dir/.libs"
found=1
break
elif test -f "$dir/lib$2.a" || test -f "$dir/lib$2.so"; then
LDFLAGS="$LDFLAGS -L$dir"
found=1
break
fi
done
fi
# in any sub-area
if test ".$found" = .0; then
changequote(, )dnl
for file in x `find $with_$2 -name "$4" -type f -print`; do
test .$file = .x && continue
dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'`
CPPFLAGS="$CPPFLAGS -I$dir"
CFLAGS="$CFLAGS -I$dir"
done
for file in x `find $with_$2 -name "lib$2.[aso]" -type f -print`; do
test .$file = .x && continue
dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'`
LDFLAGS="$LDFLAGS -L$dir"
done
changequote([, ])dnl
fi
fi
fi
AC_HAVE_HEADERS($4)
AC_CHECK_LIB($2, $3)
with_$2=yes
ac_var="ac_cv_header_`echo $4 | sed 'y%./+-%__p_%'`"
eval "ac_val=\$$ac_var"
if test ".$ac_val" != .yes; then
with_$2=no
fi
if test ".$ac_cv_lib_$2_$3" != .yes; then
with_$2=no
fi
if test ".$with_$2" = .no; then
AC_ERROR([Unable to find $1 library])
fi
], [dnl
if test ".$with_$2" = .; then
with_$2=no
fi
])dnl
AC_MSG_CHECKING(whether to build against external $1 library)
if test ".$with_$2" = .yes; then
ifelse([$5], , :, [$5])
else
ifelse([$6], , :, [$6])
fi
AC_MSG_RESULT([$with_$2])
])dnl
dnl ##
dnl ## Check whether to activate Dmalloc
dnl ##
dnl ## configure.in:
dnl ## AC_CHECK_DMALLOC
dnl ##
AC_DEFUN(AC_CHECK_DMALLOC,[dnl
AC_CHECK_EXTLIB(Dmalloc, dmalloc, dmalloc_debug, dmalloc.h,
AC_DEFINE(WITH_DMALLOC, 1, [define if building with Dmalloc]))
if test ".$with_dmalloc" = .yes; then
CFLAGS=`echo "X$CFLAGS" | sed -e 's;^X;;' -e 's; -Wredundant-decls;;'`
fi
])dnl
+216
View File
@@ -0,0 +1,216 @@
/* config.h.in. Generated from configure.ac by autoheader. */
/* Predefined possible va_copy() implementation (id: ASP) */
#define __VA_COPY_USE_ASP(d, s) do { *(d) = *(s); } while (0)
/* Predefined possible va_copy() implementation (id: ASS) */
#define __VA_COPY_USE_ASS(d, s) do { (d) = (s); } while (0)
/* Predefined possible va_copy() implementation (id: C99) */
#define __VA_COPY_USE_C99(d, s) va_copy((d), (s))
/* Predefined possible va_copy() implementation (id: CPP) */
#define __VA_COPY_USE_CPP(d, s) memcpy((void *)(d), (void *)(s), sizeof(*(s)))
/* Predefined possible va_copy() implementation (id: CPS) */
#define __VA_COPY_USE_CPS(d, s) memcpy((void *)&(d), (void *)&(s), sizeof((s)))
/* Predefined possible va_copy() implementation (id: GCB) */
#define __VA_COPY_USE_GCB(d, s) __builtin_va_copy((d), (s))
/* Predefined possible va_copy() implementation (id: GCH) */
#define __VA_COPY_USE_GCH(d, s) __va_copy((d), (s))
/* Predefined possible va_copy() implementation (id: GCM) */
#define __VA_COPY_USE_GCM(d, s) VA_COPY((d), (s))
/* Define to 1 if you have the <arpa/inet.h> header file. */
#undef HAVE_ARPA_INET_H
/* Define to 1 if you have the `clock_gettime' function. */
#undef HAVE_CLOCK_GETTIME
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the <dmalloc.h> header file. */
#undef HAVE_DMALLOC_H
/* Define to 1 if you have the `getifaddrs' function. */
#undef HAVE_GETIFADDRS
/* Define to 1 if you have the `gettimeofday' function. */
#undef HAVE_GETTIMEOFDAY
/* Define to 1 if you have the <ifaddrs.h> header file. */
#undef HAVE_IFADDRS_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `dmalloc' library (-ldmalloc). */
#undef HAVE_LIBDMALLOC
/* Define to 1 if you have the `nsl' library (-lnsl). */
#undef HAVE_LIBNSL
/* Define to 1 if you have the `socket' library (-lsocket). */
#undef HAVE_LIBSOCKET
/* Define to 1 if the system has the type `long double'. */
#undef HAVE_LONG_DOUBLE
/* Define to 1 if the system has the type `long long'. */
#undef HAVE_LONG_LONG
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `nanosleep' function. */
#undef HAVE_NANOSLEEP
/* Define to 1 if you have the <netdb.h> header file. */
#undef HAVE_NETDB_H
/* Define to 1 if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H
/* Define to 1 if you have the <net/if_arp.h> header file. */
#undef HAVE_NET_IF_ARP_H
/* Define to 1 if you have the <net/if_dl.h> header file. */
#undef HAVE_NET_IF_DL_H
/* Define to 1 if you have the <net/if.h> header file. */
#undef HAVE_NET_IF_H
/* Define to 1 if you have the `Sleep' function. */
#undef HAVE_SLEEP
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* define if exists "struct timeval" */
#undef HAVE_STRUCT_TIMEVAL
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
/* Define to 1 if you have the <sys/param.h> header file. */
#undef HAVE_SYS_PARAM_H
/* Define to 1 if you have the <sys/select.h> header file. */
#undef HAVE_SYS_SELECT_H
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the <sys/sockio.h> header file. */
#undef HAVE_SYS_SOCKIO_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define if va_copy() macro exists (and no fallback implementation is
required) */
#undef HAVE_VA_COPY
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#undef LT_OBJDIR
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* The size of `char', as computed by sizeof. */
#undef SIZEOF_CHAR
/* The size of `int', as computed by sizeof. */
#undef SIZEOF_INT
/* The size of `long', as computed by sizeof. */
#undef SIZEOF_LONG
/* The size of `long long', as computed by sizeof. */
#undef SIZEOF_LONG_LONG
/* The size of `short', as computed by sizeof. */
#undef SIZEOF_SHORT
/* The size of `unsigned char', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_CHAR
/* The size of `unsigned int', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_INT
/* The size of `unsigned long', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_LONG
/* The size of `unsigned long long', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_LONG_LONG
/* The size of `unsigned short', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_SHORT
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* whether to build C++ bindings to C API */
#undef WITH_CXX
/* whether to build DCE 1.1 backward compatibility API */
#undef WITH_DCE
/* define if building with Dmalloc */
#undef WITH_DMALLOC
/* whether to build Perl bindings to C API */
#undef WITH_PERL
/* whether to build Perl compatibility API */
#undef WITH_PERL_COMPAT
/* whether to build PostgreSQL bindings to C API */
#undef WITH_PGSQL
/* whether to build PHP bindings to C API */
#undef WITH_PHP
/* Optional va_copy() implementation activation */
#ifndef HAVE_VA_COPY
#define va_copy(d, s) __VA_COPY_USE(d, s)
#endif
/* Define to id of used va_copy() implementation */
#undef __VA_COPY_USE
+57
View File
@@ -0,0 +1,57 @@
dnl ##
dnl ## OSSP uuid - Universally Unique Identifier
dnl ## Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
dnl ## Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
dnl ##
dnl ## This file is part of OSSP uuid, a library for the generation
dnl ## of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
dnl ##
dnl ## Permission to use, copy, modify, and distribute this software for
dnl ## any purpose with or without fee is hereby granted, provided that
dnl ## the above copyright notice and this permission notice appear in all
dnl ## copies.
dnl ##
dnl ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
dnl ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
dnl ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dnl ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dnl ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
dnl ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
dnl ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
dnl ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
dnl ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
dnl ## SUCH DAMAGE.
dnl ##
dnl ## configure.ac: GNU Autoconf source script
dnl ##
AC_PREREQ(2.53)
AC_INIT
UUID_VERSION_RAW=`$ac_confdir/shtool version -l c -d short uuid_vers.h`
UUID_VERSION_STR=`$ac_confdir/shtool version -l c -d long uuid_vers.h`
UUID_VERSION_HEX=`$ac_confdir/shtool version -l c -d hex uuid_vers.h`
$ac_confdir/shtool echo -e \
"Configuring %BOSSP uuid%b (Universally Unique Identifier), version %B${UUID_VERSION_STR}%b"
AC_SUBST(UUID_VERSION_RAW)
AC_SUBST(UUID_VERSION_STR)
AC_SUBST(UUID_VERSION_HEX)
AC_PROG_MAKE_SET
AC_PROG_CC
AC_CHECK_DEBUGGING
AC_CHECK_DMALLOC
with_tags=""
sinclude(libtool.m4)
AC_PROG_LIBTOOL
sinclude(uuid.ac)
UUID_CHECK_ALL
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_FILES([Makefile uuid-config uuid.pc uuid.h])
AC_CONFIG_COMMANDS([adjustment], [chmod a-w uuid.h; chmod a+x uuid-config])
AC_OUTPUT
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+236
View File
@@ -0,0 +1,236 @@
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.07)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C`
. ds C'
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.ie \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.el \{\
. de IX
..
.\}
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "UUID-CONFIG 1"
.TH UUID-CONFIG 1 "OSSP uuid 1.6.2" "04-Jul-2008" "Universally Unique Identifier"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
\&\fBuuid-config\fR \- \fB\s-1OSSP\s0 uuid \s-1API\s0 build utility\fR
.SH "VERSION"
.IX Header "VERSION"
\&\s-1OSSP\s0 uuid \s-11.6.2 (04-Jul-2008)\s0
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
\&\fBuuid-config\fR
[\fB\-\-help\fR]
[\fB\-\-version\fR]
[\fB\-\-all\fR]
[\fB\-\-prefix\fR]
[\fB\-\-exec\-prefix\fR]
[\fB\-\-bindir\fR]
[\fB\-\-libdir\fR]
[\fB\-\-includedir\fR]
[\fB\-\-mandir\fR]
[\fB\-\-datadir\fR]
[\fB\-\-acdir\fR]
[\fB\-\-cflags\fR]
[\fB\-\-ldflags\fR]
[\fB\-\-libs\fR]
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The \fBuuid-config\fR program is a little helper utility for easy configuring and
building applications based on the \fIuuid\fR\|(3) library. It can be used to query the
C compiler and linker flags which are required to correctly compile and link
the application against the \fIuuid\fR\|(3) library.
.SH "OPTIONS"
.IX Header "OPTIONS"
\&\fBuuid-config\fR accepts the following options:
.IP "\fB\-\-help\fR" 2
.IX Item "--help"
Prints the short usage information.
.IP "\fB\-\-version\fR" 2
.IX Item "--version"
Prints the version number and date of the installed \fIuuid\fR\|(3) library.
.IP "\fB\-\-all\fR" 2
.IX Item "--all"
Forces the output of all flags, that is, including extra flags which are not
\&\fB\s-1OSSP\s0 uuid\fR specific.
.IP "\fB\-\-prefix\fR" 2
.IX Item "--prefix"
Prints the installation prefix of architecture independent files
.IP "\fB\-\-exec\-prefix\fR" 2
.IX Item "--exec-prefix"
Prints the installation prefix of architecture dependent files.
.IP "\fB\-\-bindir\fR" 2
.IX Item "--bindir"
Prints the installation directory of binaries.
.IP "\fB\-\-libdir\fR" 2
.IX Item "--libdir"
Prints the installation directory of libraries.
.IP "\fB\-\-includedir\fR" 2
.IX Item "--includedir"
Prints the installation directory of include headers.
.IP "\fB\-\-mandir\fR" 2
.IX Item "--mandir"
Prints the installation directory of manual pages.
.IP "\fB\-\-datadir\fR" 2
.IX Item "--datadir"
Prints the installation directory of shared data.
.IP "\fB\-\-acdir\fR" 2
.IX Item "--acdir"
Prints the installation directory of \fBautoconf\fR data.
.IP "\fB\-\-cflags\fR" 2
.IX Item "--cflags"
Prints the C compiler flags which are needed to compile the \fIuuid\fR\|(3)\-based
application. The output is usually added to the \f(CW\*(C`CFLAGS\*(C'\fR uuidiable of the
applications \f(CW\*(C`Makefile\*(C'\fR.
.IP "\fB\-\-ldflags\fR" 2
.IX Item "--ldflags"
Prints the linker flags (\f(CW\*(C`\-L\*(C'\fR) which are needed to link the application with
the \fIuuid\fR\|(3) library. The output is usually added to the \f(CW\*(C`LDFLAGS\*(C'\fR uuidiable of
the applications \f(CW\*(C`Makefile\*(C'\fR.
.IP "\fB\-\-libs\fR" 2
.IX Item "--libs"
Prints the library flags (\f(CW\*(C`\-l\*(C'\fR) which are needed to link the application with
the C \fIuuid\fR\|(3) library. The output is usually added to the \f(CW\*(C`LIBS\*(C'\fR uuidiable of the
applications \f(CW\*(C`Makefile\*(C'\fR.
.SH "EXAMPLE"
.IX Header "EXAMPLE"
.Vb 4
\& CC = cc
\& CFLAGS = \-O \`uuid\-config \-\-cflags\`
\& LDFLAGS = \`uuid\-config \-\-ldflags\`
\& LIBS = \-lm \`uuid\-config \-\-libs\`
\&
\& all: foo
\& foo: foo.o
\& $(CC) $(LDFLAGS) \-o foo foo.o $(LIBS)
\& foo.o: foo.c
\& $(CC) $(CFLAGS) \-c foo.c
.Ve
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\fIuuid\fR\|(3), \fIuuid\fR\|(1), \fIOSSP::uuid\fR\|(3).
+145
View File
@@ -0,0 +1,145 @@
#!/bin/sh
##
## OSSP uuid - Universally Unique Identifier
## Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
## Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
##
## This file is part of OSSP uuid, a library for the generation
## of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
##
## Permission to use, copy, modify, and distribute this software for
## any purpose with or without fee is hereby granted, provided that
## the above copyright notice and this permission notice appear in all
## copies.
##
## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
## SUCH DAMAGE.
##
## uuid-config.in: library build utility
##
DIFS='
'
prefix="@prefix@"
exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@"
uuid_prefix="$prefix"
uuid_exec_prefix="$exec_prefix"
uuid_bindir="@bindir@"
uuid_libdir="@libdir@"
uuid_includedir="@includedir@"
uuid_mandir="@mandir@"
uuid_datadir="@datadir@"
uuid_acdir="@datadir@/aclocal"
uuid_cflags="@CFLAGS@"
uuid_ldflags="@LDFLAGS@"
uuid_libs="@LIBS@"
uuid_version="@UUID_VERSION_STR@"
help=no
version=no
usage="uuid-config"
usage="$usage [--help] [--version] [--all]"
usage="$usage [--prefix] [--exec-prefix] [--bindir] [--libdir] [--includedir] [--mandir] [--datadir] [--acdir]"
usage="$usage [--cflags] [--ldflags] [--libs]"
if [ $# -eq 0 ]; then
echo "uuid-config:Error: Invalid option" 1>&2
echo "uuid-config:Usage: $usage" 1>&2
exit 1
fi
output=''
output_extra=''
all=no
prev=''
OIFS="$IFS" IFS="$DIFS"
for option
do
if [ ".$prev" != . ]; then
eval "$prev=\$option"
prev=''
continue
fi
case "$option" in
-*=*) optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg='' ;;
esac
case "$option" in
--help|-h)
echo "Usage: $usage"
exit 0
;;
--version|-v)
echo "OSSP uuid $uuid_version"
exit 0
;;
--all)
all=yes
;;
--prefix)
output="$output $uuid_prefix"
;;
--exec-prefix)
output="$output $uuid_exec_prefix"
;;
--bindir)
output="$output $uuid_bindir"
;;
--libdir)
output="$output $uuid_libdir"
;;
--includedir)
output="$output $uuid_includedir"
;;
--mandir)
output="$output $uuid_mandir"
;;
--datadir)
output="$output $uuid_datadir"
;;
--acdir)
output="$output $uuid_acdir"
;;
--cflags)
output="$output -I$uuid_includedir"
output_extra="$output_extra $uuid_cflags"
;;
--ldflags)
output="$output -L$uuid_libdir"
output_extra="$output_extra $uuid_ldflags"
;;
--libs)
output="$output -luuid"
output_extra="$output_extra $uuid_libs"
;;
* )
echo "uuid-config:Error: Invalid option" 1>&2
echo "uuid-config:Usage: $usage" 1>&2
exit 1;
;;
esac
done
IFS="$OIFS"
if [ ".$prev" != . ]; then
echo "uuid-config:Error: missing argument to --`echo $prev | sed 's/_/-/g'`" 1>&2
exit 1
fi
if [ ".$output" != . ]; then
if [ ".$all" = .yes ]; then
output="$output $output_extra"
fi
echo $output
fi
+206
View File
@@ -0,0 +1,206 @@
dnl ##
dnl ## OSSP uuid - Universally Unique Identifier
dnl ## Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
dnl ## Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
dnl ##
dnl ## This file is part of OSSP uuid, a library for the generation
dnl ## of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
dnl ##
dnl ## Permission to use, copy, modify, and distribute this software for
dnl ## any purpose with or without fee is hereby granted, provided that
dnl ## the above copyright notice and this permission notice appear in all
dnl ## copies.
dnl ##
dnl ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
dnl ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
dnl ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dnl ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dnl ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
dnl ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
dnl ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
dnl ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
dnl ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
dnl ## SUCH DAMAGE.
dnl ##
dnl ## uuid.ac: UUID specific Autoconf checks
dnl ##
dnl # Check for anything OSSP uuid wants to know
dnl # configure.in:
dnl # UUID_CHECK_ALL
AC_DEFUN(UUID_CHECK_ALL,[
dnl # make sure libnsl and libsocket are linked in if they exist
AC_CHECK_LIB(nsl, gethostname)
if test ".`echo $LIBS | grep nsl`" = .; then
AC_CHECK_LIB(nsl, gethostbyname)
fi
AC_CHECK_LIB(socket, accept)
dnl # check for portable va_copy()
AC_CHECK_VA_COPY()
dnl # check for system headers
AC_CHECK_HEADERS(sys/types.h sys/param.h sys/time.h sys/socket.h sys/sockio.h sys/ioctl.h sys/select.h)
AC_CHECK_HEADERS(netdb.h ifaddrs.h net/if.h net/if_dl.h net/if_arp.h netinet/in.h arpa/inet.h,,,
[[
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#if HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
]])
dnl # check for existence of particular C structures
AC_MSG_CHECKING(for struct timeval)
AC_TRY_COMPILE([
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <time.h>
],[ struct timeval tv; ],
[ msg="yes" ], [ msg="no" ])
if test ".$msg" = .yes; then
AC_DEFINE(HAVE_STRUCT_TIMEVAL, 1, [define if exists "struct timeval"])
fi
AC_MSG_RESULT([$msg])
dnl # check for functions
AC_CHECK_FUNCS(getifaddrs nanosleep Sleep gettimeofday clock_gettime)
dnl # check size of built-in types
AC_CHECK_TYPES([long long, long double])
AC_CHECK_SIZEOF(char, 1)
AC_CHECK_SIZEOF(unsigned char, 1)
AC_CHECK_SIZEOF(short, 2)
AC_CHECK_SIZEOF(unsigned short, 2)
AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(unsigned int, 4)
AC_CHECK_SIZEOF(long, 4)
AC_CHECK_SIZEOF(unsigned long, 4)
AC_CHECK_SIZEOF(long long, 8)
AC_CHECK_SIZEOF(unsigned long long, 8)
dnl # configure option --with-dce
AC_ARG_WITH([dce],
AC_HELP_STRING([--with-dce], [build DCE 1.1 backward compatibility API]),
[ac_cv_with_dce=$withval], [ac_cv_with_dce=no])
AC_CACHE_CHECK([whether to build DCE 1.1 backward compatibility API], [ac_cv_with_dce], [ac_cv_with_dce=no])
if test ".$ac_cv_with_dce" = ".yes"; then
AC_DEFINE(WITH_DCE, 1, [whether to build DCE 1.1 backward compatibility API])
WITH_DCE='yes'
DCE_NAME='$(DCE_NAME)'
else
WITH_DCE='no'
DCE_NAME=''
fi
AC_SUBST(WITH_DCE)
AC_SUBST(DCE_NAME)
dnl # configure option --with-cxx
AC_ARG_WITH([cxx],
AS_HELP_STRING([--with-cxx], [build C++ bindings to C API]),
[ac_cv_with_cxx=$withval], [ac_cv_with_cxx=no])
AC_CACHE_CHECK([whether to build C++ bindings to C API], [ac_cv_with_cxx], [ac_cv_with_cxx=no])
if test ".$ac_cv_with_cxx" = ".yes"; then
AC_DEFINE(WITH_CXX, 1, [whether to build C++ bindings to C API])
WITH_CXX='yes'
CXX_NAME='$(CXX_NAME)'
AC_PROG_CXX
else
WITH_CXX='no'
CXX_NAME=''
fi
AC_SUBST(CXX_NAME)
AC_SUBST(WITH_CXX)
dnl # configure option --with-perl
AC_ARG_WITH([perl],
AS_HELP_STRING([--with-perl], [build Perl bindings to C API]),
[ac_cv_with_perl=$withval], [ac_cv_with_perl=no])
AC_CACHE_CHECK([whether to build Perl bindings to C API], [ac_cv_with_perl], [ac_cv_with_perl=no])
AC_ARG_WITH([perl-compat],
AS_HELP_STRING([--with-perl-compat], [build Perl compatibility API]),
[ac_cv_with_perl_compat=$withval], [ac_cv_with_perl_compat=no])
AC_CACHE_CHECK([whether to build Perl compatibility API], [ac_cv_with_perl_compat], [ac_cv_with_perl_compat=no])
if test ".$ac_cv_with_perl" = ".yes"; then
AC_DEFINE(WITH_PERL, 1, [whether to build Perl bindings to C API])
WITH_PERL='yes'
PERL_NAME='$(PERL_NAME)'
else
WITH_PERL='no'
PERL_NAME=''
fi
if test ".$ac_cv_with_perl_compat" = ".yes"; then
AC_DEFINE(WITH_PERL_COMPAT, 1, [whether to build Perl compatibility API])
WITH_PERL_COMPAT=1
else
WITH_PERL_COMPAT=0
fi
AC_SUBST(PERL_NAME)
AC_SUBST(WITH_PERL)
AC_SUBST(WITH_PERL_COMPAT)
AC_PATH_PROG(PERL, perl, NA)
if test ".$ac_cv_with_perl" = ".yes" -a ".$PERL" = ".NA"; then
AC_ERROR([required Perl interpreter not found in \$PATH])
fi
dnl # configure option --with-php
AC_ARG_WITH([php],
AS_HELP_STRING([--with-php], [build PHP bindings to C API]),
[ac_cv_with_php=$withval], [ac_cv_with_php=no])
AC_CACHE_CHECK([whether to build PHP bindings to C API], [ac_cv_with_php], [ac_cv_with_php=no])
if test ".$ac_cv_with_php" = ".yes"; then
AC_DEFINE(WITH_PHP, 1, [whether to build PHP bindings to C API])
WITH_PHP='yes'
PHP_NAME='$(PHP_NAME)'
else
WITH_PHP='no'
PHP_NAME=''
fi
AC_SUBST(PHP_NAME)
AC_SUBST(WITH_PHP)
AC_PATH_PROGS(PHP, php5 php, NA)
if test ".$ac_cv_with_php" = ".yes" -a ".$PHP" = ".NA"; then
AC_ERROR([required PHP interpreter not found in \$PATH])
fi
if test ".$ac_cv_with_php" = ".yes"; then
(cd php && make -f Makefile.local config PHP=$PHP)
fi
dnl # configure option --with-pgsql
AC_ARG_WITH([pgsql],
AS_HELP_STRING([--with-pgsql], [build PostgreSQL bindings to C API]),
[ac_cv_with_pgsql=$withval], [ac_cv_with_pgsql=no])
AC_CACHE_CHECK([whether to build PostgreSQL bindings to C API], [ac_cv_with_pgsql], [ac_cv_with_pgsql=no])
if test ".$ac_cv_with_pgsql" = ".yes"; then
AC_DEFINE(WITH_PGSQL, 1, [whether to build PostgreSQL bindings to C API])
WITH_PGSQL='yes'
PGSQL_NAME='$(PGSQL_NAME)'
else
WITH_PGSQL='no'
PGSQL_NAME=''
fi
AC_SUBST(PGSQL_NAME)
AC_SUBST(WITH_PGSQL)
AC_PATH_PROGS(PG_CONFIG, pg_config, NA)
if test ".$ac_cv_with_pgsql" = ".yes" -a ".$PG_CONFIG" = ".NA"; then
AC_ERROR([required PostgreSQL pg_config utility not found in \$PATH])
fi
if test ".$ac_cv_with_pgsql" = ".yes" -a ".`${MAKE-make} -v 2>/dev/null | grep GNU`" = .; then
AC_ERROR([PostgreSQL bindings require GNU make to build])
fi
])
File diff suppressed because it is too large Load Diff
+120
View File
@@ -0,0 +1,120 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid.h: library API definition
*/
#ifndef __UUID_H__
#define __UUID_H__
/* workaround conflicts with system headers */
#define uuid_t __vendor_uuid_t
#define uuid_create __vendor_uuid_create
#define uuid_compare __vendor_uuid_compare
#include <sys/types.h>
#include <unistd.h>
#undef uuid_t
#undef uuid_create
#undef uuid_compare
/* required system headers */
#include <string.h>
/* minimum C++ support */
#ifdef __cplusplus
#define DECLARATION_BEGIN extern "C" {
#define DECLARATION_END }
#else
#define DECLARATION_BEGIN
#define DECLARATION_END
#endif
DECLARATION_BEGIN
/* OSSP uuid version (compile-time information) */
#define UUID_VERSION @UUID_VERSION_HEX@
/* encoding octet stream lengths */
#define UUID_LEN_BIN (128 /*bit*/ / 8 /*bytes*/)
#define UUID_LEN_STR (128 /*bit*/ / 4 /*nibbles*/ + 4 /*hyphens*/)
#define UUID_LEN_SIV (39 /*int(log(10,exp(2,128)-1)+1) digits*/)
/* API return codes */
typedef enum {
UUID_RC_OK = 0, /* everything ok */
UUID_RC_ARG = 1, /* invalid argument */
UUID_RC_MEM = 2, /* out of memory */
UUID_RC_SYS = 3, /* system error */
UUID_RC_INT = 4, /* internal error */
UUID_RC_IMP = 5 /* not implemented */
} uuid_rc_t;
/* UUID make modes */
enum {
UUID_MAKE_V1 = (1 << 0), /* DCE 1.1 v1 UUID */
UUID_MAKE_V3 = (1 << 1), /* DCE 1.1 v3 UUID */
UUID_MAKE_V4 = (1 << 2), /* DCE 1.1 v4 UUID */
UUID_MAKE_V5 = (1 << 3), /* DCE 1.1 v5 UUID */
UUID_MAKE_MC = (1 << 4) /* enforce multi-cast MAC address */
};
/* UUID import/export formats */
typedef enum {
UUID_FMT_BIN = 0, /* binary representation (import/export) */
UUID_FMT_STR = 1, /* string representation (import/export) */
UUID_FMT_SIV = 2, /* single integer value (import/export) */
UUID_FMT_TXT = 3 /* textual description (export only) */
} uuid_fmt_t;
/* UUID abstract data type */
struct uuid_st;
typedef struct uuid_st uuid_t;
/* UUID object handling */
extern uuid_rc_t uuid_create ( uuid_t **_uuid);
extern uuid_rc_t uuid_destroy ( uuid_t *_uuid);
extern uuid_rc_t uuid_clone (const uuid_t *_uuid, uuid_t **_clone);
/* UUID generation */
extern uuid_rc_t uuid_load ( uuid_t *_uuid, const char *_name);
extern uuid_rc_t uuid_make ( uuid_t *_uuid, unsigned int _mode, ...);
/* UUID comparison */
extern uuid_rc_t uuid_isnil (const uuid_t *_uuid, int *_result);
extern uuid_rc_t uuid_compare (const uuid_t *_uuid, const uuid_t *_uuid2, int *_result);
/* UUID import/export */
extern uuid_rc_t uuid_import ( uuid_t *_uuid, uuid_fmt_t _fmt, const void *_data_ptr, size_t _data_len);
extern uuid_rc_t uuid_export (const uuid_t *_uuid, uuid_fmt_t _fmt, void *_data_ptr, size_t *_data_len);
/* library utilities */
extern char *uuid_error (uuid_rc_t _rc);
extern unsigned long uuid_version (void);
DECLARATION_END
#endif /* __UUID_H__ */
+529
View File
@@ -0,0 +1,529 @@
##
## OSSP uuid - Universally Unique Identifier
## Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
## Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
##
## This file is part of OSSP uuid, a library for the generation
## of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
##
## Permission to use, copy, modify, and distribute this software for
## any purpose with or without fee is hereby granted, provided that
## the above copyright notice and this permission notice appear in all
## copies.
##
## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
## SUCH DAMAGE.
##
## uuid.pod: manual page
##
=pod
=head1 NAME
B<OSSP uuid> - B<Universally Unique Identifier>
=head1 VERSION
OSSP uuid UUID_VERSION_STR
=head1 DESCRIPTION
B<OSSP uuid> is a ISO-C:1999 application programming interface (API) and
corresponding command line interface (CLI) for the generation of DCE
1.1, ISO/IEC 11578:1996 and IETF RFC-4122 compliant I<Universally Unique
Identifier> (UUID). It supports DCE 1.1 variant UUIDs of version 1 (time
and node based), version 3 (name based, MD5), version 4 (random number
based) and version 5 (name based, SHA-1). Additional API bindings are
provided for the languages ISO-C++:1998, Perl:5 and PHP:4/5. Optional
backward compatibility exists for the ISO-C DCE-1.1 and Perl Data::UUID
APIs.
UUIDs are 128 bit numbers which are intended to have a high likelihood
of uniqueness over space and time and are computationally difficult
to guess. They are globally unique identifiers which can be locally
generated without contacting a global registration authority. UUIDs
are intended as unique identifiers for both mass tagging objects
with an extremely short lifetime and to reliably identifying very
persistent objects across a network.
This is the ISO-C application programming interface (API) of B<OSSP uuid>.
=head2 UUID Binary Representation
According to the DCE 1.1, ISO/IEC 11578:1996 and IETF RFC-4122
standards, a DCE 1.1 variant UUID is a 128 bit number defined out of 7
fields, each field a multiple of an octet in size and stored in network
byte order:
[4]
version
-->| |<--
| |
| | [16]
[32] [16] | |time_hi
time_low time_mid | _and_version
|<---------------------------->||<------------>||<------------>|
| MSB || || | |
| / || || | |
|/ || || | |
+------++------++------++------++------++------++------++------+~~
| 15 || 14 || 13 || 12 || 11 || 10 |####9 || 8 |
| MSO || || || || || |#### || |
+------++------++------++------++------++------++------++------+~~
7654321076543210765432107654321076543210765432107654321076543210
~~+------++------++------++------++------++------++------++------+
##* 7 || 6 || 5 || 4 || 3 || 2 || 1 || 0 |
##* || || || || || || || LSO |
~~+------++------++------++------++------++------++------++------+
7654321076543210765432107654321076543210765432107654321076543210
| | || || /|
| | || || / |
| | || || LSB |
|<---->||<---->||<-------------------------------------------->|
|clk_seq clk_seq node
|_hi_res _low [48]
|[5-6] [8]
| |
-->| |<--
variant
[2-3]
An example of a UUID binary representation is the octet stream C<0xF8
0x1D 0x4F 0xAE 0x7D 0xEC 0x11 0xD0 0xA7 0x65 0x00 0xA0 0xC9 0x1E 0x6B
0xF6>. The binary representation format is exactly what the B<OSSP uuid>
API functions B<uuid_import>() and B<uuid_export>() deal with under
C<UUID_FMT_BIN>.
=head2 UUID ASCII String Representation
According to the DCE 1.1, ISO/IEC 11578:1996 and IETF RFC-4122
standards, a DCE 1.1 variant UUID is represented as an ASCII string
consisting of 8 hexadecimal digits followed by a hyphen, then three
groups of 4 hexadecimal digits each followed by a hyphen, then 12
hexadecimal digits. Formally, the string representation is defined by
the following grammar:
uuid = <time_low> "-"
<time_mid> "-"
<time_high_and_version> "-"
<clock_seq_high_and_reserved>
<clock_seq_low> "-"
<node>
time_low = 4*<hex_octet>
time_mid = 2*<hex_octet>
time_high_and_version = 2*<hex_octet>
clock_seq_high_and_reserved = <hex_octet>
clock_seq_low = <hex_octet>
node = 6*<hex_octet>
hex_octet = <hex_digit> <hex_digit>
hex_digit = "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"
|"a"|"b"|"c"|"d"|"e"|"f"
|"A"|"B"|"C"|"D"|"E"|"F"
An example of a UUID string representation is the ASCII string
"C<f81d4fae-7dec-11d0-a765-00a0c91e6bf6>". The string representation
format is exactly what the B<OSSP uuid> API functions B<uuid_import>()
and B<uuid_export>() deal with under C<UUID_FMT_STR>.
Notice: a corresponding URL can be generated out of a ASCII string
representation of an UUID by prefixing with "C<urn:uuid:>" as in
"C<urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6>".
=head2 UUID Single Integer Value Representation
According to the ISO/IEC 11578:1996 and ITU-T Rec. X.667 standards, a
DCE 1.1 variant UUID can be also represented as a single integer value
consisting of a decimal number with up to 39 digits.
An example of a UUID single integer value representation is the decimal
number "C<329800735698586629295641978511506172918>". The string
representation format is exactly what the B<OSSP uuid> API functions
B<uuid_import>() and B<uuid_export>() deal with under C<UUID_FMT_SIV>.
Notice: a corresponding ISO OID can be generated under the
"{joint-iso-itu-t(2) uuid(25)}" arc out of a single integer value
representation of a UUID by prefixing with "C<2.25.>". An example OID
is "C<2.25.329800735698586629295641978511506172918>". Additionally,
an URL can be generated by further prefixing with "C<urn:oid:>" as in
"C<urn:oid:2.25.329800735698586629295641978511506172918>".
=head2 UUID Variants and Versions
A UUID has a variant and version. The variant defines the layout of the
UUID. The version defines the content of the UUID. The UUID variant
supported in B<OSSP uuid> is the DCE 1.1 variant only. The DCE 1.1 UUID
variant versions supported in B<OSSP uuid> are:
=over 4
=item B<Version 1> (time and node based)
These are the classical UUIDs, created out of a 60-bit system time,
a 14-bit local clock sequence and 48-bit system MAC address. The MAC
address can be either the real one of a physical network interface card
(NIC) or a random multi-cast MAC address. Version 1 UUIDs are usually
used as one-time global unique identifiers.
=item B<Version 3> (name based, MD5)
These are UUIDs which are based on the 128-bit MD5 message digest of the
concatenation of a 128-bit namespace UUID and a name string of arbitrary
length. Version 3 UUIDs are usually used for non-unique but repeatable
message digest identifiers.
=item B<Version 4> (random data based)
These are UUIDs which are based on just 128-bit of random data. Version
4 UUIDs are usually used as one-time local unique identifiers.
=item B<Version 5> (name based, SHA-1)
These are UUIDs which are based on the 160-bit SHA-1 message digest of the
concatenation of a 128-bit namespace UUID and a name string of arbitrary
length. Version 5 UUIDs are usually used for non-unique but repeatable
message digest identifiers.
=back
=head2 UUID Uniqueness
Version 1 UUIDs are guaranteed to be unique through combinations of
hardware addresses, time stamps and random seeds. There is a reference
in the UUID to the hardware (MAC) address of the first network interface
card (NIC) on the host which generated the UUID -- this reference
is intended to ensure the UUID will be unique in space as the MAC
address of every network card is assigned by a single global authority
(IEEE) and is guaranteed to be unique. The next component in a UUID
is a timestamp which, as clock always (should) move forward, will
be unique in time. Just in case some part of the above goes wrong
(the hardware address cannot be determined or the clock moved steps
backward), there is a random clock sequence component placed into the
UUID as a "catch-all" for uniqueness.
Version 3 and version 5 UUIDs are guaranteed to be inherently globally
unique if the combination of namespace and name used to generate them is
unique.
Version 4 UUIDs are not guaranteed to be globally unique, because they
are generated out of locally gathered pseudo-random numbers only.
Nevertheless there is still a high likelihood of uniqueness over space
and time and that they are computationally difficult to guess.
=head2 Nil UUID
There is a special I<Nil> UUID consisting of all octets set to zero in
the binary representation. It can be used as a special UUID value which does
not conflict with real UUIDs.
=head1 APPLICATION PROGRAMMING INTERFACE
The ISO-C Application Programming Interface (API) of B<OSSP uuid>
consists of the following components.
=head2 CONSTANTS
The following constants are provided:
=over 4
=item B<UUID_VERSION>
The hexadecimal encoded B<OSSP uuid> version. This allows compile-time
checking of the B<OSSP uuid> version. For run-time checking use
B<uuid_version>() instead.
The hexadecimal encoding for a version "$I<v>.$I<r>$I<t>$I<l>" is
calculated with the B<GNU shtool> B<version> command and is (in
Perl-style for concise description) "sprintf('0x%x%02x%d%02x', $I<v>,
$I<r>, {qw(s 9 . 2 b 1 a 0)}->{$I<t>}, ($I<t> eq 's' ? 99 : $I<l>))",
i.e., the version 0.9.6 is encoded as "0x009206".
=item B<UUID_LEN_BIN>, B<UUID_LEN_STR>, B<UUID_LEN_SIV>
The number of octets of the UUID binary and string representations.
Notice that the lengths of the string representation (B<UUID_LEN_STR>)
and the lengths of the single integer value representation
(B<UUID_LEN_SIV>) does I<not> include the necessary C<NUL> termination
character.
=item B<UUID_MAKE_V1>, B<UUID_MAKE_V3>, B<UUID_MAKE_V4>, B<UUID_MAKE_V5>, B<UUID_MAKE_MC>
The I<mode> bits for use with B<uuid_make>(). The B<UUID_MAKE_V>I<N>
specify which UUID version to generate. The B<UUID_MAKE_MC> forces the
use of a random multi-cast MAC address instead of the real physical MAC
address in version 1 UUIDs.
=item B<UUID_RC_OK>, B<UUID_RC_ARG>, B<UUID_RC_MEM>, B<UUID_RC_SYS>, B<UUID_RC_INT>, B<UUID_RC_IMP>
The possible numerical return-codes of API functions.
The C<UUID_RC_OK> indicates success, the others indicate errors.
Use B<uuid_error>() to translate them into string versions.
=item B<UUID_FMT_BIN>, B<UUID_FMT_STR>, B<UUID_FMT_SIV>, B<UUID_FMT_TXT>
The I<fmt> formats for use with B<uuid_import>() and B<uuid_export>().
The B<UUID_FMT_BIN> indicates the UUID binary representation (of
length B<UUID_LEN_BIN>), the B<UUID_FMT_STR> indicates the UUID string
representation (of length B<UUID_LEN_STR>), the B<UUID_FMT_SIV>
indicates the UUID single integer value representation (of maximum
length B<UUID_LEN_SIV>) and the B<UUID_FMT_TXT> indicates the textual
description (of arbitrary length) of a UUID.
=back
=head2 FUNCTIONS
The following functions are provided:
=over 4
=item uuid_rc_t B<uuid_create>(uuid_t **I<uuid>);
Create a new UUID object and store a pointer to it in C<*>I<uuid>.
A UUID object consists of an internal representation of a UUID, the
internal PRNG and MD5 generator contexts, and cached MAC address and
timestamp information. The initial UUID is the I<Nil> UUID.
=item uuid_rc_t B<uuid_destroy>(uuid_t *I<uuid>);
Destroy UUID object I<uuid>.
=item uuid_rc_t B<uuid_clone>(const uuid_t *I<uuid>, uuid_t **I<uuid_clone>);
Clone UUID object I<uuid> and store new UUID object in I<uuid_clone>.
=item uuid_rc_t B<uuid_isnil>(const uuid_t *I<uuid>, int *I<result>);
Checks whether the UUID in I<uuid> is the I<Nil> UUID.
If this is the case, it returns I<true> in C<*>I<result>.
Else it returns I<false> in C<*>I<result>.
=item uuid_rc_t B<uuid_compare>(const uuid_t *I<uuid>, const uuid_t *I<uuid2>, int *I<result>);
Compares the order of the two UUIDs in I<uuid1> and I<uuid2>
and returns the result in C<*>I<result>: C<-1> if I<uuid1> is
smaller than I<uuid2>, C<0> if I<uuid1> is equal to I<uuid2>
and C<+1> if I<uuid1> is greater than I<uuid2>.
=item uuid_rc_t B<uuid_import>(uuid_t *I<uuid>, uuid_fmt_t I<fmt>, const void *I<data_ptr>, size_t I<data_len>);
Imports a UUID I<uuid> from an external representation of format I<fmt>.
The data is read from the buffer at I<data_ptr> which contains at least
I<data_len> bytes.
The format of the external representation is specified by I<fmt> and the
minimum expected length in I<data_len> depends on it. Valid values for
I<fmt> are B<UUID_FMT_BIN>, B<UUID_FMT_STR> and B<UUID_FMT_SIV>.
=item uuid_rc_t B<uuid_export>(const uuid_t *I<uuid>, uuid_fmt_t I<fmt>, void *I<data_ptr>, size_t *I<data_len>);
Exports a UUID I<uuid> into an external representation of format
I<fmt>. Valid values for I<fmt> are B<UUID_FMT_BIN>, B<UUID_FMT_STR>,
B<UUID_FMT_SIV> and B<UUID_FMT_TXT>.
The data is written to the buffer whose location is obtained
by dereferencing I<data_ptr> after a "cast" to the appropriate
pointer-to-pointer type. Hence the generic pointer argument I<data_ptr>
is expected to be a pointer to a "pointer of a particular type", i.e.,
it has to be of type "C<unsigned char **>" for B<UUID_FMT_BIN> and
"C<char **>" for B<UUID_FMT_STR>, B<UUID_FMT_SIV> and B<UUID_FMT_TXT>.
The buffer has to be room for at least C<*>I<data_len> bytes. If the
value of the pointer after "casting" and dereferencing I<data_ptr>
is C<NULL>, I<data_len> is ignored as input and a new buffer is
allocated and returned in the pointer after "casting" and dereferencing
I<data_ptr> (the caller has to free(3) it later on).
If I<data_len> is not C<NULL>, the number of available bytes in the
buffer has to be provided in C<*>I<data_len> and the number of actually
written bytes are returned in C<*>I<data_len> again. The minimum
required buffer length depends on the external representation as
specified by I<fmt> and is at least B<UUID_LEN_BIN> for B<UUID_FMT_BIN>,
B<UUID_LEN_STR> for B<UUID_FMT_STR> and B<UUID_LEN_SIV> for
B<UUID_FMT_SIV>. For B<UUID_FMT_TXT> a buffer of unspecified length is
required and hence it is recommended to allow B<OSSP uuid> to allocate
the buffer as necessary.
=item uuid_rc_t B<uuid_load>(uuid_t *I<uuid>, const char *I<name>);
Loads a pre-defined UUID value into the UUID object I<uuid>. The
following I<name> arguments are currently known:
=over 4
=item I<name> I<UUID>
=item nil 00000000-0000-0000-0000-000000000000
=item ns:DNS 6ba7b810-9dad-11d1-80b4-00c04fd430c8
=item ns:URL 6ba7b811-9dad-11d1-80b4-00c04fd430c8
=item ns:OID 6ba7b812-9dad-11d1-80b4-00c04fd430c8
=item ns:X500 6ba7b814-9dad-11d1-80b4-00c04fd430c8
=back
The "C<ns:>I<XXX>" are names of pre-defined name-space UUIDs for use in
the generation of DCE 1.1 version 3 and version 5 UUIDs.
=item uuid_rc_t B<uuid_make>(uuid_t *I<uuid>, unsigned int I<mode>, ...);
Generates a new UUID in I<uuid> according to I<mode> and optional
arguments (dependent on I<mode>).
If I<mode> contains the C<UUID_MAKE_V1> bit, a DCE 1.1 variant UUID of
version 1 is generated. Then optionally the bit C<UUID_MAKE_MC> forces
the use of random multi-cast MAC address instead of the real physical
MAC address (the default). The UUID is generated out of the 60-bit current
system time, a 12-bit clock sequence and the 48-bit MAC address.
If I<mode> contains the C<UUID_MAKE_V3> or C<UUID_MAKE_V5> bit, a DCE
1.1 variant UUID of version 3 or 5 is generated and two additional
arguments are expected: first, a namespace UUID object (C<uuid_t *>).
Second, a name string of arbitrary length (C<const char *>). The UUID is
generated out of the 128-bit MD5 or 160-bit SHA-1 from the concatenated
octet stream of namespace UUID and name string.
If I<mode> contains the C<UUID_MAKE_V4> bit, a DCE 1.1 variant UUID
of version 4 is generated. The UUID is generated out of 128-bit random
data.
=item char *B<uuid_error>(uuid_rc_t I<rc>);
Returns a constant string representation corresponding to the
return-code I<rc> for use in displaying B<OSSP uuid> errors.
=item unsigned long B<uuid_version>(void);
Returns the hexadecimal encoded B<OSSP uuid> version as compiled into
the library object files. This allows run-time checking of the B<OSSP
uuid> version. For compile-time checking use C<UUID_VERSION> instead.
=back
=head1 EXAMPLE
The following shows an example usage of the API. Error handling is
omitted for code simplification and has to be re-added for production
code.
/* generate a DCE 1.1 v1 UUID from system environment */
char *uuid_v1(void)
{
uuid_t *uuid;
char *str;
uuid_create(&uuid);
uuid_make(uuid, UUID_MAKE_V1);
str = NULL;
uuid_export(uuid, UUID_FMT_STR, &str, NULL);
uuid_destroy(uuid);
return str;
}
/* generate a DCE 1.1 v3 UUID from an URL */
char *uuid_v3(const char *url)
{
uuid_t *uuid;
uuid_t *uuid_ns;
char *str;
uuid_create(&uuid);
uuid_create(&uuid_ns);
uuid_load(uuid_ns, "ns:URL");
uuid_make(uuid, UUID_MAKE_V3, uuid_ns, url);
str = NULL;
uuid_export(uuid, UUID_FMT_STR, &str, NULL);
uuid_destroy(uuid_ns);
uuid_destroy(uuid);
return str;
}
=head1 SEE ALSO
The following are references to B<UUID> documentation and specifications:
=over 4
=item
B<A Universally Unique IDentifier (UUID) URN Namespace>,
P. Leach, M. Mealling, R. Salz,
IETF RFC-4122,
July 2005, 32 pages,
http://www.ietf.org/rfc/rfc4122.txt
=item
Information Technology -- Open Systems Interconnection (OSI),
B<Procedures for the operation of OSI Registration Authorities:
Generation and Registration of Universally Unique Identifiers (UUIDs)
and their Use as ASN.1 Object Identifier Components>,
ISO/IEC 9834-8:2004 / ITU-T Rec. X.667, 2004,
December 2004, 25 pages,
http://www.itu.int/ITU-T/studygroups/com17/oid/X.667-E.pdf
=item
B<DCE 1.1: Remote Procedure Call>,
appendix B<Universally Unique Identifier>,
Open Group Technical Standard
Document Number C706, August 1997, 737 pages,
(supersedes C309 DCE: Remote Procedure Call 8/1994,
which was basis for ISO/IEC 11578:1996 specification),
http://www.opengroup.org/publications/catalog/c706.htm
=item
Information technology -- Open Systems Interconnection (OSI),
B<Remote Procedure Call (RPC)>,
ISO/IEC 11578:1996,
August 2001, 570 pages, (CHF 340,00),
http://www.iso.ch/cate/d2229.html
=item
B<HTTP Extensions for Distributed Authoring (WebDAV)>,
section B<6.4.1 Node Field Generation Without the IEEE 802 Address>,
IETF RFC-2518,
February 1999, 94 pages,
http://www.ietf.org/rfc/rfc2518.txt
=item
B<DCE 1.1 compliant UUID functions>,
FreeBSD manual pages uuid(3) and uuidgen(2),
http://www.freebsd.org/cgi/man.cgi?query=uuid&manpath=FreeBSD+6.0-RELEASE
=back
=head1 HISTORY
B<OSSP uuid> was implemented in January 2004 by Ralf S. Engelschall
E<lt>rse@engelschall.comE<gt>. It was prompted by the use of UUIDs
in the B<OSSP as> and B<OpenPKG> projects. It is a clean room
implementation intended to be strictly standards compliant and maximum
portable.
=head1 SEE ALSO
uuid(1), uuid-config(1), OSSP::uuid(3).
=cut
+109
View File
@@ -0,0 +1,109 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_ac.c: auto-configuration
*/
#ifndef __UUID_AC_H__
#define __UUID_AC_H__
/* include GNU autoconf results */
#include "config.h" /* HAVE_xxx */
/* include standard system headers */
#include <stdio.h> /* NULL, etc. */
#include <stdlib.h> /* malloc, NULL, etc. */
#include <stdarg.h> /* va_list, etc. */
#include <string.h> /* size_t, strlen, etc. */
#include <unistd.h> /* dmalloc pre-loading */
/* enable optional "dmalloc" support */
#ifdef WITH_DMALLOC
#include <dmalloc.h> /* malloc override, etc */
#endif
/* define boolean values */
#define UUID_FALSE 0
#define UUID_TRUE (/*lint -save -e506*/ !UUID_FALSE /*lint -restore*/)
/* determine types of 8-bit size */
#if SIZEOF_CHAR == 1
typedef char uuid_int8_t;
#else
#error unexpected: sizeof(char) != 1 !?
#endif
#if SIZEOF_UNSIGNED_CHAR == 1
typedef unsigned char uuid_uint8_t;
#else
#error unexpected: sizeof(unsigned char) != 1 !?
#endif
/* determine types of 16-bit size */
#if SIZEOF_SHORT == 2
typedef short uuid_int16_t;
#elif SIZEOF_INT == 2
typedef int uuid_int16_t;
#elif SIZEOF_LONG == 2
typedef long uuid_int16_t;
#else
#error unexpected: no type found for uuid_int16_t
#endif
#if SIZEOF_UNSIGNED_SHORT == 2
typedef unsigned short uuid_uint16_t;
#elif SIZEOF_UNSIGNED_INT == 2
typedef unsigned int uuid_uint16_t;
#elif SIZEOF_UNSIGNED_LONG == 2
typedef unsigned long uuid_uint16_t;
#else
#error unexpected: no type found for uuid_uint16_t
#endif
/* determine types of 32-bit size */
#if SIZEOF_SHORT == 4
typedef short uuid_int32_t;
#elif SIZEOF_INT == 4
typedef int uuid_int32_t;
#elif SIZEOF_LONG == 4
typedef long uuid_int32_t;
#elif SIZEOF_LONG_LONG == 4
typedef long long uuid_int32_t;
#else
#error unexpected: no type found for uuid_int32_t
#endif
#if SIZEOF_UNSIGNED_SHORT == 4
typedef unsigned short uuid_uint32_t;
#elif SIZEOF_UNSIGNED_INT == 4
typedef unsigned int uuid_uint32_t;
#elif SIZEOF_UNSIGNED_LONG == 4
typedef unsigned long uuid_uint32_t;
#elif SIZEOF_UNSIGNED_LONG_LONG == 4
typedef unsigned long long uuid_uint32_t;
#else
#error unexpected: no type found for uuid_uint32_t
#endif
#endif /* __UUID_AC_H__ */
+80
View File
@@ -0,0 +1,80 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_bm.c: bitmask API implementation
*/
#ifndef __UUID_BM_H__
#define __UUID_BM_H__
/*
* Bitmask Calculation Macros (up to 32 bit only)
* (Notice: bit positions are counted n...0, i.e. lowest bit is position 0)
*/
/* generate a bitmask consisting of 1 bits from (and including)
bit position `l' (left) to (and including) bit position `r' */
#define BM_MASK(l,r) \
((((unsigned int)1<<(((l)-(r))+1))-1)<<(r))
/* extract a value v from a word w at position `l' to `r' and return value */
#define BM_GET(w,l,r) \
(((w)>>(r))&BM_MASK((l)-(r),0))
/* insert a value v into a word w at position `l' to `r' and return word */
#define BM_SET(w,l,r,v) \
((w)|(((v)&BM_MASK((l)-(r),0))<<(r)))
/* generate a single bit `b' (0 or 1) at bit position `n' */
#define BM_BIT(n,b) \
((b)<<(n))
/* generate a quad word octet of bits (a half byte, i.e. bit positions 3 to 0) */
#define BM_QUAD(b3,b2,b1,b0) \
(BM_BIT(3,(b3))|BM_BIT(2,(b2))|BM_BIT(1,(b1))|BM_BIT(0,(b0)))
/* generate an octet word of bits (a byte, i.e. bit positions 7 to 0) */
#define BM_OCTET(b7,b6,b5,b4,b3,b2,b1,b0) \
((BM_QUAD(b7,b6,b5,b4)<<4)|BM_QUAD(b3,b2,b1,b0))
/* generate the value 2^n */
#define BM_POW2(n) \
BM_BIT(n,1)
/* shift word w k bits to the left or to the right */
#define BM_SHL(w,k) \
((w)<<(k))
#define BM_SHR(w,k) \
((w)>>(k))
/* rotate word w (of bits n..0) k bits to the left or to the right */
#define BM_ROL(w,n,k) \
((BM_SHL((w),(k))&BM_MASK(n,0))|BM_SHR(((w)&BM_MASK(n,0)),(n)-(k)))
#define BM_ROR(w,n,k) \
((BM_SHR(((w)&BM_MASK(n,0)),(k)))|BM_SHL(((w),(n)-(k))&BM_MASK(n,0)))
#endif /* __UUID_BM_H__ */
+283
View File
@@ -0,0 +1,283 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_cli.c: command line tool
*/
/* own headers */
#include "uuid.h"
#include "uuid_ac.h"
/* system headers */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
/* error handler */
static void
error(int ec, const char *str, ...)
{
va_list ap;
va_start(ap, str);
fprintf(stderr, "uuid:ERROR: ");
vfprintf(stderr, str, ap);
fprintf(stderr, "\n");
va_end(ap);
exit(ec);
}
/* usage handler */
static void
usage(const char *str, ...)
{
va_list ap;
va_start(ap, str);
if (str != NULL) {
fprintf(stderr, "uuid:ERROR: ");
vfprintf(stderr, str, ap);
fprintf(stderr, "\n");
}
fprintf(stderr, "usage: uuid [-v version] [-m] [-n count] [-1] [-F format] [-o filename] [namespace name]\n");
fprintf(stderr, "usage: uuid -d [-F format] [-o filename] [uuid]\n");
va_end(ap);
exit(1);
}
/* main procedure */
int main(int argc, char *argv[])
{
char uuid_buf_bin[UUID_LEN_BIN];
char uuid_buf_str[UUID_LEN_STR+1];
char uuid_buf_siv[UUID_LEN_SIV+1];
uuid_t *uuid;
uuid_t *uuid_ns;
uuid_rc_t rc;
FILE *fp;
char *p;
int ch;
int count;
int i;
int iterate;
uuid_fmt_t fmt;
int decode;
void *vp;
size_t n;
unsigned int version;
/* command line parsing */
count = -1; /* no count yet */
fp = stdout; /* default output file */
iterate = 0; /* not one at a time */
fmt = UUID_FMT_STR; /* default is ASCII output */
decode = 0; /* default is to encode */
version = UUID_MAKE_V1;
while ((ch = getopt(argc, argv, "1n:rF:dmo:v:h")) != -1) {
switch (ch) {
case '1':
iterate = 1;
break;
case 'n':
if (count > 0)
usage("option 'n' specified multiple times");
count = strtol(optarg, &p, 10);
if (*p != '\0' || count < 1)
usage("invalid argument to option 'n'");
break;
case 'r':
fmt = UUID_FMT_BIN;
break;
case 'F':
if (strcasecmp(optarg, "bin") == 0)
fmt = UUID_FMT_BIN;
else if (strcasecmp(optarg, "str") == 0)
fmt = UUID_FMT_STR;
else if (strcasecmp(optarg, "siv") == 0)
fmt = UUID_FMT_SIV;
else
error(1, "invalid format \"%s\" (has to be \"bin\", \"str\" or \"siv\")", optarg);
break;
case 'd':
decode = 1;
break;
case 'o':
if (fp != stdout)
error(1, "multiple output files are not allowed");
if ((fp = fopen(optarg, "w")) == NULL)
error(1, "fopen: %s", strerror(errno));
break;
case 'm':
version |= UUID_MAKE_MC;
break;
case 'v':
i = strtol(optarg, &p, 10);
if (*p != '\0')
usage("invalid argument to option 'v'");
switch (i) {
case 1: version = UUID_MAKE_V1; break;
case 3: version = UUID_MAKE_V3; break;
case 4: version = UUID_MAKE_V4; break;
case 5: version = UUID_MAKE_V5; break;
default:
usage("invalid version on option 'v'");
break;
}
break;
case 'h':
usage(NULL);
break;
default:
usage("invalid option '%c'", optopt);
}
}
argv += optind;
argc -= optind;
if (count == -1)
count = 1;
if (decode) {
/* decoding */
if ((rc = uuid_create(&uuid)) != UUID_RC_OK)
error(1, "uuid_create: %s", uuid_error(rc));
if (argc != 1)
usage("invalid number of arguments");
if (strcmp(argv[0], "-") == 0) {
if (fmt == UUID_FMT_BIN) {
if (fread(uuid_buf_bin, UUID_LEN_BIN, 1, stdin) != 1)
error(1, "fread: failed to read %d (UUID_LEN_BIN) bytes from stdin", UUID_LEN_BIN);
if ((rc = uuid_import(uuid, UUID_FMT_BIN, uuid_buf_bin, UUID_LEN_BIN)) != UUID_RC_OK)
error(1, "uuid_import: %s", uuid_error(rc));
}
else if (fmt == UUID_FMT_STR) {
if (fread(uuid_buf_str, UUID_LEN_STR, 1, stdin) != 1)
error(1, "fread: failed to read %d (UUID_LEN_STR) bytes from stdin", UUID_LEN_STR);
uuid_buf_str[UUID_LEN_STR] = '\0';
if ((rc = uuid_import(uuid, UUID_FMT_STR, uuid_buf_str, UUID_LEN_STR)) != UUID_RC_OK)
error(1, "uuid_import: %s", uuid_error(rc));
}
else if (fmt == UUID_FMT_SIV) {
if (fread(uuid_buf_siv, UUID_LEN_SIV, 1, stdin) != 1)
error(1, "fread: failed to read %d (UUID_LEN_SIV) bytes from stdin", UUID_LEN_SIV);
uuid_buf_siv[UUID_LEN_SIV] = '\0';
if ((rc = uuid_import(uuid, UUID_FMT_SIV, uuid_buf_siv, UUID_LEN_SIV)) != UUID_RC_OK)
error(1, "uuid_import: %s", uuid_error(rc));
}
}
else {
if (fmt == UUID_FMT_BIN) {
error(1, "binary input mode only possible if reading from stdin");
}
else if (fmt == UUID_FMT_STR) {
if ((rc = uuid_import(uuid, UUID_FMT_STR, argv[0], strlen(argv[0]))) != UUID_RC_OK)
error(1, "uuid_import: %s", uuid_error(rc));
}
else if (fmt == UUID_FMT_SIV) {
if ((rc = uuid_import(uuid, UUID_FMT_SIV, argv[0], strlen(argv[0]))) != UUID_RC_OK)
error(1, "uuid_import: %s", uuid_error(rc));
}
}
vp = NULL;
if ((rc = uuid_export(uuid, UUID_FMT_TXT, &vp, NULL)) != UUID_RC_OK)
error(1, "uuid_export: %s", uuid_error(rc));
fprintf(stdout, "%s", (char *)vp);
free(vp);
if ((rc = uuid_destroy(uuid)) != UUID_RC_OK)
error(1, "uuid_destroy: %s", uuid_error(rc));
}
else {
/* encoding */
if ( (version == UUID_MAKE_V1 && argc != 0)
|| (version == UUID_MAKE_V3 && argc != 2)
|| (version == UUID_MAKE_V4 && argc != 0)
|| (version == UUID_MAKE_V5 && argc != 2))
usage("invalid number of arguments");
if ((rc = uuid_create(&uuid)) != UUID_RC_OK)
error(1, "uuid_create: %s", uuid_error(rc));
if (argc == 1) {
/* load initial UUID for setting old generator state */
if (strlen(argv[0]) != UUID_LEN_STR)
error(1, "invalid length of UUID string representation");
if ((rc = uuid_import(uuid, UUID_FMT_STR, argv[0], strlen(argv[0]))) != UUID_RC_OK)
error(1, "uuid_import: %s", uuid_error(rc));
}
for (i = 0; i < count; i++) {
if (iterate) {
if ((rc = uuid_load(uuid, "nil")) != UUID_RC_OK)
error(1, "uuid_load: %s", uuid_error(rc));
}
if (version == UUID_MAKE_V3 || version == UUID_MAKE_V5) {
if ((rc = uuid_create(&uuid_ns)) != UUID_RC_OK)
error(1, "uuid_create: %s", uuid_error(rc));
if ((rc = uuid_load(uuid_ns, argv[0])) != UUID_RC_OK) {
if ((rc = uuid_import(uuid_ns, UUID_FMT_STR, argv[0], strlen(argv[0]))) != UUID_RC_OK)
error(1, "uuid_import: %s", uuid_error(rc));
}
if ((rc = uuid_make(uuid, version, uuid_ns, argv[1])) != UUID_RC_OK)
error(1, "uuid_make: %s", uuid_error(rc));
if ((rc = uuid_destroy(uuid_ns)) != UUID_RC_OK)
error(1, "uuid_destroy: %s", uuid_error(rc));
}
else {
if ((rc = uuid_make(uuid, version)) != UUID_RC_OK)
error(1, "uuid_make: %s", uuid_error(rc));
}
if (fmt == UUID_FMT_BIN) {
vp = NULL;
if ((rc = uuid_export(uuid, UUID_FMT_BIN, &vp, &n)) != UUID_RC_OK)
error(1, "uuid_export: %s", uuid_error(rc));
fwrite(vp, n, 1, fp);
free(vp);
}
else if (fmt == UUID_FMT_STR) {
vp = NULL;
if ((rc = uuid_export(uuid, UUID_FMT_STR, &vp, &n)) != UUID_RC_OK)
error(1, "uuid_export: %s", uuid_error(rc));
fprintf(fp, "%s\n", (char *)vp);
free(vp);
}
else if (fmt == UUID_FMT_SIV) {
vp = NULL;
if ((rc = uuid_export(uuid, UUID_FMT_SIV, &vp, &n)) != UUID_RC_OK)
error(1, "uuid_export: %s", uuid_error(rc));
fprintf(fp, "%s\n", (char *)vp);
free(vp);
}
}
if ((rc = uuid_destroy(uuid)) != UUID_RC_OK)
error(1, "uuid_destroy: %s", uuid_error(rc));
}
/* close output channel */
if (fp != stdout)
fclose(fp);
return 0;
}
+294
View File
@@ -0,0 +1,294 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_dce.c: DCE 1.1 compatibility API implementation
*/
/* include DCE 1.1 API */
#define uuid_t uuid_dce_t
#include "uuid_dce.h"
#undef uuid_t
#undef uuid_create
#undef uuid_create_nil
#undef uuid_is_nil
#undef uuid_compare
#undef uuid_equal
#undef uuid_from_string
#undef uuid_to_string
#undef uuid_hash
/* include regular API */
#include "uuid.h"
/* helper macro */
#define LEAVE /*lint -save -e801*/ goto leave /*lint -restore*/
/* create a UUID (v1 only) */
void uuid_dce_create(uuid_dce_t *uuid_dce, int *status)
{
uuid_t *uuid;
size_t len;
void *vp;
/* initialize status */
if (status != NULL)
*status = uuid_s_error;
/* sanity check argument(s) */
if (uuid_dce == NULL)
return;
/* create UUID and export as binary representation */
if (uuid_create(&uuid) != UUID_RC_OK)
return;
if (uuid_make(uuid, UUID_MAKE_V1) != UUID_RC_OK) {
uuid_destroy(uuid);
return;
}
vp = uuid_dce;
len = UUID_LEN_BIN;
if (uuid_export(uuid, UUID_FMT_BIN, &vp, &len) != UUID_RC_OK) {
uuid_destroy(uuid);
return;
}
uuid_destroy(uuid);
/* return successfully */
if (status != NULL)
*status = uuid_s_ok;
return;
}
/* create a Nil UUID */
void uuid_dce_create_nil(uuid_dce_t *uuid_dce, int *status)
{
/* initialize status */
if (status != NULL)
*status = uuid_s_error;
/* sanity check argument(s) */
if (uuid_dce == NULL)
return;
/* short-circuit implementation, because Nil UUID is trivial to
create, so no need to use regular OSSP uuid API */
memset(uuid_dce, 0, UUID_LEN_BIN);
/* return successfully */
if (status != NULL)
*status = uuid_s_ok;
return;
}
/* check whether it is Nil UUID */
int uuid_dce_is_nil(uuid_dce_t *uuid_dce, int *status)
{
int i;
int result;
unsigned char *ucp;
/* initialize status */
if (status != NULL)
*status = uuid_s_error;
/* sanity check argument(s) */
if (uuid_dce == NULL)
return 0;
/* short-circuit implementation, because Nil UUID is trivial to
check, so no need to use regular OSSP uuid API */
result = 1;
ucp = (unsigned char *)uuid_dce;
for (i = 0; i < UUID_LEN_BIN; i++) {
if (ucp[i] != '\0') {
result = 0;
break;
}
}
/* return successfully with result */
if (status != NULL)
*status = uuid_s_ok;
return result;
}
/* compare two UUIDs */
int uuid_dce_compare(uuid_dce_t *uuid_dce1, uuid_dce_t *uuid_dce2, int *status)
{
uuid_t *uuid1 = NULL;
uuid_t *uuid2 = NULL;
int result = 0;
/* initialize status */
if (status != NULL)
*status = uuid_s_error;
/* sanity check argument(s) */
if (uuid_dce1 == NULL || uuid_dce2 == NULL)
return 0;
/* import both UUID binary representations and compare them */
if (uuid_create(&uuid1) != UUID_RC_OK)
LEAVE;
if (uuid_create(&uuid2) != UUID_RC_OK)
LEAVE;
if (uuid_import(uuid1, UUID_FMT_BIN, uuid_dce1, UUID_LEN_BIN) != UUID_RC_OK)
LEAVE;
if (uuid_import(uuid2, UUID_FMT_BIN, uuid_dce2, UUID_LEN_BIN) != UUID_RC_OK)
LEAVE;
if (uuid_compare(uuid1, uuid2, &result) != UUID_RC_OK)
LEAVE;
/* indicate successful operation */
if (status != NULL)
*status = uuid_s_ok;
/* cleanup and return */
leave:
if (uuid1 != NULL)
uuid_destroy(uuid1);
if (uuid2 != NULL)
uuid_destroy(uuid2);
return result;
}
/* compare two UUIDs (equality only) */
int uuid_dce_equal(uuid_dce_t *uuid_dce1, uuid_dce_t *uuid_dce2, int *status)
{
/* initialize status */
if (status != NULL)
*status = uuid_s_error;
/* sanity check argument(s) */
if (uuid_dce1 == NULL || uuid_dce2 == NULL)
return 0;
/* pass through to generic compare function */
return (uuid_dce_compare(uuid_dce1, uuid_dce2, status) == 0 ? 1 : 0);
}
/* import UUID from string representation */
void uuid_dce_from_string(const char *str, uuid_dce_t *uuid_dce, int *status)
{
uuid_t *uuid = NULL;
size_t len;
void *vp;
/* initialize status */
if (status != NULL)
*status = uuid_s_error;
/* sanity check argument(s) */
if (str == NULL || uuid_dce == NULL)
return;
/* import string representation and export binary representation */
if (uuid_create(&uuid) != UUID_RC_OK)
LEAVE;
if (uuid_import(uuid, UUID_FMT_STR, str, UUID_LEN_STR) != UUID_RC_OK)
LEAVE;
vp = uuid_dce;
len = UUID_LEN_BIN;
if (uuid_export(uuid, UUID_FMT_BIN, &vp, &len) != UUID_RC_OK)
LEAVE;
/* indicate successful operation */
if (status != NULL)
*status = uuid_s_ok;
/* cleanup and return */
leave:
if (uuid != NULL)
uuid_destroy(uuid);
return;
}
/* export UUID to string representation */
void uuid_dce_to_string(uuid_dce_t *uuid_dce, char **str, int *status)
{
uuid_t *uuid = NULL;
size_t len;
void *vp;
/* initialize status */
if (status != NULL)
*status = uuid_s_error;
/* sanity check argument(s) */
if (str == NULL || uuid_dce == NULL)
return;
/* import binary representation and export string representation */
if (uuid_create(&uuid) != UUID_RC_OK)
LEAVE;
if (uuid_import(uuid, UUID_FMT_BIN, uuid_dce, UUID_LEN_BIN) != UUID_RC_OK)
LEAVE;
vp = str;
len = UUID_LEN_STR;
if (uuid_export(uuid, UUID_FMT_STR, &vp, &len) != UUID_RC_OK)
LEAVE;
/* indicate successful operation */
if (status != NULL)
*status = uuid_s_ok;
/* cleanup and return */
leave:
if (uuid != NULL)
uuid_destroy(uuid);
return;
}
/* export UUID into hash value */
unsigned int uuid_dce_hash(uuid_dce_t *uuid_dce, int *status)
{
int i;
unsigned char *ucp;
unsigned int hash;
/* initialize status */
if (status != NULL)
*status = uuid_s_error;
/* sanity check argument(s) */
if (uuid_dce == NULL)
return 0;
/* generate a hash value
(DCE 1.1 actually requires 16-bit only) */
hash = 0;
ucp = (unsigned char *)uuid_dce;
for (i = UUID_LEN_BIN-1; i >= 0; i--) {
hash <<= 8;
hash |= ucp[i];
}
/* return successfully */
if (status != NULL)
*status = uuid_s_ok;
return hash;
}
+88
View File
@@ -0,0 +1,88 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_dce.h: DCE 1.1 compatibility API definition
*/
#ifndef __UUID_DCE_H___
#define __UUID_DCE_H___
/* sanity check usage */
#ifdef __UUID_H__
#error the regular OSSP uuid API and the DCE 1.1 backward compatibility API are mutually exclusive -- you cannot use them at the same time.
#endif
/* resolve namespace conflicts (at linking level) with regular OSSP uuid API */
#define uuid_create uuid_dce_create
#define uuid_create_nil uuid_dce_create_nil
#define uuid_is_nil uuid_dce_is_nil
#define uuid_compare uuid_dce_compare
#define uuid_equal uuid_dce_equal
#define uuid_from_string uuid_dce_from_string
#define uuid_to_string uuid_dce_to_string
#define uuid_hash uuid_dce_hash
/* DCE 1.1 uuid_t type */
typedef struct {
#if 0
/* stricter but unportable version */
uuid_uint32_t time_low;
uuid_uint16_t time_mid;
uuid_uint16_t time_hi_and_version;
uuid_uint8_t clock_seq_hi_and_reserved;
uuid_uint8_t clock_seq_low;
uuid_uint8_t node[6];
#else
/* sufficient and portable version */
unsigned char data[16];
#endif
} uuid_t;
typedef uuid_t *uuid_p_t;
/* DCE 1.1 uuid_vector_t type */
typedef struct {
unsigned int count;
uuid_t *uuid[1];
} uuid_vector_t;
/* DCE 1.1 UUID API status codes */
enum {
uuid_s_ok = 0, /* standardized */
uuid_s_error = 1 /* implementation specific */
};
/* DCE 1.1 UUID API functions */
extern void uuid_create (uuid_t *, int *);
extern void uuid_create_nil (uuid_t *, int *);
extern int uuid_is_nil (uuid_t *, int *);
extern int uuid_compare (uuid_t *, uuid_t *, int *);
extern int uuid_equal (uuid_t *, uuid_t *, int *);
extern void uuid_from_string (const char *, uuid_t *, int *);
extern void uuid_to_string (uuid_t *, char **, int *);
extern unsigned int uuid_hash (uuid_t *, int *);
#endif /* __UUID_DCE_H___ */
+183
View File
@@ -0,0 +1,183 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_mac.c: Media Access Control (MAC) resolver implementation
*/
/* own headers (part (1/2) */
#include "uuid_ac.h"
/* system headers */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
#ifdef HAVE_NET_IF_DL_H
#include <net/if_dl.h>
#endif
#ifdef HAVE_NET_IF_ARP_H
#include <net/if_arp.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif
/* own headers (part (1/2) */
#include "uuid_mac.h"
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (/*lint -save -e506*/ !FALSE /*lint -restore*/)
#endif
/* return the Media Access Control (MAC) address of
the FIRST network interface card (NIC) */
int mac_address(unsigned char *data_ptr, size_t data_len)
{
/* sanity check arguments */
if (data_ptr == NULL || data_len < MAC_LEN)
return FALSE;
#if defined(HAVE_IFADDRS_H) && defined(HAVE_NET_IF_DL_H) && defined(HAVE_GETIFADDRS)
/* use getifaddrs(3) on BSD class platforms (xxxBSD, MacOS X, etc) */
{
struct ifaddrs *ifap;
struct ifaddrs *ifap_head;
const struct sockaddr_dl *sdl;
unsigned char *ucp;
int i;
if (getifaddrs(&ifap_head) < 0)
return FALSE;
for (ifap = ifap_head; ifap != NULL; ifap = ifap->ifa_next) {
if (ifap->ifa_addr != NULL && ifap->ifa_addr->sa_family == AF_LINK) {
sdl = (const struct sockaddr_dl *)(void *)ifap->ifa_addr;
ucp = (unsigned char *)(sdl->sdl_data + sdl->sdl_nlen);
if (sdl->sdl_alen > 0) {
for (i = 0; i < MAC_LEN && i < sdl->sdl_alen; i++, ucp++)
data_ptr[i] = (unsigned char)(*ucp & 0xff);
freeifaddrs(ifap_head);
return TRUE;
}
}
}
freeifaddrs(ifap_head);
}
#endif
#if defined(HAVE_NET_IF_H) && defined(SIOCGIFHWADDR)
/* use SIOCGIFHWADDR ioctl(2) on Linux class platforms */
{
struct ifreq ifr;
struct sockaddr *sa;
int s;
int i;
if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
return FALSE;
sprintf(ifr.ifr_name, "eth0");
if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
close(s);
return FALSE;
}
sa = (struct sockaddr *)&ifr.ifr_addr;
for (i = 0; i < MAC_LEN; i++)
data_ptr[i] = (unsigned char)(sa->sa_data[i] & 0xff);
close(s);
return TRUE;
}
#endif
#if defined(SIOCGARP)
/* use SIOCGARP ioctl(2) on SVR4 class platforms (Solaris, etc) */
{
char hostname[MAXHOSTNAMELEN];
struct hostent *he;
struct arpreq ar;
struct sockaddr_in *sa;
int s;
int i;
if (gethostname(hostname, sizeof(hostname)) < 0)
return FALSE;
if ((he = gethostbyname(hostname)) == NULL)
return FALSE;
if ((s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
return FALSE;
memset(&ar, 0, sizeof(ar));
sa = (struct sockaddr_in *)((void *)&(ar.arp_pa));
sa->sin_family = AF_INET;
memcpy(&(sa->sin_addr), *(he->h_addr_list), sizeof(struct in_addr));
if (ioctl(s, SIOCGARP, &ar) < 0) {
close(s);
return FALSE;
}
close(s);
if (!(ar.arp_flags & ATF_COM))
return FALSE;
for (i = 0; i < MAC_LEN; i++)
data_ptr[i] = (unsigned char)(ar.arp_ha.sa_data[i] & 0xff);
return TRUE;
}
#endif
return FALSE;
}
+54
View File
@@ -0,0 +1,54 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_mac.h: Media Access Control (MAC) resolver API definition
*/
#ifndef __UUID_MAC_H__
#define __UUID_MAC_H__
#include <string.h> /* size_t */
#define MAC_PREFIX uuid_
/* embedding support */
#ifdef MAC_PREFIX
#if defined(__STDC__) || defined(__cplusplus)
#define __MAC_CONCAT(x,y) x ## y
#define MAC_CONCAT(x,y) __MAC_CONCAT(x,y)
#else
#define __MAC_CONCAT(x) x
#define MAC_CONCAT(x,y) __MAC_CONCAT(x)y
#endif
#define mac_address MAC_CONCAT(MAC_PREFIX,mac_address)
#endif
#define MAC_LEN 6
extern int mac_address(unsigned char *_data_ptr, size_t _data_len);
#endif /* __UUID_MAC_H__ */
+471
View File
@@ -0,0 +1,471 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_md5.c: MD5 API implementation
*/
/* own headers (part 1/2) */
#include "uuid_ac.h"
/* system headers */
#include <stdlib.h>
#include <string.h>
/* own headers (part 2/2) */
#include "uuid_md5.h"
/*
* This is a RFC 1321 compliant Message Digest 5 (MD5) algorithm
* implementation. It is directly derived from the RSA code published in
* RFC 1321 with just the following functionality preserving changes:
* - converted function definitions from K&R to ANSI C
* - included contents of the "global.h" and "md5.h" headers
* - moved the SXX defines into the MD5Transform function
* - replaced MD5_memcpy() with memcpy(3) and MD5_memset() with memset(3)
* - renamed "index" variables to "idx" to avoid namespace conflicts
* - reformatted C style to conform with OSSP C style
* - added own OSSP style frontend API
*/
/*
** ==== BEGIN RFC 1321 CODE ====
*/
/*
* RSA Data Security, Inc., MD5 message-digest algorithm
* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991.
* All rights reserved.
*
* License to copy and use this software is granted provided that it
* is identified as the "RSA Data Security, Inc. MD5 Message-Digest
* Algorithm" in all material mentioning or referencing this software
* or this function.
*
* License is also granted to make and use derivative works provided
* that such works are identified as "derived from the RSA Data
* Security, Inc. MD5 Message-Digest Algorithm" in all material
* mentioning or referencing the derived work.
*
* RSA Data Security, Inc. makes no representations concerning either
* the merchantability of this software or the suitability of this
* software for any particular purpose. It is provided "as is"
* without express or implied warranty of any kind.
*
* These notices must be retained in any copies of any part of this
* documentation and/or software.
*/
/* POINTER defines a generic pointer type */
typedef unsigned char *POINTER;
/* UINT4 defines a four byte word */
#if SIZEOF_UNSIGNED_SHORT == 4
typedef unsigned short int UINT4;
#elif SIZEOF_UNSIGNED_INT == 4
typedef unsigned int UINT4;
#elif SIZEOF_UNSIGNED_LONG == 4
typedef unsigned long int UINT4;
#elif SIZEOF_UNSIGNED_LONG_LONG == 4
typedef unsigned long long int UINT4;
#else
#error ERROR: unable to determine UINT4 type (four byte word)
#endif
/* MD5 context. */
typedef struct {
UINT4 state[4]; /* state (ABCD) */
UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
unsigned char buffer[64]; /* input buffer */
} MD5_CTX;
/* prototypes for internal functions */
static void MD5Init (MD5_CTX *_ctx);
static void MD5Update (MD5_CTX *_ctx, unsigned char *, unsigned int);
static void MD5Final (unsigned char [], MD5_CTX *);
static void MD5Transform (UINT4 [], unsigned char []);
static void Encode (unsigned char *, UINT4 *, unsigned int);
static void Decode (UINT4 *, unsigned char *, unsigned int);
/* finalization padding */
static unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/* F, G, H and I are basic MD5 functions. */
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits. */
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
Rotation is separate from addition to prevent recomputation. */
#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
static void MD5Init(
MD5_CTX *context)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants. */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
return;
}
/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context. */
static void MD5Update(
MD5_CTX *context, /* context */
unsigned char *input, /* input block */
unsigned int inputLen) /* length of input block */
{
unsigned int i, idx, partLen;
/* Compute number of bytes mod 64 */
idx = (unsigned int)((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
if ((context->count[0] += ((UINT4)inputLen << 3)) < ((UINT4)inputLen << 3))
context->count[1]++;
context->count[1] += ((UINT4)inputLen >> 29);
partLen = (unsigned int)64 - idx;
/* Transform as many times as possible. */
if (inputLen >= partLen) {
memcpy((POINTER)&context->buffer[idx], (POINTER)input, (size_t)partLen);
MD5Transform(context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
MD5Transform(context->state, &input[i]);
idx = 0;
}
else
i = 0;
/* Buffer remaining input */
memcpy((POINTER)&context->buffer[idx], (POINTER)&input[i], (size_t)(inputLen - i));
}
/* MD5 finalization. Ends an MD5 message-digest operation, writing the
the message digest and zeroizing the context. */
static void MD5Final(
unsigned char digest[], /* message digest */
MD5_CTX *context) /* context */
{
unsigned char bits[8];
unsigned int idx, padLen;
/* Save number of bits */
Encode(bits, context->count, 8);
/* Pad out to 56 mod 64. */
idx = (unsigned int)((context->count[0] >> 3) & 0x3f);
padLen = (idx < 56) ? ((unsigned int)56 - idx) : ((unsigned int)120 - idx);
MD5Update(context, PADDING, padLen);
/* Append length (before padding) */
MD5Update(context, bits, 8);
/* Store state in digest */
Encode(digest, context->state, 16);
/* Zeroize sensitive information. */
memset((POINTER)context, 0, sizeof(*context));
}
/* MD5 basic transformation. Transforms state based on block. */
static void MD5Transform(
UINT4 state[],
unsigned char block[])
{
UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
Decode(x, block, 64);
/* Round 1 */
#define S11 7
#define S12 12
#define S13 17
#define S14 22
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
#define S21 5
#define S22 9
#define S23 14
#define S24 20
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
#define S31 4
#define S32 11
#define S33 16
#define S34 23
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
#define S41 6
#define S42 10
#define S43 15
#define S44 21
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
/* Zeroize sensitive information. */
memset((POINTER)x, 0, sizeof(x));
}
/* Encodes input (UINT4) into output (unsigned char).
Assumes len is a multiple of 4. */
static void Encode(
unsigned char *output,
UINT4 *input,
unsigned int len)
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (unsigned char)( input[i] & 0xff);
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
}
return;
}
/* Decodes input (unsigned char) into output (UINT4).
Assumes len is a multiple of 4. */
static void Decode(
UINT4 *output,
unsigned char *input,
unsigned int len)
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = ( (UINT4)input[j])
| (((UINT4)input[j+1]) << 8 )
| (((UINT4)input[j+2]) << 16)
| (((UINT4)input[j+3]) << 24);
return;
}
/*
** ==== END RFC 1321 CODE ====
*/
struct md5_st {
MD5_CTX ctx;
};
md5_rc_t md5_create(md5_t **md5)
{
if (md5 == NULL)
return MD5_RC_ARG;
if ((*md5 = (md5_t *)malloc(sizeof(md5_t))) == NULL)
return MD5_RC_MEM;
MD5Init(&((*md5)->ctx));
return MD5_RC_OK;
}
md5_rc_t md5_init(md5_t *md5)
{
if (md5 == NULL)
return MD5_RC_ARG;
MD5Init(&(md5->ctx));
return MD5_RC_OK;
}
md5_rc_t md5_update(md5_t *md5, const void *data_ptr, size_t data_len)
{
if (md5 == NULL)
return MD5_RC_ARG;
MD5Update(&(md5->ctx), (unsigned char *)data_ptr, (unsigned int)data_len);
return MD5_RC_OK;
}
md5_rc_t md5_store(md5_t *md5, void **data_ptr, size_t *data_len)
{
MD5_CTX ctx;
if (md5 == NULL || data_ptr == NULL)
return MD5_RC_ARG;
if (*data_ptr == NULL) {
if ((*data_ptr = malloc(MD5_LEN_BIN)) == NULL)
return MD5_RC_MEM;
if (data_len != NULL)
*data_len = MD5_LEN_BIN;
}
else {
if (data_len != NULL) {
if (*data_len < MD5_LEN_BIN)
return MD5_RC_MEM;
*data_len = MD5_LEN_BIN;
}
}
memcpy((void *)(&ctx), (void *)(&(md5->ctx)), sizeof(MD5_CTX));
MD5Final((unsigned char *)(*data_ptr), &(ctx));
return MD5_RC_OK;
}
md5_rc_t md5_format(md5_t *md5, char **data_ptr, size_t *data_len)
{
static const char hex[] = "0123456789abcdef";
unsigned char buf[MD5_LEN_BIN];
unsigned char *bufptr;
size_t buflen;
md5_rc_t rc;
int i;
if (md5 == NULL || data_ptr == NULL)
return MD5_RC_ARG;
if (*data_ptr == NULL) {
if ((*data_ptr = (char *)malloc(MD5_LEN_STR+1)) == NULL)
return MD5_RC_MEM;
if (data_len != NULL)
*data_len = MD5_LEN_STR+1;
}
else {
if (data_len != NULL) {
if (*data_len < MD5_LEN_STR+1)
return MD5_RC_MEM;
*data_len = MD5_LEN_STR+1;
}
}
bufptr = buf;
buflen = sizeof(buf);
if ((rc = md5_store(md5, (void **)((void *)&bufptr), &buflen)) != MD5_RC_OK)
return rc;
for (i = 0; i < (int)buflen; i++) {
(*data_ptr)[(i*2)+0] = hex[(int)(bufptr[i] >> 4)];
(*data_ptr)[(i*2)+1] = hex[(int)(bufptr[i] & 0x0f)];
}
(*data_ptr)[(i*2)] = '\0';
return MD5_RC_OK;
}
md5_rc_t md5_destroy(md5_t *md5)
{
if (md5 == NULL)
return MD5_RC_ARG;
free(md5);
return MD5_RC_OK;
}
+76
View File
@@ -0,0 +1,76 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_md5.h: MD5 API definition
*/
#ifndef __MD5_H___
#define __MD5_H___
#include <string.h> /* size_t */
#define MD5_PREFIX uuid_
/* embedding support */
#ifdef MD5_PREFIX
#if defined(__STDC__) || defined(__cplusplus)
#define __MD5_CONCAT(x,y) x ## y
#define MD5_CONCAT(x,y) __MD5_CONCAT(x,y)
#else
#define __MD5_CONCAT(x) x
#define MD5_CONCAT(x,y) __MD5_CONCAT(x)y
#endif
#define md5_st MD5_CONCAT(MD5_PREFIX,md5_st)
#define md5_t MD5_CONCAT(MD5_PREFIX,md5_t)
#define md5_create MD5_CONCAT(MD5_PREFIX,md5_create)
#define md5_init MD5_CONCAT(MD5_PREFIX,md5_init)
#define md5_update MD5_CONCAT(MD5_PREFIX,md5_update)
#define md5_store MD5_CONCAT(MD5_PREFIX,md5_store)
#define md5_format MD5_CONCAT(MD5_PREFIX,md5_format)
#define md5_destroy MD5_CONCAT(MD5_PREFIX,md5_destroy)
#endif
struct md5_st;
typedef struct md5_st md5_t;
#define MD5_LEN_BIN 16
#define MD5_LEN_STR 32
typedef enum {
MD5_RC_OK = 0,
MD5_RC_ARG = 1,
MD5_RC_MEM = 2
} md5_rc_t;
extern md5_rc_t md5_create (md5_t **md5);
extern md5_rc_t md5_init (md5_t *md5);
extern md5_rc_t md5_update (md5_t *md5, const void *data_ptr, size_t data_len);
extern md5_rc_t md5_store (md5_t *md5, void **data_ptr, size_t *data_len);
extern md5_rc_t md5_format (md5_t *md5, char **data_ptr, size_t *data_len);
extern md5_rc_t md5_destroy (md5_t *md5);
#endif /* __MD5_H___ */
+198
View File
@@ -0,0 +1,198 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_prng.c: PRNG API implementation
*/
/* own headers (part 1/2) */
#include "uuid_ac.h"
/* system headers */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <fcntl.h>
#if defined(WIN32)
#define WINVER 0x0500
#include <windows.h>
#include <wincrypt.h>
#endif
/* own headers (part 2/2) */
#include "uuid_time.h"
#include "uuid_prng.h"
#include "uuid_md5.h"
struct prng_st {
int dev; /* system PRNG device */
md5_t *md5; /* local MD5 PRNG engine */
long cnt; /* time resolution compensation counter */
};
prng_rc_t prng_create(prng_t **prng)
{
#if !defined(WIN32)
int fd = -1;
#endif
struct timeval tv;
pid_t pid;
unsigned int i;
/* sanity check argument(s) */
if (prng == NULL)
return PRNG_RC_ARG;
/* allocate object */
if ((*prng = (prng_t *)malloc(sizeof(prng_t))) == NULL)
return PRNG_RC_MEM;
/* try to open the system PRNG device */
(*prng)->dev = -1;
#if !defined(WIN32)
if ((fd = open("/dev/urandom", O_RDONLY)) == -1)
fd = open("/dev/random", O_RDONLY|O_NONBLOCK);
if (fd != -1) {
(void)fcntl(fd, F_SETFD, FD_CLOEXEC);
(*prng)->dev = fd;
}
#endif
/* initialize MD5 engine */
if (md5_create(&((*prng)->md5)) != MD5_RC_OK) {
free(*prng);
return PRNG_RC_INT;
}
/* initialize time resolution compensation counter */
(*prng)->cnt = 0;
/* seed the C library PRNG once */
(void)time_gettimeofday(&tv);
pid = getpid();
srand((unsigned int)(
((unsigned int)pid << 16)
^ (unsigned int)pid
^ (unsigned int)tv.tv_sec
^ (unsigned int)tv.tv_usec));
for (i = (unsigned int)((tv.tv_sec ^ tv.tv_usec) & 0x1F); i > 0; i--)
(void)rand();
return PRNG_RC_OK;
}
prng_rc_t prng_data(prng_t *prng, void *data_ptr, size_t data_len)
{
size_t n;
unsigned char *p;
struct {
struct timeval tv;
long cnt;
int rnd;
} entropy;
unsigned char md5_buf[MD5_LEN_BIN];
unsigned char *md5_ptr;
size_t md5_len;
int retries;
int i;
#if defined(WIN32)
HCRYPTPROV hProv;
#endif
/* sanity check argument(s) */
if (prng == NULL || data_len == 0)
return PRNG_RC_ARG;
/* prepare for generation */
p = (unsigned char *)data_ptr;
n = data_len;
/* approach 1: try to gather data via stronger system PRNG device */
if (prng->dev != -1) {
retries = 0;
while (n > 0) {
i = (int)read(prng->dev, (void *)p, n);
if (i <= 0) {
if (retries++ > 16)
break;
continue;
}
retries = 0;
n -= (unsigned int)i;
p += (unsigned int)i;
}
}
#if defined(WIN32)
else {
if (CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0))
CryptGenRandom(hProv, n, p);
}
#endif
/* approach 2: try to gather data via weaker libc PRNG API. */
while (n > 0) {
/* gather new entropy */
(void)time_gettimeofday(&(entropy.tv)); /* source: libc time */
entropy.rnd = rand(); /* source: libc PRNG */
entropy.cnt = prng->cnt++; /* source: local counter */
/* pass entropy into MD5 engine */
if (md5_update(prng->md5, (void *)&entropy, sizeof(entropy)) != MD5_RC_OK)
return PRNG_RC_INT;
/* store MD5 engine state as PRN output */
md5_ptr = md5_buf;
md5_len = sizeof(md5_buf);
if (md5_store(prng->md5, (void **)(void *)&md5_ptr, &md5_len) != MD5_RC_OK)
return PRNG_RC_INT;
for (i = 0; i < MD5_LEN_BIN && n > 0; i++, n--)
*p++ ^= md5_buf[i]; /* intentionally no assignment because arbitrary
caller buffer content is leveraged, too */
}
return PRNG_RC_OK;
}
prng_rc_t prng_destroy(prng_t *prng)
{
/* sanity check argument(s) */
if (prng == NULL)
return PRNG_RC_ARG;
/* close PRNG device */
if (prng->dev != -1)
(void)close(prng->dev);
/* destroy MD5 engine */
(void)md5_destroy(prng->md5);
/* free object */
free(prng);
return PRNG_RC_OK;
}
+68
View File
@@ -0,0 +1,68 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_prng.h: PRNG API definition
*/
#ifndef __PRNG_H___
#define __PRNG_H___
#include <string.h> /* size_t */
#define PRNG_PREFIX uuid_
/* embedding support */
#ifdef PRNG_PREFIX
#if defined(__STDC__) || defined(__cplusplus)
#define __PRNG_CONCAT(x,y) x ## y
#define PRNG_CONCAT(x,y) __PRNG_CONCAT(x,y)
#else
#define __PRNG_CONCAT(x) x
#define PRNG_CONCAT(x,y) __PRNG_CONCAT(x)y
#endif
#define prng_st PRNG_CONCAT(PRNG_PREFIX,prng_st)
#define prng_t PRNG_CONCAT(PRNG_PREFIX,prng_t)
#define prng_create PRNG_CONCAT(PRNG_PREFIX,prng_create)
#define prng_data PRNG_CONCAT(PRNG_PREFIX,prng_data)
#define prng_destroy PRNG_CONCAT(PRNG_PREFIX,prng_destroy)
#endif
struct prng_st;
typedef struct prng_st prng_t;
typedef enum {
PRNG_RC_OK = 0,
PRNG_RC_ARG = 1,
PRNG_RC_MEM = 2,
PRNG_RC_INT = 3
} prng_rc_t;
extern prng_rc_t prng_create (prng_t **prng);
extern prng_rc_t prng_data (prng_t *prng, void *data_ptr, size_t data_len);
extern prng_rc_t prng_destroy (prng_t *prng);
#endif /* __PRNG_H___ */
+450
View File
@@ -0,0 +1,450 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_sha1.c: SHA-1 API implementation
*/
/* own headers (part 1/2) */
#include "uuid_ac.h"
/* system headers */
#include <stdlib.h>
#include <string.h>
/* own headers (part 2/2) */
#include "uuid_sha1.h"
/*
* This is a RFC 3174 compliant Secure Hash Function (SHA-1) algorithm
* implementation. It is directly derived from the SHA-1 reference
* code published in RFC 3174 with just the following functionality
* preserving changes:
* - reformatted C style to conform with OSSP C style
* - added own OSSP style frontend API
* - added Autoconf based determination of sha1_uintX_t types
*/
/*
** ==== BEGIN RFC 3174 CODE ====
*/
/*
* This implements the Secure Hashing Algorithm 1 as defined in
* FIPS PUB 180-1 published April 17, 1995.
*
* The SHA-1, produces a 160-bit message digest for a given data
* stream. It should take about 2**n steps to find a message with the
* same digest as a given message and 2**(n/2) to find any two messages
* with the same digest, when n is the digest size in bits. Therefore,
* this algorithm can serve as a means of providing a "fingerprint" for
* a message.
*
* Caveats: SHA-1 is designed to work with messages less than 2^64 bits
* long. Although SHA-1 allows a message digest to be generated for
* messages of any number of bits less than 2^64, this implementation
* only works with messages with a length that is a multiple of the
* size of an 8-bit character.
*/
typedef unsigned char sha1_uint8_t;
#if SIZEOF_SHORT > 2
typedef short int sha1_int16plus_t;
#elif SIZEOF_INT > 2
typedef int sha1_int16plus_t;
#elif SIZEOF_LONG > 2
typedef long int sha1_int16plus_t;
#else
#error ERROR: unable to determine sha1_int16plus_t type (at least two byte word)
#endif
#if SIZEOF_UNSIGNED_SHORT == 4
typedef unsigned short int sha1_uint32_t;
#elif SIZEOF_UNSIGNED_INT == 4
typedef unsigned int sha1_uint32_t;
#elif SIZEOF_UNSIGNED_LONG == 4
typedef unsigned long int sha1_uint32_t;
#elif SIZEOF_UNSIGNED_LONG_LONG == 4
typedef unsigned long long int sha1_uint32_t;
#else
#error ERROR: unable to determine sha1_uint32_t type (four byte word)
#endif
enum {
shaSuccess = 0,
shaNull, /* null pointer parameter */
shaStateError /* called Input after Result */
};
#define SHA1HashSize 20
/* This structure will hold context information for the SHA-1 hashing operation */
typedef struct SHA1Context {
sha1_uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */
sha1_uint32_t Length_Low; /* Message length in bits */
sha1_uint32_t Length_High; /* Message length in bits */
sha1_int16plus_t Message_Block_Index; /* Index into message block array */
sha1_uint8_t Message_Block[64]; /* 512-bit message blocks */
int Computed; /* Is the digest computed? */
int Corrupted; /* Is the message digest corrupted? */
} SHA1Context;
/* Function Prototypes */
static int SHA1Reset (SHA1Context *);
static int SHA1Input (SHA1Context *, const sha1_uint8_t *, unsigned int);
static int SHA1Result (SHA1Context *, sha1_uint8_t Message_Digest[]);
/* Local Function Prototyptes */
static void SHA1PadMessage (SHA1Context *);
static void SHA1ProcessMessageBlock(SHA1Context *);
/* Define the SHA1 circular left shift macro */
#define SHA1CircularShift(bits,word) \
(((word) << (bits)) | ((word) >> (32-(bits))))
/*
* This function will initialize the SHA1Context in preparation for
* computing a new SHA1 message digest.
*/
static int SHA1Reset(SHA1Context *context)
{
if (context == NULL)
return shaNull;
context->Length_Low = 0;
context->Length_High = 0;
context->Message_Block_Index = 0;
context->Intermediate_Hash[0] = 0x67452301;
context->Intermediate_Hash[1] = 0xEFCDAB89;
context->Intermediate_Hash[2] = 0x98BADCFE;
context->Intermediate_Hash[3] = 0x10325476;
context->Intermediate_Hash[4] = 0xC3D2E1F0;
context->Computed = 0;
context->Corrupted = 0;
return shaSuccess;
}
/*
* This function will return the 160-bit message digest into the
* Message_Digest array provided by the caller. NOTE: The first octet
* of hash is stored in the 0th element, the last octet of hash in the
* 19th element.
*/
static int SHA1Result(SHA1Context *context, sha1_uint8_t Message_Digest[])
{
int i;
if (context == NULL || Message_Digest == NULL)
return shaNull;
if (context->Corrupted)
return context->Corrupted;
if (!context->Computed) {
SHA1PadMessage(context);
for (i = 0; i < 64; i++) {
/* message may be sensitive, clear it out */
context->Message_Block[i] = (sha1_uint8_t)0;
}
context->Length_Low = 0; /* and clear length */
context->Length_High = 0;
context->Computed = 1;
}
for (i = 0; i < SHA1HashSize; i++)
Message_Digest[i] = (sha1_uint8_t)(context->Intermediate_Hash[i>>2] >> (8 * (3 - (i & 0x03))));
return shaSuccess;
}
/*
* This function accepts an array of octets as the next portion of the
* message.
*/
static int SHA1Input(SHA1Context *context, const sha1_uint8_t *message_array, unsigned int length)
{
if (length == 0)
return shaSuccess;
if (context == NULL || message_array == NULL)
return shaNull;
if (context->Computed) {
context->Corrupted = shaStateError;
return shaStateError;
}
if (context->Corrupted)
return context->Corrupted;
while (length-- && !context->Corrupted) {
context->Message_Block[context->Message_Block_Index++] = (*message_array & 0xFF);
context->Length_Low += 8;
if (context->Length_Low == 0) {
context->Length_High++;
if (context->Length_High == 0)
context->Corrupted = 1; /* Message is too long */
}
if (context->Message_Block_Index == 64)
SHA1ProcessMessageBlock(context);
message_array++;
}
return shaSuccess;
}
/*
* This function will process the next 512 bits of the message stored
* in the Message_Block array. NOTICE: Many of the variable names in
* this code, especially the single character names, were used because
* those were the names used in the publication.
*/
static void SHA1ProcessMessageBlock(SHA1Context *context)
{
const sha1_uint32_t K[] = { /* Constants defined in SHA-1 */
0x5A827999,
0x6ED9EBA1,
0x8F1BBCDC,
0xCA62C1D6
};
int t; /* Loop counter */
sha1_uint32_t temp; /* Temporary word value */
sha1_uint32_t W[80]; /* Word sequence */
sha1_uint32_t A, B, C, D, E; /* Word buffers */
/* Initialize the first 16 words in the array W */
for (t = 0; t < 16; t++) {
W[t] = (sha1_uint32_t)(context->Message_Block[t * 4 ] << 24);
W[t] |= (sha1_uint32_t)(context->Message_Block[t * 4 + 1] << 16);
W[t] |= (sha1_uint32_t)(context->Message_Block[t * 4 + 2] << 8);
W[t] |= (sha1_uint32_t)(context->Message_Block[t * 4 + 3] );
}
for (t = 16; t < 80; t++)
W[t] = SHA1CircularShift(1, W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
A = context->Intermediate_Hash[0];
B = context->Intermediate_Hash[1];
C = context->Intermediate_Hash[2];
D = context->Intermediate_Hash[3];
E = context->Intermediate_Hash[4];
for (t = 0; t < 20; t++) {
temp = SHA1CircularShift(5, A) + ((B & C) | ((~B) & D)) + E + W[t] + K[0];
E = D;
D = C;
C = SHA1CircularShift(30, B);
B = A;
A = temp;
}
for (t = 20; t < 40; t++) {
temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[t] + K[1];
E = D;
D = C;
C = SHA1CircularShift(30, B);
B = A;
A = temp;
}
for (t = 40; t < 60; t++) {
temp = SHA1CircularShift(5, A) + ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
E = D;
D = C;
C = SHA1CircularShift(30, B);
B = A;
A = temp;
}
for (t = 60; t < 80; t++) {
temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[t] + K[3];
E = D;
D = C;
C = SHA1CircularShift(30, B);
B = A;
A = temp;
}
context->Intermediate_Hash[0] += A;
context->Intermediate_Hash[1] += B;
context->Intermediate_Hash[2] += C;
context->Intermediate_Hash[3] += D;
context->Intermediate_Hash[4] += E;
context->Message_Block_Index = 0;
return;
}
/*
* According to the standard, the message must be padded to an even
* 512 bits. The first padding bit must be a '1'. The last 64 bits
* represent the length of the original message. All bits in between
* should be 0. This function will pad the message according to those
* rules by filling the Message_Block array accordingly. It will also
* call the ProcessMessageBlock function provided appropriately. When
* it returns, it can be assumed that the message digest has been
* computed.
*/
static void SHA1PadMessage(SHA1Context *context)
{
/* Check to see if the current message block is too small to hold
the initial padding bits and length. If so, we will pad the block,
process it, and then continue padding into a second block. */
if (context->Message_Block_Index > 55) {
context->Message_Block[context->Message_Block_Index++] = (sha1_uint8_t)0x80;
while (context->Message_Block_Index < 64)
context->Message_Block[context->Message_Block_Index++] = (sha1_uint8_t)0;
SHA1ProcessMessageBlock(context);
while(context->Message_Block_Index < 56)
context->Message_Block[context->Message_Block_Index++] = (sha1_uint8_t)0;
}
else {
context->Message_Block[context->Message_Block_Index++] = (sha1_uint8_t)0x80;
while(context->Message_Block_Index < 56)
context->Message_Block[context->Message_Block_Index++] = (sha1_uint8_t)0;
}
/* Store the message length as the last 8 octets */
context->Message_Block[56] = (sha1_uint8_t)(context->Length_High >> 24);
context->Message_Block[57] = (sha1_uint8_t)(context->Length_High >> 16);
context->Message_Block[58] = (sha1_uint8_t)(context->Length_High >> 8);
context->Message_Block[59] = (sha1_uint8_t)(context->Length_High );
context->Message_Block[60] = (sha1_uint8_t)(context->Length_Low >> 24);
context->Message_Block[61] = (sha1_uint8_t)(context->Length_Low >> 16);
context->Message_Block[62] = (sha1_uint8_t)(context->Length_Low >> 8);
context->Message_Block[63] = (sha1_uint8_t)(context->Length_Low );
SHA1ProcessMessageBlock(context);
return;
}
/*
** ==== END RFC 3174 CODE ====
*/
struct sha1_st {
SHA1Context ctx;
};
sha1_rc_t sha1_create(sha1_t **sha1)
{
if (sha1 == NULL)
return SHA1_RC_ARG;
if ((*sha1 = (sha1_t *)malloc(sizeof(sha1_t))) == NULL)
return SHA1_RC_MEM;
if (SHA1Reset(&((*sha1)->ctx)) != shaSuccess)
return SHA1_RC_INT;
return SHA1_RC_OK;
}
sha1_rc_t sha1_init(sha1_t *sha1)
{
if (sha1 == NULL)
return SHA1_RC_ARG;
if (SHA1Reset(&(sha1->ctx)) != shaSuccess)
return SHA1_RC_INT;
return SHA1_RC_OK;
}
sha1_rc_t sha1_update(sha1_t *sha1, const void *data_ptr, size_t data_len)
{
if (sha1 == NULL)
return SHA1_RC_ARG;
if (SHA1Input(&(sha1->ctx), (unsigned char *)data_ptr, (unsigned int)data_len) != shaSuccess)
return SHA1_RC_INT;
return SHA1_RC_OK;
}
sha1_rc_t sha1_store(sha1_t *sha1, void **data_ptr, size_t *data_len)
{
SHA1Context ctx;
if (sha1 == NULL || data_ptr == NULL)
return SHA1_RC_ARG;
if (*data_ptr == NULL) {
if ((*data_ptr = malloc(SHA1_LEN_BIN)) == NULL)
return SHA1_RC_MEM;
if (data_len != NULL)
*data_len = SHA1_LEN_BIN;
}
else {
if (data_len != NULL) {
if (*data_len < SHA1_LEN_BIN)
return SHA1_RC_MEM;
*data_len = SHA1_LEN_BIN;
}
}
memcpy((void *)(&ctx), (void *)(&(sha1->ctx)), sizeof(SHA1Context));
if (SHA1Result(&(ctx), (unsigned char *)(*data_ptr)) != shaSuccess)
return SHA1_RC_INT;
return SHA1_RC_OK;
}
sha1_rc_t sha1_format(sha1_t *sha1, char **data_ptr, size_t *data_len)
{
static const char hex[] = "0123456789abcdef";
unsigned char buf[SHA1_LEN_BIN];
unsigned char *bufptr;
size_t buflen;
sha1_rc_t rc;
int i;
if (sha1 == NULL || data_ptr == NULL)
return SHA1_RC_ARG;
if (*data_ptr == NULL) {
if ((*data_ptr = (char *)malloc(SHA1_LEN_STR+1)) == NULL)
return SHA1_RC_MEM;
if (data_len != NULL)
*data_len = SHA1_LEN_STR+1;
}
else {
if (data_len != NULL) {
if (*data_len < SHA1_LEN_STR+1)
return SHA1_RC_MEM;
*data_len = SHA1_LEN_STR+1;
}
}
bufptr = buf;
buflen = sizeof(buf);
if ((rc = sha1_store(sha1, (void **)((void *)&bufptr), &buflen)) != SHA1_RC_OK)
return rc;
for (i = 0; i < (int)buflen; i++) {
(*data_ptr)[(i*2)+0] = hex[(int)(bufptr[i] >> 4)];
(*data_ptr)[(i*2)+1] = hex[(int)(bufptr[i] & 0x0f)];
}
(*data_ptr)[(i*2)] = '\0';
return SHA1_RC_OK;
}
sha1_rc_t sha1_destroy(sha1_t *sha1)
{
if (sha1 == NULL)
return SHA1_RC_ARG;
free(sha1);
return SHA1_RC_OK;
}
+77
View File
@@ -0,0 +1,77 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_sha1.h: SHA-1 API definition
*/
#ifndef __SHA1_H___
#define __SHA1_H___
#include <string.h> /* size_t */
#define SHA1_PREFIX uuid_
/* embedding support */
#ifdef SHA1_PREFIX
#if defined(__STDC__) || defined(__cplusplus)
#define __SHA1_CONCAT(x,y) x ## y
#define SHA1_CONCAT(x,y) __SHA1_CONCAT(x,y)
#else
#define __SHA1_CONCAT(x) x
#define SHA1_CONCAT(x,y) __SHA1_CONCAT(x)y
#endif
#define sha1_st SHA1_CONCAT(SHA1_PREFIX,sha1_st)
#define sha1_t SHA1_CONCAT(SHA1_PREFIX,sha1_t)
#define sha1_create SHA1_CONCAT(SHA1_PREFIX,sha1_create)
#define sha1_init SHA1_CONCAT(SHA1_PREFIX,sha1_init)
#define sha1_update SHA1_CONCAT(SHA1_PREFIX,sha1_update)
#define sha1_store SHA1_CONCAT(SHA1_PREFIX,sha1_store)
#define sha1_format SHA1_CONCAT(SHA1_PREFIX,sha1_format)
#define sha1_destroy SHA1_CONCAT(SHA1_PREFIX,sha1_destroy)
#endif
struct sha1_st;
typedef struct sha1_st sha1_t;
#define SHA1_LEN_BIN 20
#define SHA1_LEN_STR 40
typedef enum {
SHA1_RC_OK = 0,
SHA1_RC_ARG = 1,
SHA1_RC_MEM = 2,
SHA1_RC_INT = 3
} sha1_rc_t;
extern sha1_rc_t sha1_create (sha1_t **sha1);
extern sha1_rc_t sha1_init (sha1_t *sha1);
extern sha1_rc_t sha1_update (sha1_t *sha1, const void *data_ptr, size_t data_len);
extern sha1_rc_t sha1_store (sha1_t *sha1, void **data_ptr, size_t *data_len);
extern sha1_rc_t sha1_format (sha1_t *sha1, char **data_ptr, size_t *data_len);
extern sha1_rc_t sha1_destroy (sha1_t *sha1);
#endif /* __SHA1_H___ */
+762
View File
@@ -0,0 +1,762 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_str.c: string formatting functions
*/
/*
* Copyright Patrick Powell 1995
* This code is based on code written by Patrick Powell <papowell@astart.com>
* It may be used for any purpose as long as this notice remains intact
* on all source code distributions.
*/
/*
* This code contains numerious changes and enhancements which were
* made by lots of contributors over the last years to Patrick Powell's
* original code:
*
* o Patrick Powell <papowell@astart.com> (1995)
* o Brandon Long <blong@fiction.net> (1996, for Mutt)
* o Thomas Roessler <roessler@guug.de> (1998, for Mutt)
* o Michael Elkins <me@cs.hmc.edu> (1998, for Mutt)
* o Andrew Tridgell <tridge@samba.org> (1998, for Samba)
* o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)
* o Ralf S. Engelschall <rse@engelschall.com> (1999, for OSSP)
*/
/* own headers (part 1/2) */
#include "uuid_ac.h"
/* system headers */
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
/* own headers (part 2/2) */
#include "uuid_str.h"
#if HAVE_LONG_LONG
#define LLONG long long
#else
#define LLONG long
#endif
#if HAVE_LONG_DOUBLE
#define LDOUBLE long double
#else
#define LDOUBLE double
#endif
static void fmtstr (char *, size_t *, size_t, char *, int, int, int);
static void fmtint (char *, size_t *, size_t, LLONG, int, int, int, int);
static void fmtfp (char *, size_t *, size_t, LDOUBLE, int, int, int);
static void dopr_outch (char *, size_t *, size_t, int);
/* format read states */
#define DP_S_DEFAULT 0
#define DP_S_FLAGS 1
#define DP_S_MIN 2
#define DP_S_DOT 3
#define DP_S_MAX 4
#define DP_S_MOD 5
#define DP_S_CONV 6
#define DP_S_DONE 7
/* format flags - Bits */
#define DP_F_MINUS (1 << 0)
#define DP_F_PLUS (1 << 1)
#define DP_F_SPACE (1 << 2)
#define DP_F_NUM (1 << 3)
#define DP_F_ZERO (1 << 4)
#define DP_F_UP (1 << 5)
#define DP_F_UNSIGNED (1 << 6)
/* conversion flags */
#define DP_C_SHORT 1
#define DP_C_LONG 2
#define DP_C_LDOUBLE 3
#define DP_C_LLONG 4
/* some handy macros */
#define char_to_int(p) (p - '0')
#define STR_MAX(p,q) ((p >= q) ? p : q)
#define NUL '\0'
static void
dopr(
char *buffer,
size_t maxlen,
size_t *retlen,
const char *format,
va_list args)
{
char ch;
LLONG value;
LDOUBLE fvalue;
char *strvalue;
int min;
int max;
int state;
int flags;
int cflags;
size_t currlen;
state = DP_S_DEFAULT;
flags = currlen = cflags = min = 0;
max = -1;
ch = *format++;
if (buffer == NULL)
maxlen = 999999;
while (state != DP_S_DONE) {
if ((ch == NUL) || (currlen >= maxlen))
state = DP_S_DONE;
switch (state) {
case DP_S_DEFAULT:
if (ch == '%')
state = DP_S_FLAGS;
else
dopr_outch(buffer, &currlen, maxlen, ch);
ch = *format++;
break;
case DP_S_FLAGS:
switch (ch) {
case '-':
flags |= DP_F_MINUS;
ch = *format++;
break;
case '+':
flags |= DP_F_PLUS;
ch = *format++;
break;
case ' ':
flags |= DP_F_SPACE;
ch = *format++;
break;
case '#':
flags |= DP_F_NUM;
ch = *format++;
break;
case '0':
flags |= DP_F_ZERO;
ch = *format++;
break;
default:
state = DP_S_MIN;
break;
}
break;
case DP_S_MIN:
if (isdigit((unsigned char)ch)) {
min = 10 * min + char_to_int(ch);
ch = *format++;
} else if (ch == '*') {
min = va_arg(args, int);
ch = *format++;
state = DP_S_DOT;
} else
state = DP_S_DOT;
break;
case DP_S_DOT:
if (ch == '.') {
state = DP_S_MAX;
ch = *format++;
} else
state = DP_S_MOD;
break;
case DP_S_MAX:
if (isdigit((unsigned char)ch)) {
if (max < 0)
max = 0;
max = 10 * max + char_to_int(ch);
ch = *format++;
} else if (ch == '*') {
max = va_arg(args, int);
ch = *format++;
state = DP_S_MOD;
} else
state = DP_S_MOD;
break;
case DP_S_MOD:
switch (ch) {
case 'h':
cflags = DP_C_SHORT;
ch = *format++;
break;
case 'l':
if (*format == 'l') {
cflags = DP_C_LLONG;
format++;
} else
cflags = DP_C_LONG;
ch = *format++;
break;
case 'q':
cflags = DP_C_LLONG;
ch = *format++;
break;
case 'L':
cflags = DP_C_LDOUBLE;
ch = *format++;
break;
default:
break;
}
state = DP_S_CONV;
break;
case DP_S_CONV:
switch (ch) {
case 'd':
case 'i':
switch (cflags) {
case DP_C_SHORT:
value = (short int)va_arg(args, int);
break;
case DP_C_LONG:
value = va_arg(args, long int);
break;
case DP_C_LLONG:
value = va_arg(args, LLONG);
break;
default:
value = va_arg(args, int);
break;
}
fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags);
break;
case 'X':
flags |= DP_F_UP;
/* FALLTHROUGH */
case 'x':
case 'o':
case 'u':
flags |= DP_F_UNSIGNED;
switch (cflags) {
case DP_C_SHORT:
value = (unsigned short int)va_arg(args, unsigned int);
break;
case DP_C_LONG:
value = (LLONG)va_arg(args, unsigned long int);
break;
case DP_C_LLONG:
value = va_arg(args, unsigned LLONG);
break;
default:
value = (LLONG)va_arg(args, unsigned int);
break;
}
fmtint(buffer, &currlen, maxlen, value,
ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
min, max, flags);
break;
case 'f':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags);
break;
case 'E':
flags |= DP_F_UP;
/* FALLTHROUGH */
case 'e':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
break;
case 'G':
flags |= DP_F_UP;
/* FALLTHROUGH */
case 'g':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
break;
case 'c':
dopr_outch(buffer, &currlen, maxlen, va_arg(args, int));
break;
case 's':
strvalue = va_arg(args, char *);
if (max < 0)
max = maxlen;
fmtstr(buffer, &currlen, maxlen, strvalue, flags, min, max);
break;
case 'p':
value = (long)va_arg(args, void *);
fmtint(buffer, &currlen, maxlen, value, 16, min, max, flags);
break;
case 'n': /* XXX */
if (cflags == DP_C_SHORT) {
short int *num;
num = va_arg(args, short int *);
*num = currlen;
} else if (cflags == DP_C_LONG) { /* XXX */
long int *num;
num = va_arg(args, long int *);
*num = (long int) currlen;
} else if (cflags == DP_C_LLONG) { /* XXX */
LLONG *num;
num = va_arg(args, LLONG *);
*num = (LLONG) currlen;
} else {
int *num;
num = va_arg(args, int *);
*num = currlen;
}
break;
case '%':
dopr_outch(buffer, &currlen, maxlen, ch);
break;
case 'w':
/* not supported yet, treat as next char */
ch = *format++;
break;
default:
/* unknown, skip */
break;
}
ch = *format++;
state = DP_S_DEFAULT;
flags = cflags = min = 0;
max = -1;
break;
case DP_S_DONE:
break;
default:
break;
}
}
if (currlen >= maxlen - 1)
currlen = maxlen - 1;
if (buffer != NULL)
buffer[currlen] = NUL;
*retlen = currlen;
return;
}
static void
fmtstr(
char *buffer,
size_t *currlen,
size_t maxlen,
char *value,
int flags,
int min,
int max)
{
int padlen, strln;
int cnt = 0;
if (value == NULL)
value = "<NULL>";
for (strln = 0; value[strln] != '\0'; strln++)
;
padlen = min - strln;
if (padlen < 0)
padlen = 0;
if (flags & DP_F_MINUS)
padlen = -padlen;
while ((padlen > 0) && (cnt < max)) {
dopr_outch(buffer, currlen, maxlen, ' ');
--padlen;
++cnt;
}
while (*value && (cnt < max)) {
dopr_outch(buffer, currlen, maxlen, *value++);
++cnt;
}
while ((padlen < 0) && (cnt < max)) {
dopr_outch(buffer, currlen, maxlen, ' ');
++padlen;
++cnt;
}
}
static void
fmtint(
char *buffer,
size_t *currlen,
size_t maxlen,
LLONG value,
int base,
int min,
int max,
int flags)
{
int signvalue = 0;
unsigned LLONG uvalue;
char convert[20];
int place = 0;
int spadlen = 0;
int zpadlen = 0;
int caps = 0;
if (max < 0)
max = 0;
uvalue = value;
if (!(flags & DP_F_UNSIGNED)) {
if (value < 0) {
signvalue = '-';
uvalue = -value;
} else if (flags & DP_F_PLUS)
signvalue = '+';
else if (flags & DP_F_SPACE)
signvalue = ' ';
}
if (flags & DP_F_UP)
caps = 1;
do {
convert[place++] =
(caps ? "0123456789ABCDEF" : "0123456789abcdef")
[uvalue % (unsigned) base];
uvalue = (uvalue / (unsigned) base);
} while (uvalue && (place < 20));
if (place == 20)
place--;
convert[place] = 0;
zpadlen = max - place;
spadlen = min - STR_MAX(max, place) - (signvalue ? 1 : 0);
if (zpadlen < 0)
zpadlen = 0;
if (spadlen < 0)
spadlen = 0;
if (flags & DP_F_ZERO) {
zpadlen = STR_MAX(zpadlen, spadlen);
spadlen = 0;
}
if (flags & DP_F_MINUS)
spadlen = -spadlen;
/* spaces */
while (spadlen > 0) {
dopr_outch(buffer, currlen, maxlen, ' ');
--spadlen;
}
/* sign */
if (signvalue)
dopr_outch(buffer, currlen, maxlen, signvalue);
/* zeros */
if (zpadlen > 0) {
while (zpadlen > 0) {
dopr_outch(buffer, currlen, maxlen, '0');
--zpadlen;
}
}
/* digits */
while (place > 0)
dopr_outch(buffer, currlen, maxlen, convert[--place]);
/* left justified spaces */
while (spadlen < 0) {
dopr_outch(buffer, currlen, maxlen, ' ');
++spadlen;
}
return;
}
static LDOUBLE
math_abs(LDOUBLE value)
{
LDOUBLE result = value;
if (value < 0)
result = -value;
return result;
}
static LDOUBLE
math_pow10(int exponent)
{
LDOUBLE result = 1;
while (exponent > 0) {
result *= 10;
exponent--;
}
return result;
}
static long
math_round(LDOUBLE value)
{
long intpart;
intpart = (long) value;
value = value - intpart;
if (value >= 0.5)
intpart++;
return intpart;
}
static void
fmtfp(
char *buffer,
size_t *currlen,
size_t maxlen,
LDOUBLE fvalue,
int min,
int max,
int flags)
{
int signvalue = 0;
LDOUBLE ufvalue;
char iconvert[20];
char fconvert[20];
int iplace = 0;
int fplace = 0;
int padlen = 0;
int zpadlen = 0;
int caps = 0;
long intpart;
long fracpart;
if (max < 0)
max = 6;
ufvalue = math_abs(fvalue);
if (fvalue < 0)
signvalue = '-';
else if (flags & DP_F_PLUS)
signvalue = '+';
else if (flags & DP_F_SPACE)
signvalue = ' ';
intpart = (long)ufvalue;
/* sorry, we only support 9 digits past the decimal because of our
conversion method */
if (max > 9)
max = 9;
/* we "cheat" by converting the fractional part to integer by
multiplying by a factor of 10 */
fracpart = math_round((math_pow10(max)) * (ufvalue - intpart));
if (fracpart >= math_pow10(max)) {
intpart++;
fracpart -= (long)math_pow10(max);
}
/* convert integer part */
do {
iconvert[iplace++] =
(caps ? "0123456789ABCDEF"
: "0123456789abcdef")[intpart % 10];
intpart = (intpart / 10);
} while (intpart && (iplace < 20));
if (iplace == 20)
iplace--;
iconvert[iplace] = 0;
/* convert fractional part */
do {
fconvert[fplace++] =
(caps ? "0123456789ABCDEF"
: "0123456789abcdef")[fracpart % 10];
fracpart = (fracpart / 10);
} while (fracpart && (fplace < 20));
if (fplace == 20)
fplace--;
fconvert[fplace] = 0;
/* -1 for decimal point, another -1 if we are printing a sign */
padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
zpadlen = max - fplace;
if (zpadlen < 0)
zpadlen = 0;
if (padlen < 0)
padlen = 0;
if (flags & DP_F_MINUS)
padlen = -padlen;
if ((flags & DP_F_ZERO) && (padlen > 0)) {
if (signvalue) {
dopr_outch(buffer, currlen, maxlen, signvalue);
--padlen;
signvalue = 0;
}
while (padlen > 0) {
dopr_outch(buffer, currlen, maxlen, '0');
--padlen;
}
}
while (padlen > 0) {
dopr_outch(buffer, currlen, maxlen, ' ');
--padlen;
}
if (signvalue)
dopr_outch(buffer, currlen, maxlen, signvalue);
while (iplace > 0)
dopr_outch(buffer, currlen, maxlen, iconvert[--iplace]);
/*
* Decimal point. This should probably use locale to find the correct
* char to print out.
*/
if (max > 0) {
dopr_outch(buffer, currlen, maxlen, '.');
while (fplace > 0)
dopr_outch(buffer, currlen, maxlen, fconvert[--fplace]);
}
while (zpadlen > 0) {
dopr_outch(buffer, currlen, maxlen, '0');
--zpadlen;
}
while (padlen < 0) {
dopr_outch(buffer, currlen, maxlen, ' ');
++padlen;
}
return;
}
static void
dopr_outch(
char *buffer,
size_t *currlen,
size_t maxlen,
int c)
{
if (*currlen < maxlen) {
if (buffer != NULL)
buffer[(*currlen)] = (char)c;
(*currlen)++;
}
return;
}
int
str_vsnprintf(
char *str,
size_t count,
const char *fmt,
va_list args)
{
size_t retlen;
if (str != NULL)
str[0] = NUL;
dopr(str, count, &retlen, fmt, args);
return retlen;
}
int
str_snprintf(
char *str,
size_t count,
const char *fmt,
...)
{
va_list ap;
int rv;
va_start(ap, fmt);
rv = str_vsnprintf(str, count, fmt, ap);
va_end(ap);
return rv;
}
char *
str_vasprintf(
const char *fmt,
va_list ap)
{
char *rv;
int n;
va_list ap_tmp;
va_copy(ap_tmp, ap);
n = str_vsnprintf(NULL, 0, fmt, ap_tmp);
if ((rv = (char *)malloc(n+1)) == NULL)
return NULL;
str_vsnprintf(rv, n+1, fmt, ap);
return rv;
}
char *
str_asprintf(
const char *fmt,
...)
{
va_list ap;
char *rv;
va_start(ap, fmt);
rv = str_vasprintf(fmt, ap);
va_end(ap);
return rv;
}
int
str_vrsprintf(
char **str,
const char *fmt,
va_list ap)
{
int rv;
size_t n;
va_list ap_tmp;
if (str == NULL)
return -1;
if (*str == NULL) {
*str = str_vasprintf(fmt, ap);
rv = strlen(*str);
}
else {
va_copy(ap_tmp, ap);
n = strlen(*str);
rv = str_vsnprintf(NULL, 0, fmt, ap_tmp);
if ((*str = (char *)realloc(*str, n+rv+1)) == NULL)
return -1;
str_vsnprintf((*str)+n, rv+1, fmt, ap);
}
return rv;
}
int
str_rsprintf(
char **str,
const char *fmt,
...)
{
va_list ap;
int rv;
va_start(ap, fmt);
rv = str_vrsprintf(str, fmt, ap);
va_end(ap);
return rv;
}
+63
View File
@@ -0,0 +1,63 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_str.h: string formatting functions
*/
#ifndef __UUID_STR_H__
#define __UUID_STR_H__
#include <stdarg.h>
#include <string.h>
#define STR_PREFIX uuid_
/* embedding support */
#ifdef STR_PREFIX
#if defined(__STDC__) || defined(__cplusplus)
#define __STR_CONCAT(x,y) x ## y
#define STR_CONCAT(x,y) __STR_CONCAT(x,y)
#else
#define __STR_CONCAT(x) x
#define STR_CONCAT(x,y) __STR_CONCAT(x)y
#endif
#define str_vsnprintf STR_CONCAT(STR_PREFIX,str_vsnprintf)
#define str_snprintf STR_CONCAT(STR_PREFIX,str_snprintf)
#define str_vrsprintf STR_CONCAT(STR_PREFIX,str_vrsprintf)
#define str_rsprintf STR_CONCAT(STR_PREFIX,str_rsprintf)
#define str_vasprintf STR_CONCAT(STR_PREFIX,str_vasprintf)
#define str_asprintf STR_CONCAT(STR_PREFIX,str_asprintf)
#endif
extern int str_vsnprintf (char *, size_t, const char *, va_list);
extern int str_snprintf (char *, size_t, const char *, ...);
extern int str_vrsprintf (char **, const char *, va_list);
extern int str_rsprintf (char **, const char *, ...);
extern char *str_vasprintf ( const char *, va_list);
extern char *str_asprintf ( const char *, ...);
#endif /* __UUID_STR_H__ */
+117
View File
@@ -0,0 +1,117 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_time.c: Time Management
*/
/* own headers (part (1/2) */
#include "uuid_ac.h"
/* system headers */
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
/* own headers (part (1/2) */
#include "uuid_time.h"
/* POSIX gettimeofday(2) abstraction (without timezone) */
int time_gettimeofday(struct timeval *tv)
{
#if defined(HAVE_GETTIMEOFDAY)
/* Unix/POSIX pass-through */
return gettimeofday(tv, NULL);
#elif defined(HAVE_CLOCK_GETTIME)
/* POSIX emulation */
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
return -1;
if (tv != NULL) {
tv->tv_sec = (long)ts.tv_sec;
tv->tv_usec = (long)ts.tv_nsec / 1000;
}
return 0;
#elif defined(WIN32)
/* Windows emulation */
FILETIME ft;
LARGE_INTEGER li;
__int64 t;
static int tzflag;
#if !defined(__GNUC__)
#define EPOCHFILETIME 116444736000000000i64
#else
#define EPOCHFILETIME 116444736000000000LL
#endif
if (tv != NULL) {
GetSystemTimeAsFileTime(&ft);
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
t = li.QuadPart;
t -= EPOCHFILETIME;
t /= 10;
tv->tv_sec = (long)(t / 1000000);
tv->tv_usec = (long)(t % 1000000);
}
return 0;
#else
#error neither Win32 GetSystemTimeAsFileTime() nor Unix gettimeofday() nor POSIX clock_gettime() available!
#endif
}
/* BSD usleep(3) abstraction */
int time_usleep(long usec)
{
#if defined(WIN32) && defined(HAVE_SLEEP)
/* Win32 newer Sleep(3) variant */
Sleep(usec / 1000);
#elif defined(WIN32)
/* Win32 older _sleep(3) variant */
_sleep(usec / 1000);
#elif defined(HAVE_NANOSLEEP)
/* POSIX newer nanosleep(3) variant */
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 1000 * usec;
nanosleep(&ts, NULL);
#else
/* POSIX older select(2) variant */
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = usec;
select(0, NULL, NULL, NULL, &tv);
#endif
return 0;
}
+83
View File
@@ -0,0 +1,83 @@
/*
** OSSP uuid - Universally Unique Identifier
** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP uuid, a library for the generation
** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** uuid_time.h: Time Management API
*/
#ifndef __UUID_TIME_H__
#define __UUID_TIME_H__
#include "uuid_ac.h"
#if defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include <time.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#define TIME_PREFIX uuid_
/* embedding support */
#ifdef TIME_PREFIX
#if defined(__STDC__) || defined(__cplusplus)
#define __TIME_CONCAT(x,y) x ## y
#define TIME_CONCAT(x,y) __TIME_CONCAT(x,y)
#else
#define __TIME_CONCAT(x) x
#define TIME_CONCAT(x,y) __TIME_CONCAT(x)y
#endif
#define time_gettimeofday TIME_CONCAT(TIME_PREFIX,time_gettimeofday)
#define time_usleep TIME_CONCAT(TIME_PREFIX,time_usleep)
#endif
/* minimum C++ support */
#ifdef __cplusplus
#define DECLARATION_BEGIN extern "C" {
#define DECLARATION_END }
#else
#define DECLARATION_BEGIN
#define DECLARATION_END
#endif
DECLARATION_BEGIN
#ifndef HAVE_STRUCT_TIMEVAL
struct timeval { long tv_sec; long tv_usec; };
#endif
extern int time_gettimeofday(struct timeval *);
extern int time_usleep(long usec);
DECLARATION_END
#endif /* __UUID_TIME_H__ */
+591
View File
@@ -0,0 +1,591 @@
/*
** OSSP ui128 - 128-Bit Arithmetic
** Copyright (c) 2002-2005 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2002-2005 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP ui128, a 128-bit arithmetic library
** which can be found at http://www.ossp.org/pkg/lib/ui128/.
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** ui128.c: implementation of 128-bit unsigned integer arithmetic
*/
/* own headers (part 1/2) */
#include "uuid_ac.h"
/* system headers */
#include <string.h>
#include <ctype.h>
/* own headers (part 2/2) */
#include "uuid_ui128.h"
#define UI128_BASE 256 /* 2^8 */
#define UI128_DIGITS 16 /* 8*16 = 128 bit */
#define UIXX_T(n) struct { unsigned char x[n]; }
/* fill an ui128_t with a sequence of a particular digit */
#define ui128_fill(__x, __n) \
/*lint -save -e717*/ \
do { int __i; \
for (__i = 0; __i < UI128_DIGITS; __i++) \
(__x).x[__i] = (__n); \
} while (0) \
/*lint -restore*/
/* the value zero */
ui128_t ui128_zero(void)
{
ui128_t z;
ui128_fill(z, 0);
return z;
}
/* the maximum value */
ui128_t ui128_max(void)
{
ui128_t z;
ui128_fill(z, UI128_BASE-1);
return z;
}
/* convert ISO-C "unsigned long" into internal format */
ui128_t ui128_n2i(unsigned long n)
{
ui128_t z;
int i;
i = 0;
do {
z.x[i++] = (n % UI128_BASE);
} while ((n /= UI128_BASE) > 0 && i < UI128_DIGITS);
for ( ; i < UI128_DIGITS; i++)
z.x[i] = 0;
return z;
}
/* convert internal format into ISO-C "unsigned long";
truncates if sizeof(unsigned long) is less than UI128_DIGITS! */
unsigned long ui128_i2n(ui128_t x)
{
unsigned long n;
int i;
n = 0;
i = (int)sizeof(n);
/*lint -save -e774*/
if (i > UI128_DIGITS)
i = UI128_DIGITS;
/*lint -restore*/
while (--i >= 0) {
n = (n * UI128_BASE) + x.x[i];
}
return n;
}
/* convert string representation of arbitrary base into internal format */
ui128_t ui128_s2i(const char *str, char **end, int base)
{
ui128_t z;
const char *cp;
int carry;
static char map[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 0...9 */
36, 36, 36, 36, 36, 36, 36, /* illegal chars */
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, /* A...M */
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, /* N...Z */
36, 36, 36, 36, 36, 36, /* illegal chars */
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, /* a...m */
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 /* m...z */
};
ui128_fill(z, 0);
if (str == NULL || (base < 2 || base > 36))
return z;
cp = str;
while (*cp != '\0' && isspace((int)(*cp)))
cp++;
while ( *cp != '\0'
&& isalnum((int)(*cp))
&& map[(int)(*cp)-'0'] < base) {
z = ui128_muln(z, base, &carry);
if (carry)
break;
z = ui128_addn(z, map[(int)(*cp)-'0'], &carry);
if (carry)
break;
cp++;
}
if (end != NULL)
*end = (char *)cp;
return z;
}
/* convert internal format into string representation of arbitrary base */
char *ui128_i2s(ui128_t x, char *str, size_t len, int base)
{
static char map[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char c;
int r;
int n;
int i, j;
if (str == NULL || len < 2 || (base < 2 || base > 36))
return NULL;
n = ui128_len(x);
i = 0;
do {
x = ui128_divn(x, base, &r);
str[i++] = map[r];
while (n > 1 && x.x[n-1] == 0)
n--;
} while (i < ((int)len-1) && (n > 1 || x.x[0] != 0));
str[i] = '\0';
for (j = 0; j < --i; j++) {
c = str[j];
str[j] = str[i];
str[i] = c;
}
return str;
}
/* addition of two ui128_t */
ui128_t ui128_add(ui128_t x, ui128_t y, ui128_t *ov)
{
ui128_t z;
int carry;
int i;
carry = 0;
for (i = 0; i < UI128_DIGITS; i++) {
carry += (x.x[i] + y.x[i]);
z.x[i] = (carry % UI128_BASE);
carry /= UI128_BASE;
}
if (ov != NULL)
*ov = ui128_n2i((unsigned long)carry);
return z;
}
/* addition of an ui128_t and a single digit */
ui128_t ui128_addn(ui128_t x, int y, int *ov)
{
ui128_t z;
int i;
for (i = 0; i < UI128_DIGITS; i++) {
y += x.x[i];
z.x[i] = (y % UI128_BASE);
y /= UI128_BASE;
}
if (ov != NULL)
*ov = y;
return z;
}
/* subtraction of two ui128_t */
ui128_t ui128_sub(ui128_t x, ui128_t y, ui128_t *ov)
{
ui128_t z;
int borrow;
int i;
int d;
borrow = 0;
for (i = 0; i < UI128_DIGITS; i++) {
d = ((x.x[i] + UI128_BASE) - borrow - y.x[i]);
z.x[i] = (d % UI128_BASE);
borrow = (1 - (d/UI128_BASE));
}
if (ov != NULL)
*ov = ui128_n2i((unsigned long)borrow);
return z;
}
/* subtraction of an ui128_t and a single digit */
ui128_t ui128_subn(ui128_t x, int y, int *ov)
{
ui128_t z;
int i;
int d;
for (i = 0; i < UI128_DIGITS; i++) {
d = (x.x[i] + UI128_BASE) - y;
z.x[i] = (d % UI128_BASE);
y = (1 - (d/UI128_BASE));
}
if (ov != NULL)
*ov = y;
return z;
}
/*
7 3 2
* 9 4 2 8
---------
5 8 5 6
+ 1 4 6 4
+ 2 9 2 8
+ 6 5 8 8
---------------
= 6 9 0 1 2 9 6
*/
ui128_t ui128_mul(ui128_t x, ui128_t y, ui128_t *ov)
{
UIXX_T(UI128_DIGITS+UI128_DIGITS) zx;
ui128_t z;
int carry;
int i, j;
/* clear temporary result buffer */
for (i = 0; i < (UI128_DIGITS+UI128_DIGITS); i++)
zx.x[i] = 0;
/* perform multiplication operation */
for (i = 0; i < UI128_DIGITS; i++) {
/* calculate partial product and immediately add to z */
carry = 0;
for (j = 0; j < UI128_DIGITS; j++) {
carry += (x.x[i] * y.x[j]) + zx.x[i+j];
zx.x[i+j] = (carry % UI128_BASE);
carry /= UI128_BASE;
}
/* add carry to remaining digits in z */
for ( ; j < UI128_DIGITS + UI128_DIGITS - i; j++) {
carry += zx.x[i+j];
zx.x[i+j] = (carry % UI128_BASE);
carry /= UI128_BASE;
}
}
/* provide result by splitting zx into z and ov */
memcpy(z.x, zx.x, UI128_DIGITS);
if (ov != NULL)
memcpy((*ov).x, &zx.x[UI128_DIGITS], UI128_DIGITS);
return z;
}
ui128_t ui128_muln(ui128_t x, int y, int *ov)
{
ui128_t z;
int carry;
int i;
carry = 0;
for (i = 0; i < UI128_DIGITS; i++) {
carry += (x.x[i] * y);
z.x[i] = (carry % UI128_BASE);
carry /= UI128_BASE;
}
if (ov != NULL)
*ov = carry;
return z;
}
/*
= 2078 [q]
0615367 [x] : 296 [y]
-0592 [dq]
-----
= 0233
-0000 [dq]
-----
= 2336
-2072 [dq]
-----
= 2647
-2308 [dq]
-----
= 279 [r]
*/
ui128_t ui128_div(ui128_t x, ui128_t y, ui128_t *ov)
{
ui128_t q;
ui128_t r;
int i;
int n, m;
int ovn;
/* determine actual number of involved digits */
n = ui128_len(x);
m = ui128_len(y);
if (m == 1) {
/* simple case #1: reduceable to ui128_divn() */
if (y.x[0] == 0) {
/* error case: division by zero! */
ui128_fill(q, 0);
ui128_fill(r, 0);
}
else {
q = ui128_divn(x, y.x[0], &ovn);
ui128_fill(r, 0);
r.x[0] = (unsigned char)ovn;
}
} else if (n < m) {
/* simple case #2: everything is in the remainder */
ui128_fill(q, 0);
r = x;
} else { /* n >= m, m > 1 */
/* standard case: x[0..n] / y[0..m] */
UIXX_T(UI128_DIGITS+1) rx;
UIXX_T(UI128_DIGITS+1) dq;
ui128_t t;
int km;
int k;
int qk;
unsigned long y2;
unsigned long r3;
int borrow;
int d;
/* rx is x with a leading zero in order to make
sure that n > m and not just n >= m */
memcpy(rx.x, x.x, UI128_DIGITS);
rx.x[UI128_DIGITS] = 0;
for (k = n - m; k >= 0; k--) {
/* efficiently compute qk by guessing
qk := rx[k+m-2...k+m]/y[m-2...m-1] */
km = k + m;
y2 = (y.x[m-1]*UI128_BASE) + y.x[m-2];
r3 = (rx.x[km]*(UI128_BASE*UI128_BASE)) +
(rx.x[km-1]*UI128_BASE) + rx.x[km-2];
qk = r3 / y2;
if (qk >= UI128_BASE)
qk = UI128_BASE - 1;
/* dq := y*qk (post-adjust qk if guessed incorrectly) */
t = ui128_muln(y, qk, &ovn);
memcpy(dq.x, t.x, UI128_DIGITS);
dq.x[m] = (unsigned char)ovn;
for (i = m; i > 0; i--)
if (rx.x[i+k] != dq.x[i])
break;
if (rx.x[i+k] < dq.x[i]) {
t = ui128_muln(y, --qk, &ovn);
memcpy(dq.x, t.x, UI128_DIGITS);
dq.x[m] = (unsigned char)ovn;
}
/* store qk */
q.x[k] = (unsigned char)qk;
/* rx := rx - dq*(b^k) */
borrow = 0;
for (i = 0; i < m+1; i++) {
d = ((rx.x[k+i] + UI128_BASE) - borrow - dq.x[i]);
rx.x[k+i] = (d % UI128_BASE);
borrow = (1 - (d/UI128_BASE));
}
}
memcpy(r.x, rx.x, m);
/* fill out results with leading zeros */
for (i = n-m+1; i < UI128_DIGITS; i++)
q.x[i] = 0;
for (i = m; i < UI128_DIGITS; i++)
r.x[i] = 0;
}
/* provide results */
if (ov != NULL)
*ov = r;
return q;
}
ui128_t ui128_divn(ui128_t x, int y, int *ov)
{
ui128_t z;
unsigned int carry;
int i;
carry = 0;
for (i = (UI128_DIGITS - 1); i >= 0; i--) {
carry = (carry * UI128_BASE) + x.x[i];
z.x[i] = (carry / y);
carry %= y;
}
if (ov != NULL)
*ov = carry;
return z;
}
ui128_t ui128_and(ui128_t x, ui128_t y)
{
ui128_t z;
int i;
for (i = 0; i < UI128_DIGITS; i++)
z.x[i] = (x.x[i] & y.x[i]);
return z;
}
ui128_t ui128_or(ui128_t x, ui128_t y)
{
ui128_t z;
int i;
for (i = 0; i < UI128_DIGITS; i++)
z.x[i] = (x.x[i] | y.x[i]);
return z;
}
ui128_t ui128_xor(ui128_t x, ui128_t y)
{
ui128_t z;
int i;
for (i = 0; i < UI128_DIGITS; i++)
z.x[i] = ((x.x[i] & ~(y.x[i])) | (~(x.x[i]) & (y.x[i])));
return z;
}
ui128_t ui128_not(ui128_t x)
{
ui128_t z;
int i;
for (i = 0; i < UI128_DIGITS; i++)
z.x[i] = ~(x.x[i]);
return z;
}
ui128_t ui128_rol(ui128_t x, int s, ui128_t *ov)
{
UIXX_T(UI128_DIGITS+UI128_DIGITS) zx;
ui128_t z;
int i;
int carry;
if (s <= 0) {
/* no shift at all */
if (ov != NULL)
*ov = ui128_zero();
return x;
}
else if (s > 128) {
/* too large shift */
if (ov != NULL)
*ov = ui128_zero();
return ui128_zero();
}
else if (s == 128) {
/* maximum shift */
if (ov != NULL)
*ov = x;
return ui128_zero();
}
else { /* regular shift */
/* shift (logically) left by s/8 bytes */
for (i = 0; i < UI128_DIGITS+UI128_DIGITS; i++)
zx.x[i] = 0;
for (i = 0; i < UI128_DIGITS; i++)
zx.x[i+(s/8)] = x.x[i];
/* shift (logically) left by remaining s%8 bits */
s %= 8;
if (s > 0) {
carry = 0;
for (i = 0; i < UI128_DIGITS+UI128_DIGITS; i++) {
carry += (zx.x[i] * (1 << s));
zx.x[i] = (carry % UI128_BASE);
carry /= UI128_BASE;
}
}
memcpy(z.x, zx.x, UI128_DIGITS);
if (ov != NULL)
memcpy((*ov).x, &zx.x[UI128_DIGITS], UI128_DIGITS);
}
return z;
}
ui128_t ui128_ror(ui128_t x, int s, ui128_t *ov)
{
UIXX_T(UI128_DIGITS+UI128_DIGITS) zx;
ui128_t z;
int i;
int carry;
if (s <= 0) {
/* no shift at all */
if (ov != NULL)
*ov = ui128_zero();
return x;
}
else if (s > 128) {
/* too large shift */
if (ov != NULL)
*ov = ui128_zero();
return ui128_zero();
}
else if (s == 128) {
/* maximum shift */
if (ov != NULL)
*ov = x;
return ui128_zero();
}
else { /* regular shift */
/* shift (logically) right by s/8 bytes */
for (i = 0; i < UI128_DIGITS+UI128_DIGITS; i++)
zx.x[i] = 0;
for (i = 0; i < UI128_DIGITS; i++)
zx.x[UI128_DIGITS+i-(s/8)] = x.x[i];
/* shift (logically) right by remaining s%8 bits */
s %= 8;
if (s > 0) {
carry = 0;
for (i = (UI128_DIGITS+UI128_DIGITS - 1); i >= 0; i--) {
carry = (carry * UI128_BASE) + zx.x[i];
zx.x[i] = (carry / (1 << s));
carry %= (1 << s);
}
}
memcpy(z.x, &zx.x[UI128_DIGITS], UI128_DIGITS);
if (ov != NULL)
memcpy((*ov).x, zx.x, UI128_DIGITS);
}
return z;
}
int ui128_cmp(ui128_t x, ui128_t y)
{
int i;
i = UI128_DIGITS - 1;
while (i > 0 && x.x[i] == y.x[i])
i--;
return (x.x[i] - y.x[i]);
}
int ui128_len(ui128_t x)
{
int i;
for (i = UI128_DIGITS; i > 1 && x.x[i-1] == 0; i--)
;
return i;
}
+114
View File
@@ -0,0 +1,114 @@
/*
** OSSP ui128 - 128-Bit Arithmetic
** Copyright (c) 2002-2005 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2002-2005 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP ui128, a 128-bit arithmetic library
** which can be found at http://www.ossp.org/pkg/lib/ui128/.
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** ui128.h: API declaration
*/
#ifndef __UI128_H__
#define __UI128_H__
#include <string.h>
#define UI128_PREFIX uuid_
/* embedding support */
#ifdef UI128_PREFIX
#if defined(__STDC__) || defined(__cplusplus)
#define __UI128_CONCAT(x,y) x ## y
#define UI128_CONCAT(x,y) __UI128_CONCAT(x,y)
#else
#define __UI128_CONCAT(x) x
#define UI128_CONCAT(x,y) __UI128_CONCAT(x)y
#endif
#define ui128_t UI128_CONCAT(UI128_PREFIX,ui128_t)
#define ui128_zero UI128_CONCAT(UI128_PREFIX,ui128_zero)
#define ui128_max UI128_CONCAT(UI128_PREFIX,ui128_max)
#define ui128_n2i UI128_CONCAT(UI128_PREFIX,ui128_n2i)
#define ui128_i2n UI128_CONCAT(UI128_PREFIX,ui128_i2n)
#define ui128_s2i UI128_CONCAT(UI128_PREFIX,ui128_s2i)
#define ui128_i2s UI128_CONCAT(UI128_PREFIX,ui128_i2s)
#define ui128_add UI128_CONCAT(UI128_PREFIX,ui128_add)
#define ui128_addn UI128_CONCAT(UI128_PREFIX,ui128_addn)
#define ui128_sub UI128_CONCAT(UI128_PREFIX,ui128_sub)
#define ui128_subn UI128_CONCAT(UI128_PREFIX,ui128_subn)
#define ui128_mul UI128_CONCAT(UI128_PREFIX,ui128_mul)
#define ui128_muln UI128_CONCAT(UI128_PREFIX,ui128_muln)
#define ui128_div UI128_CONCAT(UI128_PREFIX,ui128_div)
#define ui128_divn UI128_CONCAT(UI128_PREFIX,ui128_divn)
#define ui128_and UI128_CONCAT(UI128_PREFIX,ui128_and)
#define ui128_or UI128_CONCAT(UI128_PREFIX,ui128_or)
#define ui128_xor UI128_CONCAT(UI128_PREFIX,ui128_xor)
#define ui128_not UI128_CONCAT(UI128_PREFIX,ui128_not)
#define ui128_rol UI128_CONCAT(UI128_PREFIX,ui128_rol)
#define ui128_ror UI128_CONCAT(UI128_PREFIX,ui128_ror)
#define ui128_len UI128_CONCAT(UI128_PREFIX,ui128_len)
#define ui128_cmp UI128_CONCAT(UI128_PREFIX,ui128_cmp)
#endif
typedef struct {
unsigned char x[16]; /* x_0, ..., x_15 */
} ui128_t;
#define ui128_cons(x15,x14,x13,x12,x11,x10,x9,x8,x7,x6,x5,x4,x3,x2,x1,x0) \
{ { 0x##x0, 0x##x1, 0x##x2, 0x##x3, 0x##x4, 0x##x5, 0x##x6, 0x##x7, \
{ { 0x##x8, 0x##x9, 0x##x10, 0x##x11, 0x##x12, 0x##x13, 0x##x14, 0x##x15 } }
/* particular values */
extern ui128_t ui128_zero (void);
extern ui128_t ui128_max (void);
/* import and export via ISO-C "unsigned long" */
extern ui128_t ui128_n2i (unsigned long n);
extern unsigned long ui128_i2n (ui128_t x);
/* import and export via ISO-C string of arbitrary base */
extern ui128_t ui128_s2i (const char *str, char **end, int base);
extern char * ui128_i2s (ui128_t x, char *str, size_t len, int base);
/* arithmetical operations */
extern ui128_t ui128_add (ui128_t x, ui128_t y, ui128_t *ov);
extern ui128_t ui128_addn (ui128_t x, int y, int *ov);
extern ui128_t ui128_sub (ui128_t x, ui128_t y, ui128_t *ov);
extern ui128_t ui128_subn (ui128_t x, int y, int *ov);
extern ui128_t ui128_mul (ui128_t x, ui128_t y, ui128_t *ov);
extern ui128_t ui128_muln (ui128_t x, int y, int *ov);
extern ui128_t ui128_div (ui128_t x, ui128_t y, ui128_t *ov);
extern ui128_t ui128_divn (ui128_t x, int y, int *ov);
/* bit operations */
extern ui128_t ui128_and (ui128_t x, ui128_t y);
extern ui128_t ui128_or (ui128_t x, ui128_t y);
extern ui128_t ui128_xor (ui128_t x, ui128_t y);
extern ui128_t ui128_not (ui128_t x);
extern ui128_t ui128_rol (ui128_t x, int s, ui128_t *ov);
extern ui128_t ui128_ror (ui128_t x, int s, ui128_t *ov);
/* other operations */
extern int ui128_len (ui128_t x);
extern int ui128_cmp (ui128_t x, ui128_t y);
#endif /* __UI128_H__ */
+591
View File
@@ -0,0 +1,591 @@
/*
** OSSP ui64 - 64-Bit Arithmetic
** Copyright (c) 2002-2005 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2002-2005 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP ui64, a 64-bit arithmetic library
** which can be found at http://www.ossp.org/pkg/lib/ui64/.
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** ui64.c: implementation of 64-bit unsigned integer arithmetic
*/
/* own headers (part 1/2) */
#include "uuid_ac.h"
/* system headers */
#include <string.h>
#include <ctype.h>
/* own headers (part 2/2) */
#include "uuid_ui64.h"
#define UI64_BASE 256 /* 2^8 */
#define UI64_DIGITS 8 /* 8*8 = 64 bit */
#define UIXX_T(n) struct { unsigned char x[n]; }
/* fill an ui64_t with a sequence of a particular digit */
#define ui64_fill(__x, __n) \
/*lint -save -e717*/ \
do { int __i; \
for (__i = 0; __i < UI64_DIGITS; __i++) \
(__x).x[__i] = (__n); \
} while (0) \
/*lint -restore*/
/* the value zero */
ui64_t ui64_zero(void)
{
ui64_t z;
ui64_fill(z, 0);
return z;
}
/* the maximum value */
ui64_t ui64_max(void)
{
ui64_t z;
ui64_fill(z, UI64_BASE-1);
return z;
}
/* convert ISO-C "unsigned long" into internal format */
ui64_t ui64_n2i(unsigned long n)
{
ui64_t z;
int i;
i = 0;
do {
z.x[i++] = (n % UI64_BASE);
} while ((n /= UI64_BASE) > 0 && i < UI64_DIGITS);
for ( ; i < UI64_DIGITS; i++)
z.x[i] = 0;
return z;
}
/* convert internal format into ISO-C "unsigned long";
truncates if sizeof(unsigned long) is less than UI64_DIGITS! */
unsigned long ui64_i2n(ui64_t x)
{
unsigned long n;
int i;
n = 0;
i = (int)sizeof(n);
/*lint -save -e774*/
if (i > UI64_DIGITS)
i = UI64_DIGITS;
/*lint -restore*/
while (--i >= 0) {
n = (n * UI64_BASE) + x.x[i];
}
return n;
}
/* convert string representation of arbitrary base into internal format */
ui64_t ui64_s2i(const char *str, char **end, int base)
{
ui64_t z;
const char *cp;
int carry;
static char map[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 0...9 */
36, 36, 36, 36, 36, 36, 36, /* illegal chars */
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, /* A...M */
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, /* N...Z */
36, 36, 36, 36, 36, 36, /* illegal chars */
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, /* a...m */
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 /* m...z */
};
ui64_fill(z, 0);
if (str == NULL || (base < 2 || base > 36))
return z;
cp = str;
while (*cp != '\0' && isspace((int)(*cp)))
cp++;
while ( *cp != '\0'
&& isalnum((int)(*cp))
&& map[(int)(*cp)-'0'] < base) {
z = ui64_muln(z, base, &carry);
if (carry)
break;
z = ui64_addn(z, map[(int)(*cp)-'0'], &carry);
if (carry)
break;
cp++;
}
if (end != NULL)
*end = (char *)cp;
return z;
}
/* convert internal format into string representation of arbitrary base */
char *ui64_i2s(ui64_t x, char *str, size_t len, int base)
{
static char map[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char c;
int r;
int n;
int i, j;
if (str == NULL || len < 2 || (base < 2 || base > 36))
return NULL;
n = ui64_len(x);
i = 0;
do {
x = ui64_divn(x, base, &r);
str[i++] = map[r];
while (n > 1 && x.x[n-1] == 0)
n--;
} while (i < ((int)len-1) && (n > 1 || x.x[0] != 0));
str[i] = '\0';
for (j = 0; j < --i; j++) {
c = str[j];
str[j] = str[i];
str[i] = c;
}
return str;
}
/* addition of two ui64_t */
ui64_t ui64_add(ui64_t x, ui64_t y, ui64_t *ov)
{
ui64_t z;
int carry;
int i;
carry = 0;
for (i = 0; i < UI64_DIGITS; i++) {
carry += (x.x[i] + y.x[i]);
z.x[i] = (carry % UI64_BASE);
carry /= UI64_BASE;
}
if (ov != NULL)
*ov = ui64_n2i((unsigned long)carry);
return z;
}
/* addition of an ui64_t and a single digit */
ui64_t ui64_addn(ui64_t x, int y, int *ov)
{
ui64_t z;
int i;
for (i = 0; i < UI64_DIGITS; i++) {
y += x.x[i];
z.x[i] = (y % UI64_BASE);
y /= UI64_BASE;
}
if (ov != NULL)
*ov = y;
return z;
}
/* subtraction of two ui64_t */
ui64_t ui64_sub(ui64_t x, ui64_t y, ui64_t *ov)
{
ui64_t z;
int borrow;
int i;
int d;
borrow = 0;
for (i = 0; i < UI64_DIGITS; i++) {
d = ((x.x[i] + UI64_BASE) - borrow - y.x[i]);
z.x[i] = (d % UI64_BASE);
borrow = (1 - (d/UI64_BASE));
}
if (ov != NULL)
*ov = ui64_n2i((unsigned long)borrow);
return z;
}
/* subtraction of an ui64_t and a single digit */
ui64_t ui64_subn(ui64_t x, int y, int *ov)
{
ui64_t z;
int i;
int d;
for (i = 0; i < UI64_DIGITS; i++) {
d = (x.x[i] + UI64_BASE) - y;
z.x[i] = (d % UI64_BASE);
y = (1 - (d/UI64_BASE));
}
if (ov != NULL)
*ov = y;
return z;
}
/*
7 3 2
* 9 4 2 8
---------
5 8 5 6
+ 1 4 6 4
+ 2 9 2 8
+ 6 5 8 8
---------------
= 6 9 0 1 2 9 6
*/
ui64_t ui64_mul(ui64_t x, ui64_t y, ui64_t *ov)
{
UIXX_T(UI64_DIGITS+UI64_DIGITS) zx;
ui64_t z;
int carry;
int i, j;
/* clear temporary result buffer */
for (i = 0; i < (UI64_DIGITS+UI64_DIGITS); i++)
zx.x[i] = 0;
/* perform multiplication operation */
for (i = 0; i < UI64_DIGITS; i++) {
/* calculate partial product and immediately add to z */
carry = 0;
for (j = 0; j < UI64_DIGITS; j++) {
carry += (x.x[i] * y.x[j]) + zx.x[i+j];
zx.x[i+j] = (carry % UI64_BASE);
carry /= UI64_BASE;
}
/* add carry to remaining digits in z */
for ( ; j < UI64_DIGITS + UI64_DIGITS - i; j++) {
carry += zx.x[i+j];
zx.x[i+j] = (carry % UI64_BASE);
carry /= UI64_BASE;
}
}
/* provide result by splitting zx into z and ov */
memcpy(z.x, zx.x, UI64_DIGITS);
if (ov != NULL)
memcpy((*ov).x, &zx.x[UI64_DIGITS], UI64_DIGITS);
return z;
}
ui64_t ui64_muln(ui64_t x, int y, int *ov)
{
ui64_t z;
int carry;
int i;
carry = 0;
for (i = 0; i < UI64_DIGITS; i++) {
carry += (x.x[i] * y);
z.x[i] = (carry % UI64_BASE);
carry /= UI64_BASE;
}
if (ov != NULL)
*ov = carry;
return z;
}
/*
= 2078 [q]
0615367 [x] : 296 [y]
-0592 [dq]
-----
= 0233
-0000 [dq]
-----
= 2336
-2072 [dq]
-----
= 2647
-2308 [dq]
-----
= 279 [r]
*/
ui64_t ui64_div(ui64_t x, ui64_t y, ui64_t *ov)
{
ui64_t q;
ui64_t r;
int i;
int n, m;
int ovn;
/* determine actual number of involved digits */
n = ui64_len(x);
m = ui64_len(y);
if (m == 1) {
/* simple case #1: reduceable to ui64_divn() */
if (y.x[0] == 0) {
/* error case: division by zero! */
ui64_fill(q, 0);
ui64_fill(r, 0);
}
else {
q = ui64_divn(x, y.x[0], &ovn);
ui64_fill(r, 0);
r.x[0] = (unsigned char)ovn;
}
} else if (n < m) {
/* simple case #2: everything is in the remainder */
ui64_fill(q, 0);
r = x;
} else { /* n >= m, m > 1 */
/* standard case: x[0..n] / y[0..m] */
UIXX_T(UI64_DIGITS+1) rx;
UIXX_T(UI64_DIGITS+1) dq;
ui64_t t;
int km;
int k;
int qk;
unsigned long y2;
unsigned long r3;
int borrow;
int d;
/* rx is x with a leading zero in order to make
sure that n > m and not just n >= m */
memcpy(rx.x, x.x, UI64_DIGITS);
rx.x[UI64_DIGITS] = 0;
for (k = n - m; k >= 0; k--) {
/* efficiently compute qk by guessing
qk := rx[k+m-2...k+m]/y[m-2...m-1] */
km = k + m;
y2 = (y.x[m-1]*UI64_BASE) + y.x[m-2];
r3 = (rx.x[km]*(UI64_BASE*UI64_BASE)) +
(rx.x[km-1]*UI64_BASE) + rx.x[km-2];
qk = r3 / y2;
if (qk >= UI64_BASE)
qk = UI64_BASE - 1;
/* dq := y*qk (post-adjust qk if guessed incorrectly) */
t = ui64_muln(y, qk, &ovn);
memcpy(dq.x, t.x, UI64_DIGITS);
dq.x[m] = (unsigned char)ovn;
for (i = m; i > 0; i--)
if (rx.x[i+k] != dq.x[i])
break;
if (rx.x[i+k] < dq.x[i]) {
t = ui64_muln(y, --qk, &ovn);
memcpy(dq.x, t.x, UI64_DIGITS);
dq.x[m] = (unsigned char)ovn;
}
/* store qk */
q.x[k] = (unsigned char)qk;
/* rx := rx - dq*(b^k) */
borrow = 0;
for (i = 0; i < m+1; i++) {
d = ((rx.x[k+i] + UI64_BASE) - borrow - dq.x[i]);
rx.x[k+i] = (d % UI64_BASE);
borrow = (1 - (d/UI64_BASE));
}
}
memcpy(r.x, rx.x, m);
/* fill out results with leading zeros */
for (i = n-m+1; i < UI64_DIGITS; i++)
q.x[i] = 0;
for (i = m; i < UI64_DIGITS; i++)
r.x[i] = 0;
}
/* provide results */
if (ov != NULL)
*ov = r;
return q;
}
ui64_t ui64_divn(ui64_t x, int y, int *ov)
{
ui64_t z;
unsigned int carry;
int i;
carry = 0;
for (i = (UI64_DIGITS - 1); i >= 0; i--) {
carry = (carry * UI64_BASE) + x.x[i];
z.x[i] = (carry / y);
carry %= y;
}
if (ov != NULL)
*ov = carry;
return z;
}
ui64_t ui64_and(ui64_t x, ui64_t y)
{
ui64_t z;
int i;
for (i = 0; i < UI64_DIGITS; i++)
z.x[i] = (x.x[i] & y.x[i]);
return z;
}
ui64_t ui64_or(ui64_t x, ui64_t y)
{
ui64_t z;
int i;
for (i = 0; i < UI64_DIGITS; i++)
z.x[i] = (x.x[i] | y.x[i]);
return z;
}
ui64_t ui64_xor(ui64_t x, ui64_t y)
{
ui64_t z;
int i;
for (i = 0; i < UI64_DIGITS; i++)
z.x[i] = ((x.x[i] & ~(y.x[i])) | (~(x.x[i]) & (y.x[i])));
return z;
}
ui64_t ui64_not(ui64_t x)
{
ui64_t z;
int i;
for (i = 0; i < UI64_DIGITS; i++)
z.x[i] = ~(x.x[i]);
return z;
}
ui64_t ui64_rol(ui64_t x, int s, ui64_t *ov)
{
UIXX_T(UI64_DIGITS+UI64_DIGITS) zx;
ui64_t z;
int i;
int carry;
if (s <= 0) {
/* no shift at all */
if (ov != NULL)
*ov = ui64_zero();
return x;
}
else if (s > 64) {
/* too large shift */
if (ov != NULL)
*ov = ui64_zero();
return ui64_zero();
}
else if (s == 64) {
/* maximum shift */
if (ov != NULL)
*ov = x;
return ui64_zero();
}
else { /* regular shift */
/* shift (logically) left by s/8 bytes */
for (i = 0; i < UI64_DIGITS+UI64_DIGITS; i++)
zx.x[i] = 0;
for (i = 0; i < UI64_DIGITS; i++)
zx.x[i+(s/8)] = x.x[i];
/* shift (logically) left by remaining s%8 bits */
s %= 8;
if (s > 0) {
carry = 0;
for (i = 0; i < UI64_DIGITS+UI64_DIGITS; i++) {
carry += (zx.x[i] * (1 << s));
zx.x[i] = (carry % UI64_BASE);
carry /= UI64_BASE;
}
}
memcpy(z.x, zx.x, UI64_DIGITS);
if (ov != NULL)
memcpy((*ov).x, &zx.x[UI64_DIGITS], UI64_DIGITS);
}
return z;
}
ui64_t ui64_ror(ui64_t x, int s, ui64_t *ov)
{
UIXX_T(UI64_DIGITS+UI64_DIGITS) zx;
ui64_t z;
int i;
int carry;
if (s <= 0) {
/* no shift at all */
if (ov != NULL)
*ov = ui64_zero();
return x;
}
else if (s > 64) {
/* too large shift */
if (ov != NULL)
*ov = ui64_zero();
return ui64_zero();
}
else if (s == 64) {
/* maximum shift */
if (ov != NULL)
*ov = x;
return ui64_zero();
}
else { /* regular shift */
/* shift (logically) right by s/8 bytes */
for (i = 0; i < UI64_DIGITS+UI64_DIGITS; i++)
zx.x[i] = 0;
for (i = 0; i < UI64_DIGITS; i++)
zx.x[UI64_DIGITS+i-(s/8)] = x.x[i];
/* shift (logically) right by remaining s%8 bits */
s %= 8;
if (s > 0) {
carry = 0;
for (i = (UI64_DIGITS+UI64_DIGITS - 1); i >= 0; i--) {
carry = (carry * UI64_BASE) + zx.x[i];
zx.x[i] = (carry / (1 << s));
carry %= (1 << s);
}
}
memcpy(z.x, &zx.x[UI64_DIGITS], UI64_DIGITS);
if (ov != NULL)
memcpy((*ov).x, zx.x, UI64_DIGITS);
}
return z;
}
int ui64_cmp(ui64_t x, ui64_t y)
{
int i;
i = UI64_DIGITS - 1;
while (i > 0 && x.x[i] == y.x[i])
i--;
return (x.x[i] - y.x[i]);
}
int ui64_len(ui64_t x)
{
int i;
for (i = UI64_DIGITS; i > 1 && x.x[i-1] == 0; i--)
;
return i;
}
+113
View File
@@ -0,0 +1,113 @@
/*
** OSSP ui64 - 64-Bit Arithmetic
** Copyright (c) 2002-2005 Ralf S. Engelschall <rse@engelschall.com>
** Copyright (c) 2002-2005 The OSSP Project <http://www.ossp.org/>
**
** This file is part of OSSP ui64, a 64-bit arithmetic library
** which can be found at http://www.ossp.org/pkg/lib/ui64/.
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** ui64.h: API declaration
*/
#ifndef __UI64_H__
#define __UI64_H__
#include <string.h>
#define UI64_PREFIX uuid_
/* embedding support */
#ifdef UI64_PREFIX
#if defined(__STDC__) || defined(__cplusplus)
#define __UI64_CONCAT(x,y) x ## y
#define UI64_CONCAT(x,y) __UI64_CONCAT(x,y)
#else
#define __UI64_CONCAT(x) x
#define UI64_CONCAT(x,y) __UI64_CONCAT(x)y
#endif
#define ui64_t UI64_CONCAT(UI64_PREFIX,ui64_t)
#define ui64_zero UI64_CONCAT(UI64_PREFIX,ui64_zero)
#define ui64_max UI64_CONCAT(UI64_PREFIX,ui64_max)
#define ui64_n2i UI64_CONCAT(UI64_PREFIX,ui64_n2i)
#define ui64_i2n UI64_CONCAT(UI64_PREFIX,ui64_i2n)
#define ui64_s2i UI64_CONCAT(UI64_PREFIX,ui64_s2i)
#define ui64_i2s UI64_CONCAT(UI64_PREFIX,ui64_i2s)
#define ui64_add UI64_CONCAT(UI64_PREFIX,ui64_add)
#define ui64_addn UI64_CONCAT(UI64_PREFIX,ui64_addn)
#define ui64_sub UI64_CONCAT(UI64_PREFIX,ui64_sub)
#define ui64_subn UI64_CONCAT(UI64_PREFIX,ui64_subn)
#define ui64_mul UI64_CONCAT(UI64_PREFIX,ui64_mul)
#define ui64_muln UI64_CONCAT(UI64_PREFIX,ui64_muln)
#define ui64_div UI64_CONCAT(UI64_PREFIX,ui64_div)
#define ui64_divn UI64_CONCAT(UI64_PREFIX,ui64_divn)
#define ui64_and UI64_CONCAT(UI64_PREFIX,ui64_and)
#define ui64_or UI64_CONCAT(UI64_PREFIX,ui64_or)
#define ui64_xor UI64_CONCAT(UI64_PREFIX,ui64_xor)
#define ui64_not UI64_CONCAT(UI64_PREFIX,ui64_not)
#define ui64_rol UI64_CONCAT(UI64_PREFIX,ui64_rol)
#define ui64_ror UI64_CONCAT(UI64_PREFIX,ui64_ror)
#define ui64_len UI64_CONCAT(UI64_PREFIX,ui64_len)
#define ui64_cmp UI64_CONCAT(UI64_PREFIX,ui64_cmp)
#endif
typedef struct {
unsigned char x[8]; /* x_0, ..., x_7 */
} ui64_t;
#define ui64_cons(x7,x6,x5,x4,x3,x2,x1,x0) \
{ { 0x##x0, 0x##x1, 0x##x2, 0x##x3, 0x##x4, 0x##x5, 0x##x6, 0x##x7 } }
/* particular values */
extern ui64_t ui64_zero (void);
extern ui64_t ui64_max (void);
/* import and export via ISO-C "unsigned long" */
extern ui64_t ui64_n2i (unsigned long n);
extern unsigned long ui64_i2n (ui64_t x);
/* import and export via ISO-C string of arbitrary base */
extern ui64_t ui64_s2i (const char *str, char **end, int base);
extern char * ui64_i2s (ui64_t x, char *str, size_t len, int base);
/* arithmetical operations */
extern ui64_t ui64_add (ui64_t x, ui64_t y, ui64_t *ov);
extern ui64_t ui64_addn (ui64_t x, int y, int *ov);
extern ui64_t ui64_sub (ui64_t x, ui64_t y, ui64_t *ov);
extern ui64_t ui64_subn (ui64_t x, int y, int *ov);
extern ui64_t ui64_mul (ui64_t x, ui64_t y, ui64_t *ov);
extern ui64_t ui64_muln (ui64_t x, int y, int *ov);
extern ui64_t ui64_div (ui64_t x, ui64_t y, ui64_t *ov);
extern ui64_t ui64_divn (ui64_t x, int y, int *ov);
/* bit operations */
extern ui64_t ui64_and (ui64_t x, ui64_t y);
extern ui64_t ui64_or (ui64_t x, ui64_t y);
extern ui64_t ui64_xor (ui64_t x, ui64_t y);
extern ui64_t ui64_not (ui64_t x);
extern ui64_t ui64_rol (ui64_t x, int s, ui64_t *ov);
extern ui64_t ui64_ror (ui64_t x, int s, ui64_t *ov);
/* other operations */
extern int ui64_len (ui64_t x);
extern int ui64_cmp (ui64_t x, ui64_t y);
#endif /* __UI64_H__ */
+46
View File
@@ -0,0 +1,46 @@
/*
** uuid_vers.h -- Version Information for OSSP uuid (syntax: C/C++)
** [automatically generated and maintained by GNU shtool]
*/
#ifdef _UUID_VERS_H_AS_HEADER_
#ifndef _UUID_VERS_H_
#define _UUID_VERS_H_
#define _UUID_VERSION 0x106202
typedef struct {
const int v_hex;
const char *v_short;
const char *v_long;
const char *v_tex;
const char *v_gnu;
const char *v_web;
const char *v_sccs;
const char *v_rcs;
} _uuid_version_t;
extern _uuid_version_t _uuid_version;
#endif /* _UUID_VERS_H_ */
#else /* _UUID_VERS_H_AS_HEADER_ */
#define _UUID_VERS_H_AS_HEADER_
#include "uuid_vers.h"
#undef _UUID_VERS_H_AS_HEADER_
_uuid_version_t _uuid_version = {
0x106202,
"1.6.2",
"1.6.2 (04-Jul-2008)",
"This is OSSP uuid, Version 1.6.2 (04-Jul-2008)",
"OSSP uuid 1.6.2 (04-Jul-2008)",
"OSSP uuid/1.6.2",
"@(#)OSSP uuid 1.6.2 (04-Jul-2008)",
"$Id$"
};
#endif /* _UUID_VERS_H_AS_HEADER_ */