2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 14:25:49 +00:00

util: Add fopen_fmt helper

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
Cyrill Gorcunov
2011-12-25 17:04:02 +04:00
parent 7cf9246a8d
commit 3e45e04050
2 changed files with 17 additions and 0 deletions

View File

@@ -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, ...) \

16
util.c
View File

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