[vlc-devel] commit: add vlc_openat wrapper around openat ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sun Feb 14 12:33:54 CET 2010
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Feb 14 13:33:23 2010 +0200| [37ae6248dd0ce4b78bd3ef4526a872ba8154a7db] | committer: Rémi Denis-Courmont
add vlc_openat wrapper around openat
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=37ae6248dd0ce4b78bd3ef4526a872ba8154a7db
---
include/vlc_fs.h | 1 +
src/libvlccore.sym | 1 +
src/text/filesystem.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/include/vlc_fs.h b/include/vlc_fs.h
index 51bfd60..42d5b9b 100644
--- a/include/vlc_fs.h
+++ b/include/vlc_fs.h
@@ -33,6 +33,7 @@
VLC_EXPORT( int, vlc_open, ( const char *filename, int flags, ... ) LIBVLC_USED );
VLC_EXPORT( FILE *, vlc_fopen, ( const char *filename, const char *mode ) LIBVLC_USED );
+VLC_EXPORT( int, vlc_openat, ( int fd, const char *filename, int flags, ... ) LIBVLC_USED );
VLC_EXPORT( DIR *, vlc_opendir, ( const char *dirname ) LIBVLC_USED );
VLC_EXPORT( char *, vlc_readdir, ( DIR *dir ) LIBVLC_USED );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index d293878..d620078 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -434,6 +434,7 @@ utf8_lstat
vlc_mkdir
vlc_mkstemp
vlc_open
+vlc_openat
vlc_opendir
vlc_readdir
vlc_scandir
diff --git a/src/text/filesystem.c b/src/text/filesystem.c
index 0e3723a..b514da7 100644
--- a/src/text/filesystem.c
+++ b/src/text/filesystem.c
@@ -194,6 +194,53 @@ FILE *vlc_fopen (const char *filename, const char *mode)
}
/**
+ * Opens a system file handle relative to an existing directory handle.
+ *
+ * @param dir directory file descriptor
+ * @param filename file path to open (with UTF-8 encoding)
+ * @param flags open() flags, see the C library open() documentation
+ * @return a file handle on success, -1 on error (see errno).
+ * @note Contrary to standard open(), this function returns file handles
+ * with the close-on-exec flag enabled.
+ */
+int vlc_openat (int dir, const char *filename, int flags, ...)
+{
+ unsigned int mode = 0;
+ va_list ap;
+
+ va_start (ap, flags);
+ if (flags & O_CREAT)
+ mode = va_arg (ap, unsigned int);
+ va_end (ap);
+
+#ifdef O_CLOEXEC
+ flags |= O_CLOEXEC;
+#endif
+
+ const char *local_name = ToLocale (filename);
+ if (local_name == NULL)
+ {
+ errno = ENOENT;
+ return -1;
+ }
+
+#ifdef HAVE_FDOPENDIR
+ int fd = openat (dir, local_name, flags, mode);
+# ifdef HAVE_FCNTL
+ if (fd != -1)
+ fcntl (fd, F_SETFD, FD_CLOEXEC);
+# endif
+#else
+ int fd = -1;
+ errno = ENOSYS;
+#endif
+
+ LocaleFree (local_name);
+ return fd;
+}
+
+
+/**
* Creates a directory using UTF-8 paths.
*
* @param dirname a UTF-8 string with the name of the directory that you
More information about the vlc-devel
mailing list