Fix uuid on FreeBSD

In FreeBSD, just as in DARWIN, uuid functions are in libc and no external libuuid is required.
The API is quite different from Linux's though, so a different implementation of uuid () (util.cpp) is needed.
This commit is contained in:
Pietro Cerutti 2013-09-13 08:03:50 +02:00 committed by Paul Beckingham
parent 05afa911d3
commit da7cc6eed7
3 changed files with 31 additions and 4 deletions

View file

@ -90,10 +90,10 @@ check_struct_has_member ("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF)
check_struct_has_member ("struct stat" st_birthtime "sys/types.h;sys/stat.h" HAVE_ST_BIRTHTIME)
message ("-- Looking for libuuid")
if (DARWIN)
# Apple includes the uuid functions in their libc, rather than libuuid
if (DARWIN OR FREEBSD)
# Apple and FreeBSD include the uuid functions in their libc, rather than libuuid
check_function_exists (uuid_unparse_lower HAVE_UUID_UNPARSE_LOWER)
else (DARWIN)
else (DARWIN OR FREEBSD)
find_path (UUID_INCLUDE_DIR uuid/uuid.h)
find_library (UUID_LIBRARY NAMES uuid)
if (UUID_INCLUDE_DIR AND UUID_LIBRARY)
@ -106,7 +106,7 @@ else (DARWIN)
else (UUID_INCLUDE_DIR AND UUID_LIBRARY)
message (FATAL_ERROR "-- libuuid not found.")
endif (UUID_INCLUDE_DIR AND UUID_LIBRARY)
endif (DARWIN)
endif (DARWIN OR FREEBSD)
if (HAVE_UUID_UNPARSE_LOWER)
message ("-- Found libuuid")

View file

@ -229,6 +229,28 @@ int autoComplete (
return matches.size ();
}
// Handle the generation of UUIDs on FreeBSD in a separate implementation
// of the uuid () function, since the API is quite different from Linux's.
// Also, uuid_unparse_lower is not needed on FreeBSD, because the string
// representation is always lowercase anyway.
// For the implementation details, refer to
// http://svnweb.freebsd.org/base/head/sys/kern/kern_uuid.c
#ifdef __FreeBSD__
const std::string uuid ()
{
uuid_t id;
uint32_t status;
char *buffer (0);
uuid_create (&id, &status);
uuid_to_string (&id, &buffer, &status);
std::string res (buffer);
free (buffer);
return res;
}
#else
////////////////////////////////////////////////////////////////////////////////
#ifndef HAVE_UUID_UNPARSE_LOWER
// Older versions of libuuid don't have uuid_unparse_lower(), only uuid_unparse()
@ -253,6 +275,7 @@ const std::string uuid ()
return std::string (buffer);
}
#endif
////////////////////////////////////////////////////////////////////////////////
// On Solaris no flock function exists.

View file

@ -32,7 +32,11 @@
#include <vector>
#include <map>
#include <sys/types.h>
#ifdef __FreeBSD__
#include <uuid.h>
#else
#include <uuid/uuid.h>
#endif
#include <Task.h>
// util.cpp