public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] lib: add SAFE_RENAME()
@ 2014-07-15 10:13 Xiaoguang Wang
  2014-07-15 10:13 ` [LTP] [PATCH 2/2] syscalls/getcwd04.c: regression test for getcwd(2) Xiaoguang Wang
  0 siblings, 1 reply; 13+ messages in thread
From: Xiaoguang Wang @ 2014-07-15 10:13 UTC (permalink / raw)
  To: ltp-list

Signed-off-by: Xiaoguang Wang <wangxg.fnst@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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-08-01  1:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-15 10:13 [LTP] [PATCH 1/2] lib: add SAFE_RENAME() Xiaoguang Wang
2014-07-15 10:13 ` [LTP] [PATCH 2/2] syscalls/getcwd04.c: regression test for getcwd(2) Xiaoguang Wang
2014-07-15 10:21   ` Xiaoguang Wang
2014-07-21  9:04   ` Jan Stancek
2014-07-21  9:09     ` Wanlong Gao
2014-07-21  9:23       ` Xiaoguang Wang
2014-07-27  8:42         ` Xiaoguang Wang
2014-07-27  9:00           ` [LTP] [PATCH v2 1/2] lib: add SAFE_RENAME() Xiaoguang Wang
2014-07-27  9:00             ` [LTP] [PATCH v2 2/2] syscalls/getcwd04.c: regression test for getcwd(2) Xiaoguang Wang
2014-08-01  1:51             ` [LTP] [PATCH v2 1/2] lib: add SAFE_RENAME() Wanlong Gao
2014-07-21  9:33       ` [LTP] [PATCH 2/2] syscalls/getcwd04.c: regression test for getcwd(2) Jan Stancek
2014-07-21  9:40         ` Wanlong Gao
2014-07-21  9:58           ` Jan Stancek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox