提交 6e31c4b2 编写于 作者: M Michal Privoznik

virFileWrapper: Use VIR_AUTOFREE()

This enables us to simplify the code a bit.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 288e0ab1
...@@ -152,110 +152,74 @@ virFileWrapperOverridePrefix(const char *path) ...@@ -152,110 +152,74 @@ virFileWrapperOverridePrefix(const char *path)
FILE *fopen(const char *path, const char *mode) FILE *fopen(const char *path, const char *mode)
{ {
FILE *ret = NULL; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real_fopen(newpath, mode); return real_fopen(newpath, mode);
VIR_FREE(newpath);
return ret;
} }
int access(const char *path, int mode) int access(const char *path, int mode)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real_access(newpath, mode); return real_access(newpath, mode);
VIR_FREE(newpath);
return ret;
} }
# ifdef HAVE___LXSTAT # ifdef HAVE___LXSTAT
int __lxstat(int ver, const char *path, struct stat *sb) int __lxstat(int ver, const char *path, struct stat *sb)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real___lxstat(ver, newpath, sb); return real___lxstat(ver, newpath, sb);
VIR_FREE(newpath);
return ret;
} }
# endif /* HAVE___LXSTAT */ # endif /* HAVE___LXSTAT */
int lstat(const char *path, struct stat *sb) int lstat(const char *path, struct stat *sb)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real_lstat(newpath, sb); return real_lstat(newpath, sb);
VIR_FREE(newpath);
return ret;
} }
# ifdef HAVE___XSTAT # ifdef HAVE___XSTAT
int __xstat(int ver, const char *path, struct stat *sb) int __xstat(int ver, const char *path, struct stat *sb)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real___xstat(ver, newpath, sb); return real___xstat(ver, newpath, sb);
VIR_FREE(newpath);
return ret;
} }
# endif /* HAVE___XSTAT */ # endif /* HAVE___XSTAT */
int stat(const char *path, struct stat *sb) int stat(const char *path, struct stat *sb)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real_stat(newpath, sb); return real_stat(newpath, sb);
VIR_FREE(newpath);
return ret;
} }
int mkdir(const char *path, mode_t mode) int mkdir(const char *path, mode_t mode)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real_mkdir(newpath, mode); return real_mkdir(newpath, mode);
VIR_FREE(newpath);
return ret;
} }
int open(const char *path, int flags, ...) int open(const char *path, int flags, ...)
{ {
int ret = -1; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
va_list ap; va_list ap;
mode_t mode = 0; mode_t mode = 0;
...@@ -270,24 +234,15 @@ int open(const char *path, int flags, ...) ...@@ -270,24 +234,15 @@ int open(const char *path, int flags, ...)
va_end(ap); va_end(ap);
} }
ret = real_open(newpath, flags, mode); return real_open(newpath, flags, mode);
VIR_FREE(newpath);
return ret;
} }
DIR *opendir(const char *path) DIR *opendir(const char *path)
{ {
DIR *ret = NULL; VIR_AUTOFREE(char *) newpath = NULL;
char *newpath = NULL;
PATH_OVERRIDE(newpath, path); PATH_OVERRIDE(newpath, path);
ret = real_opendir(newpath); return real_opendir(newpath);
VIR_FREE(newpath);
return ret;
} }
#endif #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册