mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-04 08:15:37 +00:00
util: Add fopen_fmt helper
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
@@ -162,6 +162,7 @@ extern void hex_dump(void *addr, unsigned long len);
|
|||||||
|
|
||||||
extern DIR *opendir_proc(char *fmt, ...);
|
extern DIR *opendir_proc(char *fmt, ...);
|
||||||
extern FILE *fopen_proc(char *fmt, char *mode, ...);
|
extern FILE *fopen_proc(char *fmt, char *mode, ...);
|
||||||
|
extern FILE *fopen_fmt(char *fmt, char *mode, ...);
|
||||||
extern int open_fmt(char *fmt, int mode, ...);
|
extern int open_fmt(char *fmt, int mode, ...);
|
||||||
|
|
||||||
#define __xalloc(op, size, ...) \
|
#define __xalloc(op, size, ...) \
|
||||||
|
16
util.c
16
util.c
@@ -352,6 +352,22 @@ FILE *fopen_proc(char *fmt, char *mode, ...)
|
|||||||
return file;
|
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 open_fmt(char *fmt, int mode, ...)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
Reference in New Issue
Block a user