Commit 3e45e040 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

util: Add fopen_fmt helper

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 7cf9246a
......@@ -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, ...) \
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment