* [PATCH] libuuid: Make the uuid_unparse functions inline
@ 2019-01-21 2:45 Josh Triplett
2019-01-22 12:04 ` Karel Zak
0 siblings, 1 reply; 3+ messages in thread
From: Josh Triplett @ 2019-01-21 2:45 UTC (permalink / raw)
To: util-linux; +Cc: Arjan van de Ven
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@joshtriplett.org>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] libuuid: Make the uuid_unparse functions inline
2019-01-21 2:45 [PATCH] libuuid: Make the uuid_unparse functions inline Josh Triplett
@ 2019-01-22 12:04 ` Karel Zak
2019-01-22 18:55 ` Josh Triplett
0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2019-01-22 12:04 UTC (permalink / raw)
To: Josh Triplett; +Cc: util-linux, Arjan van de Ven
On Sun, Jan 20, 2019 at 06:45:16PM -0800, Josh Triplett wrote:
> 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.
> 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.
It seems unnecessary.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libuuid: Make the uuid_unparse functions inline
2019-01-22 12:04 ` Karel Zak
@ 2019-01-22 18:55 ` Josh Triplett
0 siblings, 0 replies; 3+ messages in thread
From: Josh Triplett @ 2019-01-22 18:55 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux, Arjan van de Ven
On Tue, Jan 22, 2019 at 01:04:01PM +0100, Karel Zak wrote:
> On Sun, Jan 20, 2019 at 06:45:16PM -0800, Josh Triplett wrote:
> > 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
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-01-22 18:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-21 2:45 [PATCH] libuuid: Make the uuid_unparse functions inline Josh Triplett
2019-01-22 12:04 ` Karel Zak
2019-01-22 18:55 ` Josh Triplett
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).