chiark / gitweb /
util: pathprefix_template: New facility
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 8 Oct 2019 14:45:50 +0000 (15:45 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 30 Dec 2019 13:15:49 +0000 (13:15 +0000)
We will use this for constructing public and private key filenames to
load.

No callers yet.

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

diff --git a/util.c b/util.c
index 977e131..cc2f9fa 100644 (file)
--- a/util.c
+++ b/util.c
@@ -723,6 +723,15 @@ const char *pollbadbit(int revents)
     return 0;
 }
 
+void pathprefix_template_init(struct pathprefix_template *out,
+                             const char *prefix, int maxsuffix)
+{
+    size_t l=strlen(prefix);
+    NEW_ARY(out->buffer,l+maxsuffix+1);
+    strcpy(out->buffer,prefix);
+    out->write_here=out->buffer+l;
+}
+
 enum async_linebuf_result
 async_linebuf_read(struct pollfd *pfd, struct buffer_if *buf,
                   const char **emsg_out)
diff --git a/util.h b/util.h
index a2ef828..1086ad8 100644 (file)
--- a/util.h
+++ b/util.h
@@ -169,6 +169,20 @@ void string_item_to_iaddr(const item_t *item, uint16_t port, union iaddr *ia,
                          const char *desc);
 
 
+/*----- pathprefix_template -----*/
+
+struct pathprefix_template {
+    char *buffer;
+    char *write_here;
+};
+
+void pathprefix_template_init(struct pathprefix_template *out,
+                             const char *prefix, int maxsuffix);
+static inline void pathprefix_template_setsuffix
+   (struct pathprefix_template *upd, const char *suffix)
+   { strcpy(upd->write_here,suffix); }
+
+
 /*
  * SBUF_DEFINE(int nbufs, size_t size);
  *   // Generates a number of definitions and statements organising