From: Josh Triplett <josh@joshtriplett.org>
To: util-linux@vger.kernel.org
Cc: Arjan van de Ven <arjan@linux.intel.com>
Subject: [PATCH] libuuid: Make the uuid_unparse functions inline
Date: Sun, 20 Jan 2019 18:45:16 -0800 [thread overview]
Message-ID: <20190121024510.GA22370@localhost> (raw)
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
next reply other threads:[~2019-01-21 7:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-21 2:45 Josh Triplett [this message]
2019-01-22 12:04 ` [PATCH] libuuid: Make the uuid_unparse functions inline Karel Zak
2019-01-22 18:55 ` Josh Triplett
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190121024510.GA22370@localhost \
--to=josh@joshtriplett.org \
--cc=arjan@linux.intel.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).