summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristophe Sadoine <chris@indefini.org>2013-06-19 15:47:20 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-06-25 12:29:27 +0900
commitd9e1b7d67cb278b5ad78128f15ba36f77b04756b (patch)
tree656ccc5cfbc369d9835a112db367e35a9f8869b6 /src
parent4605b91804836878b86de8761b3ae8e81b34ed46 (diff)
evil: added evil_rename() a wrapper around rename().
Signed-off-by: Cedric Bail <cedric.bail@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/lib/evil/evil_stdio.c29
-rw-r--r--src/lib/evil/evil_stdio.h20
2 files changed, 47 insertions, 2 deletions
diff --git a/src/lib/evil/evil_stdio.c b/src/lib/evil/evil_stdio.c
index 231e5043d6..dd800041f8 100644
--- a/src/lib/evil/evil_stdio.c
+++ b/src/lib/evil/evil_stdio.c
@@ -6,7 +6,7 @@
6#include "evil_private.h" 6#include "evil_private.h"
7 7
8#undef fopen 8#undef fopen
9 9#undef rename
10 10
11#ifdef _WIN32_WCE 11#ifdef _WIN32_WCE
12 12
@@ -199,3 +199,30 @@ int evil_fclose_native(FILE *stream)
199} 199}
200 200
201#endif /* _WIN32_WCE */ 201#endif /* _WIN32_WCE */
202
203int
204evil_rename(const char *src, const char* dst)
205{
206 struct stat st;
207
208 if (stat(dst, &st) < 0)
209 return rename(src, dst);
210
211 if (stat(src, &st) < 0)
212 return -1;
213
214 if (S_ISDIR(st.st_mode))
215 {
216 rmdir(dst);
217 return rename(src, dst);
218 }
219
220 if (S_ISREG(st.st_mode))
221 {
222 unlink(dst);
223 return rename(src, dst);
224 }
225
226 return -1;
227}
228
diff --git a/src/lib/evil/evil_stdio.h b/src/lib/evil/evil_stdio.h
index 0baf00f5b8..27c116e9c5 100644
--- a/src/lib/evil/evil_stdio.h
+++ b/src/lib/evil/evil_stdio.h
@@ -204,8 +204,26 @@ EAPI int evil_fclose_native(FILE *stream);
204 204
205 205
206/** 206/**
207 * @} 207 * @brief Emulate the rename() function on Windows.
208 *
209 * @param src The old pathname.
210 * @param dst The new pathname.
211 * @return 0 on success, -1 otherwise.
212 *
213 * This function emulates the POSIX rename() function on Windows.
214 * The difference with the POSIX function is that the rename() function
215 * on windows fails if the destination exists.
216 *
217 * @since 1.8
218 */
219EAPI int evil_rename(const char *src, const char *dst);
220
221/**
222 * @def rename(src, dest)
223 *
224 * Wrapper around evil_rename().
208 */ 225 */
226# define rename(src, dst) evil_rename(src, dst)
209 227
210 228
211#endif /* __EVIL_STDIO_H__ */ 229#endif /* __EVIL_STDIO_H__ */