From: Ian Jackson Date: Tue, 8 Oct 2019 14:45:50 +0000 (+0100) Subject: util: pathprefix_template: New facility X-Git-Tag: v0.6.0~210 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=secnet.git;a=commitdiff_plain;h=f817efbe5c62eb703c9acdbcad8104af671302a1 util: pathprefix_template: New facility We will use this for constructing public and private key filenames to load. No callers yet. Signed-off-by: Ian Jackson --- diff --git a/util.c b/util.c index 977e131..cc2f9fa 100644 --- 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 --- 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