Signed-off-by: Xiaoguang Wang <wangxg.f...@cn.fujitsu.com> --- include/safe_macros.h | 5 +++++ lib/safe_macros.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+)
diff --git a/include/safe_macros.h b/include/safe_macros.h index f521347..a79c4ad 100644 --- a/include/safe_macros.h +++ b/include/safe_macros.h @@ -266,5 +266,10 @@ int safe_mkfifo(const char *file, const int lineno, #define SAFE_MKFIFO(cleanup_fn, pathname, mode) \ safe_mkfifo(__FILE__, __LINE__, (cleanup_fn), (pathname), (mode)) +int safe_rename(const char *file, const int lineno, void (*cleanup_fn)(void), + const char *oldpath, const char *newpath); +#define SAFE_RENAME(cleanup_fn, oldpath, newpath) \ + safe_rename(__FILE__, __LINE__, (cleanup_fn), (oldpath), (newpath)) + #endif /* __SAFE_MACROS_H__ */ #endif /* __TEST_H__ */ diff --git a/lib/safe_macros.c b/lib/safe_macros.c index a07cffa..eefacae 100644 --- a/lib/safe_macros.c +++ b/lib/safe_macros.c @@ -768,3 +768,19 @@ int safe_mkfifo(const char *file, const int lineno, return rval; } + +int safe_rename(const char *file, const int lineno, void (*cleanup_fn)(void), + const char *oldpath, const char *newpath) +{ + int rval; + + rval = rename(oldpath, newpath); + + if (rval == -1) { + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: rename(%s, %s) failed", + file, lineno, oldpath, newpath); + } + + return rval; +} -- 1.8.2.1 ------------------------------------------------------------------------------ Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck Code Sight - the same software that powers the world's largest code search on Ohloh, the Black Duck Open Hub! Try it now. http://p.sf.net/sfu/bds _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list