Various libraries, including libblkid, depend on libuuid solely to call uuid_unparse, which just prints a UUID. Move the uuid_unparse functions to uuid.h and make them static inline, so that applications depending solely on the uuid_unparse functions don't need to pull in libuuid. Keep the out-of-line symbols for compatibility with existing applications. Signed-off-by: Josh Triplett <josh@xxxxxxxxxxxxxxxx> --- libuuid/src/unparse.c | 40 +--------------------------------------- libuuid/src/uuid.h | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 42 deletions(-) diff --git a/libuuid/src/unparse.c b/libuuid/src/unparse.c index a95bbb042..808c41869 100644 --- a/libuuid/src/unparse.c +++ b/libuuid/src/unparse.c @@ -34,43 +34,5 @@ #include <stdio.h> +#define UUID_DEFINE_UNPARSE_SYMBOLS #include "uuidP.h" - -static const char *fmt_lower = - "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"; - -static const char *fmt_upper = - "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"; - -#ifdef UUID_UNPARSE_DEFAULT_UPPER -#define FMT_DEFAULT fmt_upper -#else -#define FMT_DEFAULT fmt_lower -#endif - -static void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt) -{ - struct uuid uuid; - - uuid_unpack(uu, &uuid); - sprintf(out, fmt, - uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, - uuid.clock_seq >> 8, uuid.clock_seq & 0xFF, - uuid.node[0], uuid.node[1], uuid.node[2], - uuid.node[3], uuid.node[4], uuid.node[5]); -} - -void uuid_unparse_lower(const uuid_t uu, char *out) -{ - uuid_unparse_x(uu, out, fmt_lower); -} - -void uuid_unparse_upper(const uuid_t uu, char *out) -{ - uuid_unparse_x(uu, out, fmt_upper); -} - -void uuid_unparse(const uuid_t uu, char *out) -{ - uuid_unparse_x(uu, out, FMT_DEFAULT); -} diff --git a/libuuid/src/uuid.h b/libuuid/src/uuid.h index 03c232caa..0c207f5b9 100644 --- a/libuuid/src/uuid.h +++ b/libuuid/src/uuid.h @@ -35,6 +35,7 @@ #ifndef _UUID_UUID_H #define _UUID_UUID_H +#include <stdio.h> #include <sys/types.h> #ifndef _WIN32 #include <sys/time.h> @@ -102,9 +103,41 @@ extern int uuid_is_null(const uuid_t uu); extern int uuid_parse(const char *in, uuid_t uu); /* unparse.c */ -extern void uuid_unparse(const uuid_t uu, char *out); -extern void uuid_unparse_lower(const uuid_t uu, char *out); -extern void uuid_unparse_upper(const uuid_t uu, char *out); +#ifdef UUID_DEFINE_UNPARSE_SYMBOLS +#define UNPARSE_FUNC +void uuid_unparse_lower(const uuid_t uu, char *out); +void uuid_unparse_upper(const uuid_t uu, char *out); +void uuid_unparse(const uuid_t uu, char *out); +#else +#define UNPARSE_FUNC static inline +#endif +UNPARSE_FUNC void uuid_unparse_lower(const uuid_t uu, char *out) +{ + sprintf(out, + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + uu[0], uu[1], uu[2], uu[3], + uu[4], uu[5], + uu[6], uu[7], + uu[8], uu[9], + uu[10], uu[11], uu[12], uu[13], uu[14],uu[15]); +} + +UNPARSE_FUNC void uuid_unparse_upper(const uuid_t uu, char *out) +{ + sprintf(out, + "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", + uu[0], uu[1], uu[2], uu[3], + uu[4], uu[5], + uu[6], uu[7], + uu[8], uu[9], + uu[10], uu[11], uu[12], uu[13], uu[14],uu[15]); +} + +UNPARSE_FUNC void uuid_unparse(const uuid_t uu, char *out) +{ + uuid_unparse_lower(uu, out); +} +#undef UNPARSE_FUNC /* uuid_time.c */ extern time_t uuid_time(const uuid_t uu, struct timeval *ret_tv); -- 2.20.1