diff --git a/include/util.h b/include/util.h index 7a3029e79..066786226 100644 --- a/include/util.h +++ b/include/util.h @@ -162,6 +162,7 @@ extern void hex_dump(void *addr, unsigned long len); extern DIR *opendir_proc(char *fmt, ...); extern FILE *fopen_proc(char *fmt, char *mode, ...); +extern FILE *fopen_fmt(char *fmt, char *mode, ...); extern int open_fmt(char *fmt, int mode, ...); #define __xalloc(op, size, ...) \ diff --git a/util.c b/util.c index 43e96d9d4..c7f64769b 100644 --- a/util.c +++ b/util.c @@ -352,6 +352,22 @@ FILE *fopen_proc(char *fmt, char *mode, ...) return file; } +FILE *fopen_fmt(char *fmt, char *mode, ...) +{ + FILE *file; + char fname[128]; + va_list args; + + va_start(args, mode); + vsnprintf(fname, sizeof(fname), fmt, args); + va_end(args); + + file = fopen(fname, mode); + if (!file) + pr_perror("Can't open %s\n", fname); + return file; +} + int open_fmt(char *fmt, int mode, ...) { int fd;