[vlc-devel] commit: Implement utf8_rename ( Rémi Denis-Courmont )

git version control git at videolan.org
Thu May 7 18:13:49 CEST 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu May  7 19:11:15 2009 +0300| [353cd0a0049d9c2053a199ee5a9026454e172a92] | committer: Rémi Denis-Courmont 

Implement utf8_rename

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=353cd0a0049d9c2053a199ee5a9026454e172a92
---

 include/vlc_charset.h |    1 +
 src/text/filesystem.c |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/include/vlc_charset.h b/include/vlc_charset.h
index cae46c7..b8a9d4e 100644
--- a/include/vlc_charset.h
+++ b/include/vlc_charset.h
@@ -49,6 +49,7 @@ VLC_EXPORT( int, utf8_loaddir, ( DIR *dir, char ***namelist, int (*select)( cons
 VLC_EXPORT( int, utf8_scandir, ( const char *dirname, char ***namelist, int (*select)( const char * ), int (*compar)( const char **, const char ** ) ) );
 VLC_EXPORT( int, utf8_mkdir, ( const char *filename, mode_t mode ) );
 VLC_EXPORT( int, utf8_unlink, ( const char *filename ) );
+int utf8_rename( const char *, const char * );
 
 #if defined( WIN32 ) && !defined( UNDER_CE )
 # define stat _stati64
diff --git a/src/text/filesystem.c b/src/text/filesystem.c
index 13f86bf..7b93beb 100644
--- a/src/text/filesystem.c
+++ b/src/text/filesystem.c
@@ -450,6 +450,41 @@ int utf8_unlink( const char *filename )
     return ret;
 }
 
+/**
+ * Moves a file atomically. This only works within a single file system.
+ *
+ * @param oldpath path to the file before the move
+ * @param newpath intended path to the file after the move
+ * @return A 0 return value indicates success. A -1 return value indicates an
+ *        error, and an error code is stored in errno
+ */
+int utf8_rename (const char *oldpath, const char *newpath)
+{
+#if defined (WIN32)
+    CONVERT_PATH (oldpath, wold, -1);
+    CONVERT_PATH (newpath, wnew, -1);
+    return _wrename (wold, wnew);
+
+#endif
+    const char *lo = ToLocale (oldpath);
+    if (lo == NULL)
+        goto error;
+
+    const char *ln = ToLocale (newpath);
+    if (ln == NULL)
+    {
+        LocaleFree (lo);
+error:
+        errno = ENOENT;
+        return -1;
+    }
+
+    int ret = rename (lo, ln);
+    LocaleFree (lo);
+    LocaleFree (ln);
+    return ret;
+}
+
 int utf8_mkstemp( char *template )
 {
     static const char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";




More information about the vlc-devel mailing list