[sheepdog] [PATCH 1/2] util: add xmkdir that check EEXIST internally

Liu Yuan namei.unix at gmail.com
Wed Mar 20 10:25:39 CET 2013


From: Liu Yuan <tailai.ly at taobao.com>

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 include/util.h |    1 +
 lib/util.c     |    7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/include/util.h b/include/util.h
index 5a72bd1..192e3fd 100644
--- a/include/util.h
+++ b/include/util.h
@@ -82,6 +82,7 @@ ssize_t xread(int fd, void *buf, size_t len);
 ssize_t xwrite(int fd, const void *buf, size_t len);
 ssize_t xpread(int fd, void *buf, size_t count, off_t offset);
 ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset);
+int xmkdir(const char *pathname, mode_t mode);
 void pstrcpy(char *buf, int buf_size, const char *str);
 int rmdir_r(char *dir_path);
 int purge_directory(char *dir_path);
diff --git a/lib/util.c b/lib/util.c
index 323779a..bb47654 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -228,6 +228,13 @@ ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset)
 	return total;
 }
 
+int xmkdir(const char *pathname, mode_t mode)
+{
+	if (mkdir(pathname, mode) < 0 && errno != EEXIST)
+		return -1;
+	return 0;
+}
+
 /**
  * Copy the string str to buf. If str length is bigger than buf_size -
  * 1 then it is clamped to buf_size - 1.
-- 
1.7.9.5




More information about the sheepdog mailing list