libuuid: Make the uuid_unparse functions inline
PATCH 1/1 libuuid: Make the uuid_unparse functions inline
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.
--- libuuid/src/unparse.c | 40 +--------------------------------------- libuuid/src/uuid.h | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 42 deletions(-)
libuuid/src/unparse.c +1 -39
@@ -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 ); -}
libuuid/src/uuid.h +36 -3
@@ -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);
Signature · 1 line
2.20.1
Karel Zak
maintainerQuoted 2 lines · Josh Triplett
Various libraries, including libblkid, depend on libuuid solely to call
uuid_unparse, which just prints a UUID.
It seems only libblkid requires solely uuid_unparse() :-) So, I guess all we need is to use already implemented blkid_unparse_uuid() where is the magic snprintf. I have applied this change:
https://github.com/karelzak/util-linux/commit/c2435b946f574880201cb41d989d8d63d4bbf87d
The another stuff (e.g. mkswap, libfdisk, ...) depends on uuid_parse() or/and uuid_generate(). So, libuuid is required there.
Quoted 4 lines
Move the
uuid_unparsefunctions touuid.hand make them static inline, so that applications depending solely on theuuid_unparsefunctions don't need to pull in libuuid. Keep the out-of-line symbols for compatibility with existing applications.
It seems unnecessary.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 9 lines · Karel Zak
Quoted 2 lines · Josh Triplett
Various libraries, including libblkid, depend on libuuid solely to call
uuid_unparse, which just prints a UUID.It seems only libblkid requires solely
uuid_unparse():-) So, I guess all we need is to use already implementedblkid_unparse_uuid()where is the magic snprintf. I have applied this change:https://github.com/karelzak/util-linux/commit/c2435b946f574880201cb41d989d8d63d4bbf87d
Alright; that certainly solves the primary issue I observed. Thank you!
Looking across a large chunk of Debian, I don't see any other users of solely uuid_unparse.