]> git.sesse.net Git - vlc/blobdiff - src/text/filesystem.c
contribs: updated binary packages for Mac OS X including WebM support
[vlc] / src / text / filesystem.c
index e230f058c10178b8a45f107e50bf716c1d71d4dd..31fddef92647e1d80da80da98ce82bc16497cb2d 100644 (file)
@@ -37,6 +37,7 @@
 #include <assert.h>
 
 #include <stdio.h>
+#include <limits.h> /* NAME_MAX */
 #include <errno.h>
 #include <sys/types.h>
 #ifdef HAVE_DIRENT_H
@@ -225,7 +226,7 @@ int vlc_openat (int dir, const char *filename, int flags, ...)
         return -1;
     }
 
-#ifdef HAVE_FDOPENDIR
+#ifdef HAVE_OPENAT
     int fd = openat (dir, local_name, flags, mode);
 # ifdef HAVE_FCNTL
     if (fd != -1)
@@ -322,12 +323,18 @@ char *vlc_readdir( DIR *dir )
     return FromWide (ent->d_name);
 #else
     struct dirent *ent;
-
-    ent = readdir( (DIR *)dir );
-    if( ent == NULL )
+    struct
+    {
+        struct dirent ent;
+        char buf[NAME_MAX + 1];
+    } buf;
+    int val = readdir_r (dir, &buf.ent, &ent);
+    if (val)
+    {
+        errno = val;
         return NULL;
-
-    return vlc_fix_readdir( ent->d_name );
+    }
+    return ent ? vlc_fix_readdir( ent->d_name ) : NULL;
 #endif
 }
 
@@ -520,7 +527,17 @@ int vlc_rename (const char *oldpath, const char *newpath)
     else
         return -1;
 #else
-    return _wrename (wold, wnew);
+    if (_wrename (wold, wnew) && errno == EACCES)
+    {   /* Windows does not allow atomic file replacement */
+        if (_wremove (wnew))
+        {
+            errno = EACCES; /* restore errno */
+            return -1;
+        }
+        if (_wrename (wold, wnew))
+            return -1;
+    }
+    return 0;
 #endif
 
 #endif
@@ -695,12 +712,12 @@ int vlc_accept (int lfd, struct sockaddr *addr, socklen_t *alen, bool nonblock)
         if (fd != -1)
         {
 #ifndef WIN32
-    fcntl (fd, F_SETFD, FD_CLOEXEC);
-    if (nonblock)
-        fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
+            fcntl (fd, F_SETFD, FD_CLOEXEC);
+            if (nonblock)
+                fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
 #else
-    if (nonblock)
-        ioctlsocket (fd, FIONBIO, &(unsigned long){ 1 });
+            if (nonblock)
+                ioctlsocket (fd, FIONBIO, &(unsigned long){ 1 });
 #endif
             return fd;
         }