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
This commit is contained in:
William Wilgus 2022-11-19 22:39:14 -05:00 committed by William Wilgus
parent 8fe42c43c6
commit e7e20fab1b
8 changed files with 42 additions and 53 deletions

View file

@ -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