2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

util: Move various helpers there

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov
2011-10-24 13:43:21 +04:00
parent c475bccd53
commit 26857cc4e5
4 changed files with 40 additions and 35 deletions

34
util.c
View File

@@ -393,3 +393,37 @@ err_bogus_mapping:
vma_area->vma.end);
goto err;
}
DIR *opendir_proc(char *fmt, ...)
{
char path[128];
va_list args;
sprintf(path, "/proc/");
va_start(args, fmt);
vsnprintf(path + 6, sizeof(path) - 6, fmt, args);
va_end(args);
return opendir(path);
}
FILE *fopen_proc(char *fmt, char *mode, ...)
{
char fname[128];
va_list args;
sprintf(fname, "/proc/");
va_start(args, mode);
vsnprintf(fname + 6, sizeof(fname) - 6, fmt, args);
va_end(args);
return fopen(fname, mode);
}
int open_fmt(char *fmt, int pid, int mode)
{
char fname[128];
snprintf(fname, sizeof(fname), fmt, pid);
return open(fname, mode);
}