From e7e20fab1b2b90ea80e118959386017ed1d6f703 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sat, 19 Nov 2022 22:39:14 -0500 Subject: create function open_pathfmt() to allow printf formatting on open() save some space by allowing printf formatting directly rather than having a buffer and using sprintf Change-Id: I049c8f898fb4a68a26ad0f0646250c242647ba12 --- apps/misc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'apps/misc.c') diff --git a/apps/misc.c b/apps/misc.c index 0bac986a6f..66d1c272ae 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -1418,6 +1418,16 @@ int string_option(const char *option, const char *const oplist[], bool ignore_ca return -1; } +/* open but with a builtin printf for assembling the path */ +int open_pathfmt(int oflag, const char *pathfmt, ...) +{ + static char buf[MAX_PATH]; + va_list ap; + vsnprintf(buf, sizeof(buf), pathfmt, ap); + va_end(ap); + return open(buf, oflag, 0666); +} + /** Open a UTF-8 file and set file descriptor to first byte after BOM. * If no BOM is present this behaves like open(). * If the file is opened for writing and O_TRUNC is set, write a BOM to -- cgit v1.2.3