From 454b8ba9fee72d56ce991c4753bedc7e6095ea57 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Diego=20Elio=20'Flameeyes'=20Petten=C3=B2?= Date: Sat, 16 May 2009 01:01:39 +0200 Subject: [PATCH] Use FreeBSD uuid functions when available. If the system provide the uuid_create function assume building on FreeBSD or another OS with a compatible uuid interface. If that's the case, ignore libuuid and just use the system functions without extra deps. --- configure.ac | 15 +++++++++------ src/sm_genid.c | 25 +++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 9730b70..cf36193 100644 --- a/configure.ac +++ b/configure.ac @@ -42,12 +42,15 @@ XTRANS_CONNECTION_FLAGS AC_ARG_WITH(libuuid, AC_HELP_STRING([--with-libuuid], [Build with libuuid support for client IDs])) -if test x"$with_libuuid" != xno; then - PKG_CHECK_MODULES(LIBUUID, uuid, [HAVE_LIBUUID=yes], [HAVE_LIBUUID=no]) -fi -if test x"$with_libuuid" = xyes && test x"$HAVE_LIBUUID" = xno; then - AC_MSG_ERROR([requested libuuid support but uuid.pc not found]) -fi +AC_CHECK_FUNCS([uuid_create], [], [ + if test x"$with_libuuid" != xno && test x"$have_system_uuid" != xyes; then + PKG_CHECK_MODULES(LIBUUID, uuid, [HAVE_LIBUUID=yes], [HAVE_LIBUUID=no]) + fi + if test x"$with_libuuid" = xyes && test x"$HAVE_LIBUUID" = xno; then + AC_MSG_ERROR([requested libuuid support but uuid.pc not found]) + fi +]) + AM_CONDITIONAL(WITH_LIBUUID, test x"$HAVE_LIBUUID" = xyes) XORG_RELEASE_VERSION diff --git a/src/sm_genid.c b/src/sm_genid.c index 391a10e..f6adda3 100644 --- a/src/sm_genid.c +++ b/src/sm_genid.c @@ -76,7 +76,9 @@ in this Software without prior written authorization from The Open Group. #define TCPCONN #endif -#if defined(HAVE_LIBUUID) +#if defined(HAVE_UUID_CREATE) +#include +#elif defined(HAVE_LIBUUID) #include #endif @@ -84,7 +86,26 @@ in this Software without prior written authorization from The Open Group. char * SmsGenerateClientID(SmsConn smsConn) { -#if defined(HAVE_LIBUUID) +#if defined(HAVE_UUID_CREATE) + char *id; + char **temp; + uuid_t uuid; + uint32_t status; + + uuid_create(&uuid, &status); + + uuid_to_string(&uuid, &temp, &status); + + if ((id = malloc (strlen (temp) + 2)) != NULL) + { + id[1] = '2'; + strcpy (id+1, temp); + } + + free(temp); + + return id; +#elif defined(HAVE_LIBUUID) char *id; char temp[256]; uuid_t uuid; -- 1.6.3