chiark / gitweb /
CL_GET_STR_ARG: Move into util.h
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Dec 2019 14:19:44 +0000 (14:19 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:54 +0000 (21:56 +0000)
Move this handy macro from pubkeys.c so that we can reuse it.
(And rename it appropriately.)

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
pubkeys.c
util.h

index 62f5525..efcfa77 100644 (file)
--- a/pubkeys.c
+++ b/pubkeys.c
@@ -49,15 +49,8 @@ const struct sigscheme_info *sigscheme_lookup(const char *name)
 static list_t *makepublic_apply(closure_t *self, struct cloc loc,
                                dict_t *context, list_t *args)
 {
-#define ARG(ix,vn,what)                                                        \
-    item_t *vn##_i=list_elem(args,ix);                                 \
-    if (!vn##_i) cfgfatal(loc,"make-public","need " what);             \
-    if (vn##_i->type!=t_string) cfgfatal(vn##_i->loc,"make-public",    \
-                                   what "must be string");             \
-    const char *vn=vn##_i->data.string
-
-    ARG(0,algname,"algorithm name");
-    ARG(1,b91d,"base91s-encoded public key");
+    CL_GET_STR_ARG(0,algname,"algorithm name");
+    CL_GET_STR_ARG(1,b91d,"base91s-encoded public key");
 
     const struct sigscheme_info *sch=sigscheme_lookup(algname);
     if (!sch) cfgfatal(algname_i->loc,"make-public",
diff --git a/util.h b/util.h
index 1086ad8..3929abe 100644 (file)
--- a/util.h
+++ b/util.h
@@ -265,6 +265,13 @@ async_linebuf_read(struct pollfd *pfd, struct buffer_if *buf,
 
 /*----- some handy macros -----*/
 
+#define CL_GET_STR_ARG(ix,vn,what)                                     \
+    item_t *vn##_i=list_elem(args,ix);                                 \
+    if (!vn##_i) cfgfatal(loc,"make-public","need " what);             \
+    if (vn##_i->type!=t_string) cfgfatal(vn##_i->loc,"make-public",    \
+                                   what "must be string");             \
+    const char *vn=vn##_i->data.string
+
 #define MINMAX(ae,be,op) ({                    \
        typeof((ae)) a=(ae);                    \
        typeof((be)) b=(be);                    \